Skip to content
pg_background

pg_background

pg_background : Run SQL queries in the background

Overview

ID Extension Package Version Category License Language
1110
pg_background
pg_background
1.9.2
TIME
GPL-3.0
C
Attribute Has Binary Has Library Need Load Has DDL Relocatable Trusted
--s-d-r
No
Yes
No
Yes
yes
no
Relationships
See Also
pg_cron
pg_task
pg_later
pgq
timescaledb
timescaledb_toolkit
timeseries
periods

Release tag 1.9.2 still ships extension SQL version 1.9.

Packages

Type Repo Version PG Major Compatibility Package Pattern Dependencies
EXT
MIXED
1.9.2
18
17
16
15
14
pg_background -
RPM
PGDG
1.9.3
18
17
16
15
14
pg_background_$v -
DEB
PIGSTY
1.9.3
18
17
16
15
14
postgresql-$v-pg-background -
Linux / PG PG18 PG17 PG16 PG15 PG14
el8.x86_64
PGDG 1.9.3
PGDG 1.9.3
PGDG 1.9.3
PGDG 1.9.3
PGDG 1.9.3
el8.aarch64
PGDG 1.9.3
PGDG 1.9.3
PGDG 1.9.3
PGDG 1.9.3
PGDG 1.9.3
el9.x86_64
PGDG 1.9.3
PGDG 1.9.3
PGDG 1.9.3
PGDG 1.9.3
PGDG 1.9.3
el9.aarch64
PGDG 1.9.3
PGDG 1.9.3
PGDG 1.9.3
PGDG 1.9.3
PGDG 1.9.3
el10.x86_64
PGDG 1.9.3
PGDG 1.9.3
PGDG 1.9.3
PGDG 1.9.3
PGDG 1.9.3
el10.aarch64
PGDG 1.9.3
PGDG 1.9.3
PGDG 1.9.3
PGDG 1.9.3
PGDG 1.9.3
d12.x86_64
PGDG 1.9.2
PGDG 1.9.2
PGDG 1.9.2
PGDG 1.9.2
PGDG 1.9.2
d12.aarch64
PGDG 1.9.2
PGDG 1.9.2
PGDG 1.9.2
PGDG 1.9.2
PGDG 1.9.2
d13.x86_64
PGDG 1.9.2
PGDG 1.9.2
PGDG 1.9.2
PGDG 1.9.2
PGDG 1.9.2
d13.aarch64
PGDG 1.9.2
PGDG 1.9.2
PGDG 1.9.2
PGDG 1.9.2
PGDG 1.9.2
u22.x86_64
PGDG 1.9.2
PGDG 1.9.2
PGDG 1.9.2
PGDG 1.9.2
PGDG 1.9.2
u22.aarch64
PGDG 1.9.2
PGDG 1.9.2
PGDG 1.9.2
PGDG 1.9.2
PGDG 1.9.2
u24.x86_64
PGDG 1.9.2
PGDG 1.9.2
PGDG 1.9.2
PGDG 1.9.2
PGDG 1.9.2
u24.aarch64
PGDG 1.9.2
PGDG 1.9.2
PGDG 1.9.2
PGDG 1.9.2
PGDG 1.9.2
u26.x86_64
PGDG 1.9.2
PGDG 1.9.2
PGDG 1.9.2
PGDG 1.9.2
PGDG 1.9.2
u26.aarch64
PGDG 1.9.2
PGDG 1.9.2
PGDG 1.9.2
PGDG 1.9.2
PGDG 1.9.2
Package Version OS ORG SIZE File URL
pg_background_18 1.9.3 el8.x86_64 pgdg 58.5 KiB pg_background_18-1.9.3-1PGDG.rhel8.10.x86_64.rpm
pg_background_18 1.9.2 el8.x86_64 pigsty 56.3 KiB pg_background_18-1.9.2-1PIGSTY.el8.x86_64.rpm
pg_background_18 1.9.2 el8.x86_64 pgdg 55.4 KiB pg_background_18-1.9.2-1PGDG.rhel8.10.x86_64.rpm
pg_background_18 1.9.1 el8.x86_64 pgdg 55.1 KiB pg_background_18-1.9.1-1PGDG.rhel8.10.x86_64.rpm
pg_background_18 1.6 el8.x86_64 pgdg 41.8 KiB pg_background_18-1.6-1PGDG.rhel8.10.x86_64.rpm
pg_background_18 1.5 el8.x86_64 pgdg 22.5 KiB pg_background_18-1.5-1PGDG.rhel8.x86_64.rpm
pg_background_18 1.9.3 el8.aarch64 pgdg 57.3 KiB pg_background_18-1.9.3-1PGDG.rhel8.10.aarch64.rpm
pg_background_18 1.9.2 el8.aarch64 pigsty 55.2 KiB pg_background_18-1.9.2-1PIGSTY.el8.aarch64.rpm
pg_background_18 1.9.2 el8.aarch64 pgdg 54.1 KiB pg_background_18-1.9.2-1PGDG.rhel8.10.aarch64.rpm
pg_background_18 1.9.1 el8.aarch64 pgdg 53.9 KiB pg_background_18-1.9.1-1PGDG.rhel8.10.aarch64.rpm
pg_background_18 1.8 el8.aarch64 pgdg 45.8 KiB pg_background_18-1.8-1PGDG.rhel8.10.aarch64.rpm
pg_background_18 1.6 el8.aarch64 pgdg 40.7 KiB pg_background_18-1.6-1PGDG.rhel8.10.aarch64.rpm
pg_background_18 1.5 el8.aarch64 pgdg 22.0 KiB pg_background_18-1.5-1PGDG.rhel8.aarch64.rpm
pg_background_18 1.9.3 el9.x86_64 pgdg 57.4 KiB pg_background_18-1.9.3-1PGDG.rhel9.7.x86_64.rpm
pg_background_18 1.9.2 el9.x86_64 pigsty 55.3 KiB pg_background_18-1.9.2-1PIGSTY.el9.x86_64.rpm
pg_background_18 1.9.2 el9.x86_64 pgdg 54.3 KiB pg_background_18-1.9.2-1PGDG.rhel9.7.x86_64.rpm
pg_background_18 1.9.1 el9.x86_64 pgdg 54.0 KiB pg_background_18-1.9.1-1PGDG.rhel9.7.x86_64.rpm
pg_background_18 1.8 el9.x86_64 pgdg 46.5 KiB pg_background_18-1.8-1PGDG.rhel9.7.x86_64.rpm
pg_background_18 1.6 el9.x86_64 pgdg 41.3 KiB pg_background_18-1.6-1PGDG.rhel9.7.x86_64.rpm
pg_background_18 1.5 el9.x86_64 pgdg 22.7 KiB pg_background_18-1.5-1PGDG.rhel9.x86_64.rpm
pg_background_18 1.9.3 el9.aarch64 pgdg 56.4 KiB pg_background_18-1.9.3-1PGDG.rhel9.7.aarch64.rpm
pg_background_18 1.9.2 el9.aarch64 pigsty 54.3 KiB pg_background_18-1.9.2-1PIGSTY.el9.aarch64.rpm
pg_background_18 1.9.2 el9.aarch64 pgdg 53.4 KiB pg_background_18-1.9.2-1PGDG.rhel9.7.aarch64.rpm
pg_background_18 1.9.1 el9.aarch64 pgdg 53.1 KiB pg_background_18-1.9.1-1PGDG.rhel9.7.aarch64.rpm
pg_background_18 1.8 el9.aarch64 pgdg 45.4 KiB pg_background_18-1.8-1PGDG.rhel9.7.aarch64.rpm
pg_background_18 1.6 el9.aarch64 pgdg 40.3 KiB pg_background_18-1.6-1PGDG.rhel9.7.aarch64.rpm
pg_background_18 1.5 el9.aarch64 pgdg 22.0 KiB pg_background_18-1.5-1PGDG.rhel9.aarch64.rpm
pg_background_18 1.9.3 el10.x86_64 pgdg 57.6 KiB pg_background_18-1.9.3-1PGDG.rhel10.1.x86_64.rpm
pg_background_18 1.9.2 el10.x86_64 pigsty 55.5 KiB pg_background_18-1.9.2-1PIGSTY.el10.x86_64.rpm
pg_background_18 1.9.2 el10.x86_64 pgdg 54.5 KiB pg_background_18-1.9.2-1PGDG.rhel10.1.x86_64.rpm
pg_background_18 1.9.1 el10.x86_64 pgdg 54.2 KiB pg_background_18-1.9.1-1PGDG.rhel10.1.x86_64.rpm
pg_background_18 1.8 el10.x86_64 pgdg 46.8 KiB pg_background_18-1.8-1PGDG.rhel10.1.x86_64.rpm
pg_background_18 1.6 el10.x86_64 pgdg 41.6 KiB pg_background_18-1.6-1PGDG.rhel10.1.x86_64.rpm
pg_background_18 1.5 el10.x86_64 pgdg 23.1 KiB pg_background_18-1.5-1PGDG.rhel10.x86_64.rpm
pg_background_18 1.9.3 el10.aarch64 pgdg 56.8 KiB pg_background_18-1.9.3-1PGDG.rhel10.1.aarch64.rpm
pg_background_18 1.9.2 el10.aarch64 pigsty 54.7 KiB pg_background_18-1.9.2-1PIGSTY.el10.aarch64.rpm
pg_background_18 1.9.2 el10.aarch64 pgdg 53.8 KiB pg_background_18-1.9.2-1PGDG.rhel10.1.aarch64.rpm
pg_background_18 1.9.1 el10.aarch64 pgdg 53.5 KiB pg_background_18-1.9.1-1PGDG.rhel10.1.aarch64.rpm
pg_background_18 1.8 el10.aarch64 pgdg 45.9 KiB pg_background_18-1.8-1PGDG.rhel10.1.aarch64.rpm
pg_background_18 1.6 el10.aarch64 pgdg 40.7 KiB pg_background_18-1.6-1PGDG.rhel10.1.aarch64.rpm
pg_background_18 1.5 el10.aarch64 pgdg 22.6 KiB pg_background_18-1.5-1PGDG.rhel10.aarch64.rpm
postgresql-18-pg-background 1.9.2 d12.x86_64 pgdg 58.9 KiB postgresql-18-pg-background_1.9.2-1.pgdg12+1_amd64.deb
postgresql-18-pg-background 1.9.2 d12.x86_64 pigsty 89.2 KiB postgresql-18-pg-background_1.9.2-1PIGSTY~bookworm_amd64.deb
postgresql-18-pg-background 1.9.1 d12.x86_64 pgdg 58.6 KiB postgresql-18-pg-background_1.9.1-1.pgdg12+1_amd64.deb
postgresql-18-pg-background 1.9.2 d12.aarch64 pgdg 57.0 KiB postgresql-18-pg-background_1.9.2-1.pgdg12+1_arm64.deb
postgresql-18-pg-background 1.9.2 d12.aarch64 pigsty 87.4 KiB postgresql-18-pg-background_1.9.2-1PIGSTY~bookworm_arm64.deb
postgresql-18-pg-background 1.9.1 d12.aarch64 pgdg 56.8 KiB postgresql-18-pg-background_1.9.1-1.pgdg12+1_arm64.deb
postgresql-18-pg-background 1.9.2 d13.x86_64 pgdg 58.7 KiB postgresql-18-pg-background_1.9.2-1.pgdg13+1_amd64.deb
postgresql-18-pg-background 1.9.2 d13.x86_64 pigsty 89.3 KiB postgresql-18-pg-background_1.9.2-1PIGSTY~trixie_amd64.deb
postgresql-18-pg-background 1.9.1 d13.x86_64 pgdg 58.7 KiB postgresql-18-pg-background_1.9.1-1.pgdg13+1_amd64.deb
postgresql-18-pg-background 1.9.2 d13.aarch64 pgdg 57.3 KiB postgresql-18-pg-background_1.9.2-1.pgdg13+1_arm64.deb
postgresql-18-pg-background 1.9.2 d13.aarch64 pigsty 87.9 KiB postgresql-18-pg-background_1.9.2-1PIGSTY~trixie_arm64.deb
postgresql-18-pg-background 1.9.1 d13.aarch64 pgdg 57.2 KiB postgresql-18-pg-background_1.9.1-1.pgdg13+1_arm64.deb
postgresql-18-pg-background 1.9.2 u22.x86_64 pgdg 59.7 KiB postgresql-18-pg-background_1.9.2-1.pgdg22.04+1_amd64.deb
postgresql-18-pg-background 1.9.2 u22.x86_64 pigsty 94.9 KiB postgresql-18-pg-background_1.9.2-1PIGSTY~jammy_amd64.deb
postgresql-18-pg-background 1.9.1 u22.x86_64 pgdg 59.8 KiB postgresql-18-pg-background_1.9.1-1.pgdg22.04+1_amd64.deb
postgresql-18-pg-background 1.9.2 u22.aarch64 pgdg 58.0 KiB postgresql-18-pg-background_1.9.2-1.pgdg22.04+1_arm64.deb
postgresql-18-pg-background 1.9.2 u22.aarch64 pigsty 93.6 KiB postgresql-18-pg-background_1.9.2-1PIGSTY~jammy_arm64.deb
postgresql-18-pg-background 1.9.1 u22.aarch64 pgdg 58.1 KiB postgresql-18-pg-background_1.9.1-1.pgdg22.04+1_arm64.deb
postgresql-18-pg-background 1.9.2 u24.x86_64 pgdg 58.8 KiB postgresql-18-pg-background_1.9.2-1.pgdg24.04+1_amd64.deb
postgresql-18-pg-background 1.9.2 u24.x86_64 pigsty 92.0 KiB postgresql-18-pg-background_1.9.2-1PIGSTY~noble_amd64.deb
postgresql-18-pg-background 1.9.1 u24.x86_64 pgdg 58.7 KiB postgresql-18-pg-background_1.9.1-1.pgdg24.04+1_amd64.deb
postgresql-18-pg-background 1.9.2 u24.aarch64 pgdg 57.2 KiB postgresql-18-pg-background_1.9.2-1.pgdg24.04+1_arm64.deb
postgresql-18-pg-background 1.9.2 u24.aarch64 pigsty 91.1 KiB postgresql-18-pg-background_1.9.2-1PIGSTY~noble_arm64.deb
postgresql-18-pg-background 1.9.1 u24.aarch64 pgdg 57.1 KiB postgresql-18-pg-background_1.9.1-1.pgdg24.04+1_arm64.deb
postgresql-18-pg-background 1.9.2 u26.x86_64 pgdg 58.4 KiB postgresql-18-pg-background_1.9.2-1.pgdg26.04+1_amd64.deb
postgresql-18-pg-background 1.9.2 u26.x86_64 pigsty 91.4 KiB postgresql-18-pg-background_1.9.2-1PIGSTY~resolute_amd64.deb
postgresql-18-pg-background 1.9.1 u26.x86_64 pgdg 58.3 KiB postgresql-18-pg-background_1.9.1-1.pgdg26.04+1_amd64.deb
postgresql-18-pg-background 1.9.2 u26.aarch64 pgdg 56.3 KiB postgresql-18-pg-background_1.9.2-1.pgdg26.04+1_arm64.deb
postgresql-18-pg-background 1.9.2 u26.aarch64 pigsty 89.9 KiB postgresql-18-pg-background_1.9.2-1PIGSTY~resolute_arm64.deb
postgresql-18-pg-background 1.9.1 u26.aarch64 pgdg 56.2 KiB postgresql-18-pg-background_1.9.1-1.pgdg26.04+1_arm64.deb

Source

pig build pkg pg_background;		# 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_background;		# install via package name, for the active PG version

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

Create this extension with:

CREATE EXTENSION pg_background;

Usage

Sources: official README, v1.9.2 release

pg_background executes SQL in PostgreSQL background worker processes. The worker runs inside the server and uses its own transaction, which makes it useful for asynchronous maintenance, autonomous side effects, and long-running tasks that should not block the caller.

CREATE EXTENSION pg_background;

SELECT * FROM pg_background_launch_v2(
  'SELECT count(*) FROM large_table',
  65536,
  'count-large-table'
) AS h;

SELECT * FROM pg_background_result_v2(h.pid, h.cookie) AS (count bigint);

Core API

  • pg_background_launch_v2(sql, queue_size, label) launches a tracked worker and returns (pid, cookie).
  • pg_background_submit_v2(sql, queue_size, label) is fire-and-forget for side-effect SQL.
  • pg_background_result_v2(pid, cookie) consumes the worker result set once.
  • pg_background_wait_v2(...) and pg_background_wait_v2_timeout(...) wait for completion.
  • pg_background_cancel_v2(...) stops execution; pg_background_detach_v2(...) stops tracking but lets work continue.
  • pg_background_list_v2(), pg_background_stats_v2(), and pg_background_get_progress_v2(...) expose worker state and progress.

Typical Patterns

Run maintenance without holding the client session open:

SELECT * FROM pg_background_submit_v2(
  'VACUUM (ANALYZE) public.events',
  65536,
  'vacuum-events'
);

Use an autonomous side effect from application SQL:

SELECT * FROM pg_background_submit_v2(
  $$INSERT INTO audit_log(ts, event) VALUES (clock_timestamp(), 'job queued')$$
);

GUCs And Security

  • pg_background.max_workers limits concurrent workers per session.
  • pg_background.default_queue_size controls the shared-memory queue size.
  • pg_background.worker_timeout sets an execution timeout; 0 means no limit.
  • The extension creates a dedicated pg_background_worker NOLOGIN role and ships helper functions to grant or revoke execution privileges.

Caveats

  • Prefer the V2 API. The older V1 API is still present for compatibility but lacks cookie-based PID reuse protection.
  • The v1.9.2 release is a binary-only patch for assert-enabled PostgreSQL builds. The SQL extension version remains 1.9, so there is no new SQL upgrade script or user-facing function delta from 1.9.1.
Last updated on