我需要跑
ALTER SYSTEM SET track_activity_query_size = 16384;
Run Code Online (Sandbox Code Playgroud)
所以我可以看到一些长时间运行的查询的内容(我只能看到默认大小的开头),但是当我尝试在 RDS 实例的 pgAdmin 中执行此操作时,我收到错误
ERROR: must be superuser to execute ALTER SYSTEM command
Run Code Online (Sandbox Code Playgroud)
如何运行该更改系统查询?
连接运算符||可以连接任何字符串类型的值,返回text. 在 Postgres 中,每种类型都有一个文本表示并且可以转换为text. 因此,引用手册:
但是,字符串连接运算符 (
||) 仍然接受非字符串输入,只要至少一个输入是字符串类型
有关的:
连接一个或多个NULL值产生结果NULL。
test=# SELECT (text 'foo' || NULL) IS NULL
test-# , (text 'bar' || char '1' || NULL ) IS NULL
test-# , (NULL::bigint || text 'baz') IS NULL;
?column? | ?column? | ?column?
----------+----------+----------
t | t | t
Run Code Online (Sandbox Code Playgroud)
是否可以连接 atext和 aNULL值并获得非空结果?
换句话说, …
I am building a PostgreSQL database and I have created a timestamp table, where the primary key is the timestamp itself (e.g. id: Fri Apr 13 2018 15:00:19). The database is supposed to be later migrated to a data warehouse, from which analytics will be extracted.
At this point, I am wondering whether it is beneficial to add extra columns to the timestamp table, containing the parsed metrics such as the example below, or have a single table with …
postgresql performance database-design optimization timestamp query-performance
为什么临时表不能引用 PostgreSQL 中的非临时表?当我运行以下
CREATE TABLE foo ( a int PRIMARY KEY );
CREATE TEMP TABLE bar ( a int REFERENCES foo );
Run Code Online (Sandbox Code Playgroud)
我明白了,
错误:对临时表的约束只能引用临时表
我认为这曾经有效,所以我回到 PostgreSQL 8.4 并且我看到即使那时它曾经出错,
错误:无法从临时表约束引用永久表
这是为什么?为什么临时表不能引用非临时表。
多年来,我们一直在使用具有糟糕且低效的数据库结构的单体程序。现在我们终于用我们自己的程序摆脱了它。
我们唯一遇到困难的领域是数据库。我们的数据是财务数据,我们现有的程序主要通过覆盖 ( UPDATE, DELETE)导致数据丢失。我们决定采用仅追加的结构来保存我们积累的所有数据。如果仓库增长超过我们最初的估计,我们可能会考虑使用它,但与此同时,我们预计数据库会在几年内增长到一些较大表的数百万行;在这一点上规模不大。
我们使用PostgreSQL,将被拒绝修改特权,比如UPDATE与DELETE用户,以确保数据的一致性历史。
我们认为我们可以将所有当前和历史数据包含在一个表中,以便我们查询timestamp每个记录的最后一条(或最新),id如下表所示。
澄清一下,我们有几十个表;下面代表一个这样的表的简单版本。
????????????????????????????????????????????????????
? key ? id ? field1 ? field2 ? timestamp ?
????????????????????????????????????????????????????
? 0 ? 0 ? a ? b ? 1970-01-01 00:00:01 ?
????????????????????????????????????????????????????
? 1 ? 1 ? x ? y ? 1970-01-01 00:00:02 ?
????????????????????????????????????????????????????
? 2 ? 0 ? a ? c ? 1970-01-01 00:05:01 ? # new version of id=0 row
????????????????????????????????????????????????????
Run Code Online (Sandbox Code Playgroud)
我们还考虑了 NoSQL …
例如:
timestamp(tz) 到 int8date 到 int4json 到 text原始数据不变,唯一的区别是数据的处理方式。因此,应该可以干净且即时地来回更改。
我如何检查是否确实如此?
如果不是这种情况(表格被重写),我如何在不重写的情况下做到这一点?
我希望将 PostgreSQL 10 集群从server1克隆到server2,它在相同的硬件上运行相同的 Postgres 版本。目的是负载平衡和 HA。要记住的事情:
我考虑过的选项:
pg_dump | psql 当然,但这需要重新创建索引,并且对于相同系统之间的完整副本来说似乎非常缓慢且效率低下。rsync所有 Postgres 文件夹和文件。有这么多数据存在数据损坏的风险,我需要确保我得到了所有东西(大概只有数据目录是不够的)。pg_basebackup直接通过管道以pg_receivewal某种方式完成这项工作吗?找不到我的用例的说明。做到这一点的最佳方法是什么?好像是很常见的情况。
如何计算所有小数位直到第一个零
例如,我有一个名为 x 的列,其中包含一个数值数据类型值 1.955000000
我想计算没有零的小数位。所以在这里我希望查询输出 3 而不是 9(带零)
据我了解,在 MySQL/Postgres 数据库中,不能保证没有 order-by 子句的 select 语句的值顺序,因此应该任意获取行。如果是这样,那么为什么在执行此类查询时通常没有重复项?
SELECT * FROM `table` LIMIT 0,5
SELECT * FROM `table` LIMIT 5,5
SELECT * FROM `table` LIMIT 10,5
Run Code Online (Sandbox Code Playgroud)
考虑到人们只关心不获取重复项而不关心排序,这些查询使用起来是否安全?如果是,那又如何?
在安装 PostgreSQL 时,我不断收到消息:
“运行安装后步骤时出现问题。安装可能无法正确完成数据库集群初始化失败。”
这似乎阻止我正确使用 PGadmin。
在安装日志中,我发现以下部分似乎表明出了什么问题。
我一直无法找到解决此问题的方法。
Executing batch file 'rad7C33E.bat'...
The program "postgres" was found by "C:/Program Files/PostgreSQL/11/bin/initdb.exe"
but was not the same version as initdb.
Check your installation.
Called Die(Failed to initialise the database cluster with initdb)...
Failed to initialise the database cluster with initdb
Script stderr:
Program ended with an error exit code
Error running cscript //NoLogo "C:\Program Files\PostgreSQL\11/installer/server/initcluster.vbs" "NT AUTHORITY\NetworkService" "postgres" "****" "C:\Users\JesseDanckaarts\AppData\Local\Temp/postgresql_installer_6f373c7c91" "C:\Program Files\PostgreSQL\11" "C:\Program Files\PostgreSQL\11\data" 5432 "Dutch,Netherlands" 0: Program ended with an error …Run Code Online (Sandbox Code Playgroud) postgresql ×10
query ×2
alter-table ×1
amazon-rds ×1
aws ×1
backup ×1
concat ×1
datatypes ×1
decimal ×1
installation ×1
mysql ×1
null ×1
optimization ×1
performance ×1
replication ×1
timestamp ×1