问题
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:
- what's the best way to refresh a materialized view?
- 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:
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
来源:https://stackoverflow.com/questions/47012961/refresh-materialized-view-periodically-postgres