【发布时间】:2019-06-06 04:24:19
【问题描述】:
我在 PostgreSQL 中有三个物化视图需要很长时间才能刷新(每个都超过几个小时),我需要每天刷新它们。
我目前正在使用 Python 脚本执行此操作,该脚本一个接一个地刷新视图,但与在 pgAdmin 中手动刷新它们相比,它需要三倍的时间(我可以在不同的选项卡中同时运行所有三个刷新)。
这就是我的代码现在的样子:
import psycopg2
config = {'connection details'}
conn = psycopg2.connect(**config)
cur = conn.cursor()
# This is the part that I want to run simultaneously
cur.execute('REFRESH MATERIALIZED VIEW gsam.mv_hist_wip_data')
cur.execute('REFRESH MATERIALIZED VIEW gsam.mv_hist_ver_data')
cur.execute('REFRESH MATERIALIZED VIEW gsam.mv_hist_verda_data')
conn.close()
如何使用 Python 和 psycopg2 同时执行三个 REFRESH MATERIALIZED VIEW 语句?
【问题讨论】: