PostgreSQL查询和数据库性能调整

时间:2018-09-12 05:04:33

标签: postgresql query-performance postgresql-9.6

我们在执行查询时性能下降

select count(*) from test;

这需要30秒。一个表中有470列,索引很少,该表有5000万条记录。

select distinct name1,name2,id 
from test 
where id in (1234,6543,7643,9876);

上述查询也需要5分钟以上。请提出建议。

我在postgresql.conf中配置了参数,如下所示。

max_connections = 10 
shared_buffers = 4GB
effective_cache_size = 12GB
maintenance_work_mem = 1GB
checkpoint_completion_target = 0.7
wal_buffers = 16MB
default_statistics_target = 100
random_page_cost = 4
effective_io_concurrency = 2
work_mem = 419430kB
min_wal_size = 1GB
max_wal_size = 2GB
idle_in_transaction_session_timeout = 9000000

我正在使用PostgreSQL 9.6,我的服务器具有16 GB内存

我们可以在单个索引上创建多个列还是为单个列创建单独的索引?

CREATE TABLE test (
    accept_dt timestamp NULL,
    test_line_number int4 NULL,
    office varchar(120) NULL,
    add_dt timestamp NULL,
    name1   int4 NULL,
    name2   int4 NULL,
    name3   int4 NULL,
    .....
    .....
    ....
    );

CREATE INDEX test_indx ON public.test USING btree (name1,name2,name3,name4);
CREATE INDEX test2_indx ON public. USING btree (accept_dt, test_line_number);

0 个答案:

没有答案
相关问题