Using pg_cron in Managed Service for PostgreSQL
Written by
Updated at June 26, 2024
The pg_cron
Install the pg_cron extension in a PostgreSQL cluster
To install the pg_cron
extension in a PostgreSQL cluster:
-
Enable the shared library with the name
pg_cron
for a cluster. -
Add the
pg_cron
extension to one of the databases. You cannot enable the extension for two databases.Warning
Installing the
pg_cron
extension will cause PostgreSQL to restart sequentially on all cluster hosts. -
Add a user with the
mdb_admin
role to manage the tasks.
In the selected database, the cron
schema with tables and functions required for the extension to work will appear:
-
Tables:
cron.job
: Contains scheduled jobs. TheSELECT
command is allowed.cron.job_run_details
: Contains the history of runs. TheSELECT
,UPDATE
, andDELETE
commands are allowed.
-
Functions:
schedule
: Creates a job in the database where thepg_cron
extension is installed.schedule_in_database
: Creates a job in another database.unschedule
: Deletes a job.alter_job
: Changes a job.
To learn more about the pg_cron
extension, see the official documentation