refresh materialized view periodically postgres

2019-05-03 08:20发布

for optimization purposes I'm using a materialized view, to refresh it periodically I have set a cron job that runs each period t in my case every three hours. my questions are:

  1. what's the best way to refresh a materialized view?
  2. what can go wrong if using a cron job to refresh a materialized view?

I have come across a postgres plugin that schedule jobs link

1条回答
Ridiculous、
2楼-- · 2019-05-03 09:19

the best way is to execute periodically a script that does the task:

the script is:

#!/bin/sh
psql -U user_name -d database_instance_name -c 'refresh materialized view view_name'

and add an entry in the crontab like:

@hourly  /full_path/script_name.sh
查看更多
登录 后发表回答