How do I create a cron job to run an postgres SQL function?

后端 未结 3 1438
我在风中等你
我在风中等你 2020-12-31 08:54

I assume that all I need to do is to:

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

    perform proc_my_sql_funtion();

  2. Execute thi

3条回答
  •  不思量自难忘°
    2020-12-31 09:46

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

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

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

    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
    

提交回复
热议问题