我有两个Postgresql实例。一个是本地的(Macbook Pro Retina 15),另一个是Digital Ocean 10美元的实例。配置几乎相同(大多数是基本的)。两者都加载了相同的数据库转储。问题是,针对50k项目表的简单选择查询的执行时间在远程实例上几乎高出5倍。
本地:
explain (analyze,buffers) select * from car_trims limit 100 offset 40000;
QUERY PLAN
---------------------------------------------------------------------------------------------------------------------
Limit (cost=842.14..844.24 rows=100 width=66) (actual time=11.193..11.212 rows=100 loops=1)
Buffers: shared hit=450
-> Seq Scan on car_trims (cost=0.00..1139.01 rows=54101 width=66) (actual time=0.006..6.832 rows=40100 loops=1)
Buffers: shared hit=450
Planning time: 0.053 ms
Execution time: 11.236 ms
(6 rows)
远程:
explain (analyze,buffers) select * from car_trims limit 100 offset 40000;
QUERY PLAN
----------------------------------------------------------------------------------------------------------------------
Limit (cost=830.91..832.99 rows=100 width=66) (actual time=46.167..46.321 rows=100 loops=1)
Buffers: shared hit=439
-> Seq Scan on car_trims (cost=0.00..1124.18 rows=54118 width=66) (actual time=0.060..26.080 rows=40100 loops=1)
Buffers: shared hit=439
Planning time: 0.206 ms
Execution time: 46.442 ms
(6 rows)
这应该是由于更强大的硬件应该如何?还是有调整的空间?我可以使用哪些工具来解决问题?
UPD:我在执行这些查询之前做了一些热身。另外,以防我执行真空并重新编制此表。