Skip to content

pg_background_queue

Topic-aware background SQL task queue with concurrency limits and retries.

pg_background_queue · Topic-aware background SQL task queue with concurrency limits and retries.

Overview

IDExtensionPackageVersionCategoryLicenseLanguage
101900pg_background_queuepg_background_queue1.0TIMEGPL-3.0C

PostgreSQL · 13, 14, 15, 16, 17, 18

Usage

Sources:

pg_background_queue Topic-aware background SQL task queue with concurrency limits and retries.

Enablement

Merge pg_background_queue into the existing preload list, restart PostgreSQL, and then create pg_background_queue in each database that needs its SQL objects:

shared_preload_libraries = 'pg_background_queue'
CREATE EXTENSION pg_background_queue;

Core Workflow

The following example is taken from the reviewed upstream documentation. Adapt object names, paths, credentials, and workload values before use.

-- Check active worker count
SELECT pg_background_queue_active_workers_count();

-- Ensure workers are running (❗️️SUGGESTING: trigger by pg_cron)
SELECT pg_background_queue_ensure_workers();

-- Calibrate worker count (❗️️SUGGESTING: trigger by pg_cron)
SELECT pg_background_queue_calibrate_workers_count();

Main Objects

The reviewed install surface includes these prominent objects:

ObjectKindOperational role
pg_background_tasksTABLEExtension-owned table; account for its data in backup and upgrades.
pg_background_enqueueFUNCTIONCallable function from the reviewed install surface.
pg_background_queue_ensure_workersFUNCTIONCallable function from the reviewed install surface.
pg_background_queue_calibrate_workers_countFUNCTIONCallable function from the reviewed install surface.
pg_background_queue_active_workers_countFUNCTIONCallable function from the reviewed install surface.
pg_background_queue_task_stateTYPEUser-facing data type created by the extension.

Operations and Boundaries

  • The verified PostgreSQL-major evidence covers 13, 14, 15, 16, 17, 18; do not infer unlisted majors.
  • Preloading pg_background_queue changes cluster startup state; stage configuration and restart changes separately from CREATE EXTENSION.

Table reader