执行select时,Postgresql 9.4非常慢。例如:
explain analyze select * from ntable order by id desc limit 20 offset 3000000;
QUERY PLAN:
Limit (cost=122484.28..122485.10 rows=20 width=43) (actual time=1132.152..1132.160 rows=20 loops=1)
-> Index Scan using ntable_id_desc_index on ntable (cost=0.43..220527.42 rows=5401373 width=43) (actual time=0.021..1007.365 rows=3000020 loops=1)
Planning time: 0.273 ms
Execution time: 1132.200 ms
表格中的记录总数:
count
---------
5401521
(1 row)
索引:
"ntable_pkey" PRIMARY KEY, btree (id)
"ntable_id_desc_index" btree (id DESC)
Server在postgresql.conf中有24GB ram和16个核心设置:
max_connections = 400
shared_buffers = 3584MB
effective_cache_size = 10752MB
work_mem = 9175kB
maintenance_work_mem = 896MB
checkpoint_segments = 32
checkpoint_completion_target = 0.7
wal_buffers = 16MB
default_statistics_target = 100
请帮助提高此类查询的效果,谢谢!