0

我做了一个在远程数据库中运行的 sql 查询(使用 postgres_fdw 扩展),并结合了来自远程数据库中 2 个不同表的信息。尽管我已经使用 use_remote_estimate 选项创建了远程服务器,但查询执行时间大约需要 5 分钟。当我直接在远程数据库本身中运行相同的查询时,得到结果不到 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
4

0 回答 0