Postgres_fdw用于远程数据库连接的性能

时间:2017-04-25 10:29:25

标签: postgresql postgres-9.6

我做了一个在远程数据库中运行的sql查询(使用postgres_fdw扩展名),并结合了远程数据库中2个不同表的信息。查询执行时间大约需要5分钟,尽管我创建了远程服务器,并选择use_remote_estimate为true。当我直接在远程数据库本身运行相同的查询时,获取结果所需的时间不到5秒。我能做些什么来获得更好的表现吗?是否有可用于提高性能的设置?当查询从我的数据库运行到远程数据库时,是否使用外键和索引?我不确定。我在网上搜索解决方案,但没有答案满足我的需求。感谢

当我执行EXPLAIN(ANALYZE BUFFER)到远程数据库时,我得到了这些结果:

QUERY PLAN
Merge Join  (cost=2920.60..6345984.84 rows=56546 width=440) (actual time=5874.882..834358.774 rows=3338 loops=1)
Merge Cond: (str.store_id = prf.store_id)
->  Sort  (cost=1221.49..1229.84 rows=3338 width=18) (actual time=2835.745..2840.122 rows=3338 loops=1)
Sort Key: str.store_id
Sort Method: quicksort  Memory: 314kB
->  Foreign Scan on store str  (cost=100.00..1026.14 rows=3338 width=18) (actual time=158.809..2832.790 rows=3338 loops=1)
->  Sort  (cost=1699.11..1707.58 rows=3388 width=23) (actual time=2882.143..2891.705 rows=3338 loops=1)
Sort Key: prf.store_id
Sort Method: quicksort  Memory: 350kB
->  Foreign Scan on store_profile prf  (cost=100.00..1500.47 rows=3388 width=23) (actual time=166.818..2878.937 rows=3338 loops=1)
SubPlan 1
->  Foreign Scan on store_profile p  (cost=100.29..112.16 rows=1 width=19) (actual time=165.285..165.287 rows=1 loops=3338)
Planning time: 495.796 ms
Execution time: 834678.186 ms

0 个答案:

没有答案