pg_background 2.0 is a major release of the PostgreSQL extension that enables running SQL in independent background worker processes with their own transaction lifecycle. Key changes include: promoting clean unsuffixed API names as canonical (dropping the _v2 suffix while keeping deprecated aliases), consolidating cancellation and wait functions into single entry points with optional parameters, removing the redundant pg_background_status_v2() in favor of to_jsonb(pg_background_outcome()), improved observability with structured error info and result metadata including timing, stricter security defaults by revoking PUBLIC access and introducing a dedicated pgbackground_role, and PostgreSQL 19 beta compatibility. The release also adds convenience helpers for fan-out workloads, label-based cancellation, and worker draining. Upgrade is a single ALTER EXTENSION command, with deprecated aliases providing migration runway for existing _v2 callers.

28m read timeFrom postgr.es
Post cover image
Table of contents
The Core Mental Model Is Independent SQL Execution Inside PostgreSQLThe Canonical API Drops the Historical _v2 Suffix Without Breaking Existing CodeCancellation and Waiting Now Use One Function Each With Optional Parameterspg_background_status_v2() Is Removed Because JSON Can Be Built From the Outcome SnapshotProgress Reporting and Privilege Helpers Now Use Clearer NamesObservability Now Gives Operators More Useful SignalsConvenience Helpers Support Common Production Patterns Without Hiding the PrimitiveSecurity Defaults Are Stricter Because Background SQL Is PowerfulPostgreSQL 19 Beta Readiness Reduces Future Upgrade RiskThe Upgrade Path Is Designed to Avoid a Rewrite WeekendWhere pg_background Fits and Where It Does NotGetting Started With pg_background 2.0Why pg_background 2.0 Matters
19.4K Impressions