Using pg_cron in Managed Service for PostgreSQL
Written by
Updated at December 24, 2024
The pg_cron
Install the pg_cron extension in a PostgreSQL cluster
To install pg_cron in a PostgreSQL cluster:
-
Connect the shared library named
pg_cronto your cluster. -
Add the
pg_cronextension to one of the databases. You cannot enable the extension for two databases.Warning
Installing
pg_cronwill restart PostgreSQL on all cluster hosts one by one. -
Add a user with the
mdb_adminrole ormdb_superuserrole to manage the jobs.
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. TheSELECTcommand is allowed.cron.job_run_details: Contains the history of extension runs. TheSELECT,UPDATE, andDELETEcommands are allowed.
-
Functions:
schedule: Creates a job in the database where thepg_cronextension is installed.schedule_in_database: Creates a job in another database.unschedule: Deletes a job.alter_job: Modifies the job.
To learn more about the pg_cron extension, see its official documentation