Scheduled Tasks

Crontab

Since Postgresql does not have an embedded scheduler, this need is solved with pg_cron and pgagent extensions or with crontab at the operating system level. SQL to be executed, function procedure etc. The codes can be written in Linux bashscript and scheduled with crontab, the embedded scheduler of the Linux operatingsystem. Example Script vim /var/lib/postgresql/scripts/instest.sh Crontab

pg_cron

Using pg_cron has the same logic as cron on Unix/Linux systems.15 03 * * * → Means 03:15 every night. First, the running postgresql version is checked and the appropriate version of pg_cron is installed.shared_preload_libraries is set in the database settings, restarted and theextension is created.A schema named cron comes with the extension. Details about pg_cron

Pgagent

It is an extension of pgadmin, which is the postgres client software. After installing withapt from Postgresql repositories, an extension should also be created in databases. In the client machine ; Connect to postgresql database with pgadmin. The pgAgent Jobs tab will appear belowthe Tablespaces tab. Example By connecting to testdb, a test table is Pgagent