pg_background: Make Postgres do the long work (while your session stays light)

There’s a special kind of joy in watching a database do something heavy… without making your app threads cry.
That’s the promise of pg_background: execute SQL asynchronously in background worker processes inside PostgreSQL, so your client session can move on—while the work runs in its own transaction.
It’s a deceptively simple superpower:
pg_background enables PostgreSQL to execute SQL commands asynchronously in dedicated background worker processes. Unlike approaches such as opening another connection (e.g., dblink) or doing client-side async orchestration, these workers run inside the server with local resources and their own transaction scope.
It’s not a full-blown scheduler. It’s not a queueing platform. It’s a sharp tool: “run this SQL over there, and let me decide how to interact with it.”
I’m opinionated here: most teams don’t need more moving parts. They need fewer, with better failure modes.
pg_background shines when you need:
Common production patterns:
The project now strongly nudges new deployments toward the v2 API, which uses a (pid, cookie) handle to protect against PID reuse issues (a real-world footgun in long-lived systems).
From the repo docs, v2 brings: cookie-based identity, explicit cancellation vs detach, synchronous wait, and better monitoring via list functions.
That last point—detach is not cancel—is called out as an important semantic distinction.
Install is standard extension build + CREATE EXTENSION, but the “gotcha” is not subtle:
background workers consume max_worker_processes.
So size it intentionally.
The README walks through enabling the extension and setting max_worker_processes.
If you haven’t looked recently: the project has had a meaningful “production hardening” arc.
v1.6 (released Feb 5, 2026): production stabilization + v2 API becomes the star
This release explicitly positions itself as “stabilizes pg_background for production use” and introduces the recommended v2 API with cookie-based worker handles.
Highlights include:
Fixed items called out: NULL safety in error translation, race conditions in cleanup, memory context leaks in error paths, clearer error codes for cookie mismatches.
Known limitations that remain (still important in real deployments):
v1.7 (merged Feb 13, 2026): security + memory + CPU efficiency
v1.7 is where the internals got sharper edges sanded down—especially around handle security and long-running sessions.
Notable improvements listed in the v1.7 PR:
v1.8 (released Feb 13, 2026): operational controls + observability perks + packaging updates
The v1.8 release rolls up CI/packaging work and modernizes supported version stance: Docker-based CI refactor, tighter .gitignore, plus dropping PostgreSQL 13 and older to align with supported majors.
It also adds real operator-friendly features:
New in 1.8 (from the extension SQL and docs):
And if you’re upgrading, the README’s compatibility table is blunt: PG 14+ is the current minimum supported line, with guidance to use older pg_background versions for older Postgres majors.
A practical checklist for using pg_background safely
Here’s the “don’t make tomorrow-you hate today-you” list:
The best infrastructure is the kind that quietly does the work and refuses to be dramatic.
pg_background is that kind of tool: it gives PostgreSQL a clean, explicit async execution lane—now with safer handles (v2), stronger internals (v1.7), and operator-friendly controls and telemetry (v1.8).
If you want, paste your target use case (VACUUM jobs, backfills, “autonomous transaction” patterns, async ETL, etc.) and I’ll suggest a production-ready pattern with guardrails using the v2 API.
Alex Chen
Senior Tech EditorCovering the latest in consumer electronics and software updates. Obsessed with clean code and cleaner desks.