pg_jobmon

pg_jobmon

pg_jobmon : Extension for logging and monitoring functions in PostgreSQL

Overview

IDExtensionPackageVersionCategoryLicenseLanguage
7160
pg_jobmon
pg_jobmon
1.4.1
SEC
PostgreSQL
SQL
AttributeHas BinaryHas LibraryNeed LoadHas DDLRelocatableTrusted
--s-d--
No
Yes
No
Yes
no
no
Relationships
Requires
dblink
See Also
pg_cron
pg_task
pgagent
pg_background
logerrors
bgw_replstatus
pgauditlogtofile
pg_auth_mon

Packages

TypeRepoVersionPG Major CompatibilityPackage PatternDependencies
EXT
MIXED
1.4.1
18
17
16
15
14
pg_jobmondblink
RPM
PGDG
1.4.1
18
17
16
15
14
pg_jobmon_$v-
DEB
PIGSTY
1.4.1
18
17
16
15
14
postgresql-$v-pg-jobmon-
Linux / PGPG18PG17PG16PG15PG14
el8.x86_64
PGDG 1.4.1
PGDG 1.4.1
PGDG 1.4.1
PGDG 1.4.1
PGDG 1.4.1
el8.aarch64
PGDG 1.4.1
PGDG 1.4.1
PGDG 1.4.1
PGDG 1.4.1
PGDG 1.4.1
el9.x86_64
PGDG 1.4.1
PGDG 1.4.1
PGDG 1.4.1
PGDG 1.4.1
PGDG 1.4.1
el9.aarch64
PGDG 1.4.1
PGDG 1.4.1
PGDG 1.4.1
PGDG 1.4.1
PGDG 1.4.1
el10.x86_64
PGDG 1.4.1
PGDG 1.4.1
PGDG 1.4.1
PGDG 1.4.1
PGDG 1.4.1
el10.aarch64
PGDG 1.4.1
PGDG 1.4.1
PGDG 1.4.1
PGDG 1.4.1
PGDG 1.4.1
d12.x86_64
PIGSTY 1.4.1
PIGSTY 1.4.1
PIGSTY 1.4.1
PIGSTY 1.4.1
PIGSTY 1.4.1
d12.aarch64
PIGSTY 1.4.1
PIGSTY 1.4.1
PIGSTY 1.4.1
PIGSTY 1.4.1
PIGSTY 1.4.1
d13.x86_64
PIGSTY 1.4.1
PIGSTY 1.4.1
PIGSTY 1.4.1
PIGSTY 1.4.1
PIGSTY 1.4.1
d13.aarch64
PIGSTY 1.4.1
PIGSTY 1.4.1
PIGSTY 1.4.1
PIGSTY 1.4.1
PIGSTY 1.4.1
u22.x86_64
PIGSTY 1.4.1
PIGSTY 1.4.1
PIGSTY 1.4.1
PIGSTY 1.4.1
PIGSTY 1.4.1
u22.aarch64
PIGSTY 1.4.1
PIGSTY 1.4.1
PIGSTY 1.4.1
PIGSTY 1.4.1
PIGSTY 1.4.1
u24.x86_64
PIGSTY 1.4.1
PIGSTY 1.4.1
PIGSTY 1.4.1
PIGSTY 1.4.1
PIGSTY 1.4.1
u24.aarch64
PIGSTY 1.4.1
PIGSTY 1.4.1
PIGSTY 1.4.1
PIGSTY 1.4.1
PIGSTY 1.4.1

Source

pig build pkg pg_jobmon;		# build deb

Install

Make sure PGDG and PIGSTY repo available:

pig repo add pgsql -u   # add both repo and update cache

Install this extension with pig:

pig install pg_jobmon;		# install via package name, for the active PG version

pig install pg_jobmon -v 18;   # install for PG 18
pig install pg_jobmon -v 17;   # install for PG 17
pig install pg_jobmon -v 16;   # install for PG 16
pig install pg_jobmon -v 15;   # install for PG 15
pig install pg_jobmon -v 14;   # install for PG 14

Create this extension with:

CREATE EXTENSION pg_jobmon CASCADE; -- requires dblink

Usage

pg_jobmon: Autonomous job logging and monitoring for PostgreSQL

pg_jobmon provides autonomous (non-transactional) logging for PostgreSQL transactions and functions. If a function fails, all log information written up to that point is preserved rather than rolled back.

CREATE SCHEMA jobmon;
CREATE EXTENSION pg_jobmon SCHEMA jobmon;

Setup

The extension uses dblink to connect back to the same database (for non-transactional logging). Add credentials:

INSERT INTO jobmon.dblink_mapping_jobmon (username, pwd) VALUES ('rolename', 'rolepassword');

For non-standard ports:

INSERT INTO jobmon.dblink_mapping_jobmon (host, username, pwd, port)
VALUES ('localhost', 'rolename', 'rolepassword', '5999');

Core Logging Functions

-- Start a new job
SELECT jobmon.add_job('My Job Name');

-- Add a step to the job
SELECT jobmon.add_step(job_id, 'Step description');

-- Update step status
SELECT jobmon.update_step(step_id, 'OK', 'Step completed successfully');
SELECT jobmon.update_step(step_id, 'WARNING', 'Something unexpected');

-- Close the job
SELECT jobmon.close_job(job_id);

-- Or fail the job
SELECT jobmon.fail_job(job_id);

Monitoring Functions

-- Check for failed jobs
SELECT * FROM jobmon.check_job_status();

-- View job history
SELECT * FROM jobmon.job_log ORDER BY start_time DESC;

-- View step details
SELECT * FROM jobmon.job_detail WHERE job_id = 123;

The autonomous logging ensures that even if the parent transaction rolls back, the job log entries are preserved for troubleshooting.

Last updated on