定期刷新物化视图postgres [英] refresh materialized view periodically postgres

查看:692
本文介绍了定期刷新物化视图postgres的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

出于优化目的,我使用实例化视图来定期刷新它,我设置了一个cron作业,在我的情况下,每三个小时运行一次周期t。
我的问题是:

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. 刷新实体化视图的最佳方法是什么?

  2. 如果使用cron作业刷新实例化视图会出什么问题?

我遇到了一个Postgres插件,用于安排作业< a href = https://github.com/citusdata/pg_cron rel = noreferrer>链接

I have come across a postgres plugin that schedule jobs link

推荐答案

最好的方法是定期执行执行任务的脚本:

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

脚本为:

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

并在crontab中添加一个条目,例如:

and add an entry in the crontab like:

@hourly  /full_path/script_name.sh

这篇关于定期刷新物化视图postgres的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆