pgagent

A PostgreSQL job scheduler

Overview

PackageVersionCategoryLicenseLanguage
pgagent4.2.3ADMINPostgreSQLC
IDExtensionBinLibLoadCreateTrustRelocSchema
5880pgagentNoYesNoYesNoNo-
Relatedpg_cron pg_task pg_jobmon pg_partman pglogical pg_background pg_repack pg_rewrite

Version

TypeRepoVersionPG VerPackageDeps
EXTPGDG4.2.31817161514pgagent-
RPMPGDG4.2.31817161514pgagent_$v-
DEBPGDG4.2.31817161514pgagent-
OS / PGPG18PG17PG16PG15PG14
el8.x86_64
el8.aarch64
el9.x86_64
el9.aarch64
el10.x86_64
el10.aarch64
d12.x86_64PGDG MISSPGDG MISSPGDG MISSPGDG MISSPGDG MISS
d12.aarch64PGDG MISSPGDG MISSPGDG MISSPGDG MISSPGDG MISS
d13.x86_64PGDG MISSPGDG MISSPGDG MISSPGDG MISSPGDG MISS
d13.aarch64PGDG MISSPGDG MISSPGDG MISSPGDG MISSPGDG MISS
u22.x86_64PGDG MISSPGDG MISSPGDG MISSPGDG MISSPGDG MISS
u22.aarch64PGDG MISSPGDG MISSPGDG MISSPGDG MISSPGDG MISS
u24.x86_64PGDG MISSPGDG MISSPGDG MISSPGDG MISSPGDG MISS
u24.aarch64PGDG MISSPGDG MISSPGDG MISSPGDG MISSPGDG MISS

Install

You can install pgagent directly. First, make sure the PGDG repository is added and enabled:

pig repo add pgdg -u          # Add PGDG repo and update cache

Install the extension using pig or apt/yum/dnf:

pig install pgagent;          # Install for current active PG version
pig ext install -y pgagent -v 18  # PG 18
pig ext install -y pgagent -v 17  # PG 17
pig ext install -y pgagent -v 16  # PG 16
pig ext install -y pgagent -v 15  # PG 15
pig ext install -y pgagent -v 14  # PG 14
dnf install -y pgagent_18       # PG 18
dnf install -y pgagent_17       # PG 17
dnf install -y pgagent_16       # PG 16
dnf install -y pgagent_15       # PG 15
dnf install -y pgagent_14       # PG 14
apt install -y pgagent   # PG 18
apt install -y pgagent   # PG 17
apt install -y pgagent   # PG 16
apt install -y pgagent   # PG 15
apt install -y pgagent   # PG 14

Create Extension:

CREATE EXTENSION pgagent;

Usage

pgagent: A PostgreSQL job scheduler

pgAgent is a job scheduling agent for PostgreSQL, capable of running multi-step batch/shell scripts and SQL tasks on complex schedules. It runs as a daemon and stores job definitions in the database.

Core Concepts

  • Job: A named schedulable unit containing one or more steps and schedules
  • Step: An individual action (SQL script or OS batch/shell command) within a job
  • Schedule: Defines when a job runs, with cron-like flexibility

Job Management via SQL

pgAgent stores its configuration in the pgagent schema. Jobs can be managed through pgAdmin or directly via SQL.

-- View all jobs
SELECT jobid, jobname, jobenabled, jobdesc
FROM pgagent.pga_job;

-- View job steps
SELECT jstid, jstjobid, jstname, jstenabled, jstkind, jstcode
FROM pgagent.pga_jobstep;

-- View job schedules
SELECT jscid, jscjobid, jscname, jscenabled,
       jscstart, jscend, jscminutes, jschours,
       jscweekdays, jscmonthdays, jscmonths
FROM pgagent.pga_schedule;

-- View job execution log
SELECT * FROM pgagent.pga_joblog
WHERE jlgjobid = 1 ORDER BY jlgstart DESC;

-- View step execution log
SELECT * FROM pgagent.pga_jobsteplog
WHERE jsljlgid IN (SELECT jlgid FROM pgagent.pga_joblog WHERE jlgjobid = 1)
ORDER BY jslstart DESC;

Step Types

KindDescription
sSQL script executed against a database
bBatch/shell command executed on the OS

Schedule Fields

FieldDescription
jscstart / jscendValid date range for the schedule
jscminutesBoolean array[60]: which minutes to run
jschoursBoolean array[24]: which hours to run
jscweekdaysBoolean array[7]: which days of week
jscmonthdaysBoolean array[32]: which days of month
jscmonthsBoolean array[12]: which months

Security

The pgAgent daemon connects to the database using a stored connection string. Only database superusers or users granted appropriate privileges on the pgagent schema tables should manage jobs.


Last Modified 2026-03-12: add pg extension catalog (95749bf)