小编ale*_*lex的帖子

PostgreSQL CREATE INDEX 内存要求

我的笔记本电脑上有 6GB 的 RAM,为了进行测试,我在 PostgreSQL 9.3 中创建了一个 5000 万行的表。然后我想在表上创建一个索引。

表和结果索引一起(或表总大小的两倍)可以放入 5GB 的 RAM,我设置maintenance_work_mem为 5GB,仍然CREATE INDEX使用外部排序和大约 1.4GB 的临时文件。为什么呢?

我对它应该能够在 RAM 中进行排序的期望是不合理的吗?

test=# set maintenance_work_mem to '5GB';
SET
test=# create table t1 as (select i::int, random() as f from generate_series(1, 50000000) i);
SELECT 50000000
test=# select pg_size_pretty(pg_relation_size('t1'));
 pg_size_pretty 
----------------
 2111 MB
(1 row)

test=# create index on t1(f, i);
CREATE INDEX
test=# select pg_size_pretty(pg_relation_size('t1_f_i_idx'));
 pg_size_pretty 
----------------
 1504 MB
(1 row)
Run Code Online (Sandbox Code Playgroud)

在服务器日志中:

LOG:  temporary file: path "base/pgsql_tmp/pgsql_tmp22623.1", size 1073741824 …
Run Code Online (Sandbox Code Playgroud)

postgresql index memory postgresql-9.3

3
推荐指数
1
解决办法
1541
查看次数

标签 统计

index ×1

memory ×1

postgresql ×1

postgresql-9.3 ×1