pg_dbms_job v2.1 fixes scheduler restart logic for PostgreSQL migrations
The v2.1 update ensures the pg_dbms_job scheduler automatically restarts via the postmaster after unexpected terminations.
Summary
Hexacluster Corp. has released version 2.1 of pg_dbms_job, a PostgreSQL extension designed to provide Oracle-style DBMS_JOB compatibility. This extension allows database administrators to manage scheduled tasks, job queues, and asynchronous executions using syntax and behaviors familiar to Oracle users.
The primary focus of this release is a critical fix for the scheduler's lifecycle management. Previously, if the scheduler was terminated via SIGTERM during active server operation—such as during a forced database drop or a backend termination—it would exit with code 0, preventing the postmaster from automatically restarting it. Version 2.1 changes this exit behavior to code 1, ensuring the postmaster triggers a restart after the configured bgw_restart_time.
Technical improvements in pg_dbms_job v2.1
- Scheduler Lifecycle Fix: The daemon now exits with code 1 upon receiving a SIGTERM while the server is running, allowing the postmaster to restart the background worker after the bgw_restart_time interval.
- Asynchronous Execution Logic: Jobs can be executed immediately in an asynchronous process if the submit procedure is called without a next_date/interval, or if the interval is NULL and the next_date is in the past.
- Daemon Architecture: Unlike standard background workers, this extension utilizes an external scheduler daemon to avoid the instability of forking thousands of sub-processes directly from a background worker.
- Polling and Notification Mechanism: The scheduler utilizes NOTIFY events polled every 0.1 seconds for immediate job updates, falling back to a 5-second interval (job_queue_interval) for table polling when no notifications are present.
- Concurrency Limits: The system enforces a default limit of 1000 concurrent job executions, causing the daemon to wait for process completion before starting new tasks if the limit is reached.
Why it matters
This release is significant for engineers performing large-scale migrations from Oracle to PostgreSQL, as it increases the reliability of automated job scheduling. By ensuring the scheduler recovers from unexpected terminations, it reduces the risk of silent job failures in production environments.
Original reference: www.postgresql.org →