如何创建cron作业以运行postgres SQL函数? [英] How do I create a cron job to run an postgres SQL function?

查看:96
本文介绍了如何创建cron作业以运行postgres SQL函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认为我要做的只是:

  1. 创建一个sql文件,例如nameofsqlfile.sql内容:

  1. Create an sql file e.g. nameofsqlfile.sql contents:

执行proc_my_sql_funtion();

perform proc_my_sql_funtion();

将其作为cron作业执行.

Execute this as a cron job.

但是,我不知道要为指定主机,端口,数据库,用户&他的密码...?

However, I don't know the commands that I'd need to write to get this cron job executed as a postgres function for a specified host,port,database, user & his password...?

推荐答案

您只需要考虑cronjob就是在指定的时间或日期运行shell命令.

You just need to think of cronjob as running a shell command at a specified time or day.

所以您的第一项工作是弄清楚如何运行shell命令.

So your first job is to work out how to run your shell command.

psql --host host.example.com --port 12345 --dbname nameofdatabase < my.sql

然后您可以将其添加到您的crontab中(我建议您使用crontab -e以避免损坏内容)

You can then just add this to your crontab (I recommend you use crontab -e to avoid breaking things)

# runs your command at 00:00 every day
#
# min hour wday month mday command-to-run
    0    0    *     *    * psql --host host.example.com --port 12345 --dbname nameofdatabase < my.sql

这篇关于如何创建cron作业以运行postgres SQL函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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