小编Gui*_*mas的帖子

调整设置以减少 postgres 中大型查询的读取块数

使用 postgres 9.6,我不明白共享缓冲区如何与索引一起工作。

设置

  • Postgres 9.6
  • 所有默认设置
    • 共享缓冲区:128Mb
    • 工作内存:4Mb
    • 块大小:8192
    • ...

这意味着 shared_buffer 大小为 128 * 1024 * 1024 / 8192 = 16384 个块。

测试数据

我创建了一个简单的表,其中包含随机数据和每列的索引。

DROP TABLE IF EXISTS sandbox;


CREATE TABLE sandbox AS
SELECT generate_series(1, 4000000) AS pk,
       random() AS x;

CREATE INDEX ON sandbox(pk);
CREATE INDEX ON sandbox(x);
Run Code Online (Sandbox Code Playgroud)

我去了 4M 行。这是表和索引占用的大小:

postgres=# SELECT relname AS "relation",
       pg_relation_size(C.oid) / 8192 AS "blocks",
       pg_size_pretty(pg_relation_size(C.oid)) AS "size"
FROM pg_class C
LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace)
WHERE relname …
Run Code Online (Sandbox Code Playgroud)

postgresql performance postgresql-performance

6
推荐指数
1
解决办法
1849
查看次数