array列有上限吗?
插入数组字段时出现此错误 -
PG::Error: ERROR: index row size 3480 exceeds maximum 2712 for index "ix_data"
Run Code Online (Sandbox Code Playgroud)
这是我的表定义 -
create table test_array(id varchar(50), data text[]);
ALTER TABLE test_array ADD PRIMARY KEY (id);
CREATE INDEX ix_data ON test_array USING GIN (data);
Run Code Online (Sandbox Code Playgroud)
我需要数组字段的索引,因为我正在对它进行一些查找。
我们在处理高峰时段到我们的数据库服务器的流量时遇到问题。我们正在研究改进硬件(请参阅有关该方面的问题),但我们也希望进行池配置和服务器调整。
我们正在开发的应用程序是一款用于智能手机的回合制多人游戏,其后端由Rails和unicorn和PostgreSQL 9.1作为数据库组成。我们目前有 600 000 名注册用户,并且由于游戏状态存储在数据库中,每隔几秒钟就会进行数千次写入。我们使用PgBadger分析了来自PostgreSQL的日志文件,在关键时间我们得到了很多
FATAL: remaining connection slots are reserved for non-replication superuser connections
Run Code Online (Sandbox Code Playgroud)
解决这个问题的天真解决方案是增加postgresql.conf 中的max_connections(当前为 100) 。我已经阅读了http://wiki.postgresql.org/wiki/Number_Of_Database_Connections这表明这可能不是正确的做法。在前面提到的文章中,它提到了在 max_connections 和pool size之间找到最佳位置。
为了找到这个甜蜜点,可以做些什么?是否有任何好的工具可以测量max_connections和pool size 的不同值的 I/O 性能?
我们当前的设置是 4 个游戏服务器,每个服务器有 16 个独角兽工人,池大小为 5。
以下是我们使用的非默认 postgres 设置:
version | PostgreSQL 9.1.5 on x86_64-unknown-linux-gnu,compiled by gcc (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3, 64-bit
checkpoint_completion_target | 0.9
checkpoint_segments | 60
checkpoint_timeout | …Run Code Online (Sandbox Code Playgroud) 我是 postgreSQL 的新手。我有 3 个表,一个表引用其他 2 个表的主键。但是我无法将数据插入到Table3. 请参阅下面的代码:
DROP TABLE Table1 CASCADE;
CREATE TABLE Table1(
"DataID" bigint NOT NULL DEFAULT '0',
"AdData" integer DEFAULT NULL,
PRIMARY KEY ("DataID")
);
DROP TABLE IF EXISTS Table2 CASCADE;
CREATE TABLE Table2 (
"Address" numeric(20) NOT NULL DEFAULT '0',
"Value" numeric(20) DEFAULT NULL,
PRIMARY KEY ("Address")
);
DROP TABLE IF EXISTS Table3 CASCADE;
CREATE TABLE table3 (
"ID" bigint NOT NULL DEFAULT '0',
"DataID" bigint DEFAULT NULL,
"Address" numeric(20) DEFAULT NULL,
"Data" …Run Code Online (Sandbox Code Playgroud) 我一直在执行一种密集的模式删除和通过 PostgreSQL 服务器创建,但现在抱怨..:
WARNING: out of shared memory
ERROR: out of shared memory
HINT: You might need to increase max_locks_per_transaction.
Run Code Online (Sandbox Code Playgroud)
但是如果 PostgreSQL 只是用 重新启动,问题仍然存在service postgresql restart,我怀疑 max_locks_per_transaction 不会调整任何内容。
我有点疏远,因为此错误的故障排除列表对我不起作用。
更多信息 1409291350:缺少一些细节,但我保留了核心 SQL 结果。
postgres=# SELECT version();
PostgreSQL 9.3.5 on x86_64-unknown-linux-gnu, compiled by gcc (Ubuntu 4.8.2-19ubuntu1) 4.8.2,
64-bit
Run Code Online (Sandbox Code Playgroud)
和:
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 14.04.1 LTS
Release: 14.04
Codename: trusty
Run Code Online (Sandbox Code Playgroud) 我在 Postgresql 中有一个数据库,它是从 SQL Server 迁移过来的(只有数据)。
在 SQL Server 上,此数据库中的表具有以下列:
measure_id
datum
measure
Run Code Online (Sandbox Code Playgroud)
其中measure_id是自动增量主键,datum是日期时间,measure是浮点数。
在 Postrgresql 中迁移后,measure_id是 bigint 类型的列。
measure_id既然我的表充满了数据,我该如何将此列 ( )更改为 bigserial 并将其指定为主键?
我有一个包含大量插入内容的表,将其中一个字段 ( uploaded_at) 设置为NULL. 然后周期性任务选择所有元组WHERE uploaded_at IS NULL,处理它们并更新,设置uploaded_at为当前日期。
我应该如何索引表?
我知道我应该使用部分索引,例如:
CREATE INDEX foo ON table (uploaded_at) WHERE uploaded_at IS NULL
Run Code Online (Sandbox Code Playgroud)
或者像那样。我有点困惑,但如果在始终为NULL. 或者如果使用 b 树索引是正确的。Hash 看起来是一个更好的主意,但它已经过时并且不能通过流式热备复制进行复制。任何建议将不胜感激。
我对以下索引进行了一些试验:
"foo_part" btree (uploaded_at) WHERE uploaded_at IS NULL
"foo_part_id" btree (id) WHERE uploaded_at IS NULL
Run Code Online (Sandbox Code Playgroud)
并且查询平面似乎总是选择foo_part索引。索引的explain analyse结果也稍好一些foo_part:
Index Scan using foo_part on t1 (cost=0.28..297.25 rows=4433 width=16) (actual time=0.025..3.649 rows=4351 loops=1)
Index Cond: (uploaded_at IS NULL)
Total runtime: 4.060 ms
Run Code Online (Sandbox Code Playgroud)
对比 …
new_customerWeb 应用程序每秒调用我的函数数次(但每个会话仅调用一次)。它所做的第一件事就是锁定customer表(执行“如果不存在则插入”—— 的一个简单变体upsert)。
我对文档的理解是,其他调用new_customer应该简单地排队,直到所有先前的调用都完成:
LOCK TABLE 获得一个表级锁,必要时等待任何冲突的锁被释放。
为什么有时会死锁?
定义:
create function new_customer(secret bytea) returns integer language sql
security definer set search_path = postgres,pg_temp as $$
lock customer in exclusive mode;
--
with w as ( insert into customer(customer_secret,customer_read_secret)
select secret,decode(md5(encode(secret, 'hex')),'hex')
where not exists(select * from customer where customer_secret=secret)
returning customer_id )
insert into collection(customer_id) select customer_id from w;
--
select customer_id from customer where customer_secret=secret;
$$;
Run Code Online (Sandbox Code Playgroud)
日志中的错误:
2015-07-28 08:02:58 BST …
考虑一个prices包含这些列的表:
id integer primary key
product_id integer -- foreign key
start_date date not null
end_date date not null
quantity integer
price numeric
Run Code Online (Sandbox Code Playgroud)
我希望数据库强制执行这样的规则,即产品在日期范围内(通过where <date> BETWEEN start_date AND end_date)的特定数量只能有一个价格。
这种基于范围的约束可行吗?
postgresql database-design exclusion-constraint postgresql-9.4
每次使用 pgAdmin III 恢复数据库时,我都会收到以下 pgAdmin III 错误:
错误:无法删除文件“”(错误 2:没有这样的文件或目录)
请参阅pgadmin 日志。
我的配置:
x86_64-unknown-linux-gnu 上的 PostgreSQL 9.4.4,由 gcc (Ubuntu 4.8.2-19ubuntu1) 4.8.2 编译,64 位
Linux 3.19.0-26-generic #28~14.04.1-Ubuntu SMP Wed Aug 12 14:09:17 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
postgresql ×10
index ×2
deadlock ×1
foreign-key ×1
index-tuning ×1
memory ×1
migration ×1
null ×1
performance ×1
pgadmin-1.18 ×1
plpgsql ×1
plpython ×1
schema ×1