Skip to content
pg_statement_rollback

pg_statement_rollback

pg_statement_rollback : Server side rollback at statement level for PostgreSQL like Oracle or DB2

Overview

ID Extension Package Version Category License Language
9130
pg_statement_rollback
pg_statement_rollback
1.6
SIM
ISC
C
Attribute Has Binary Has Library Need Load Has DDL Relocatable Trusted
--sL---
No
Yes
Yes
No
no
no
Relationships
Need By
pg_dbms_errlog
See Also
oracle_fdw
orafce
pgtt
session_variable
safeupdate
pg_dbms_metadata
pg_dbms_lock
pg_hint_plan

Packages

Type Repo Version PG Major Compatibility Package Pattern Dependencies
EXT
MIXED
1.6
18
17
16
15
14
pg_statement_rollback -
RPM
PGDG
1.6
18
17
16
15
14
pg_statement_rollback_$v -
DEB
PIGSTY
1.5
18
17
16
15
14
postgresql-$v-pg-statement-rollback -
Linux / PG PG18 PG17 PG16 PG15 PG14
el8.x86_64
PGDG 1.6
PGDG 1.6
PGDG 1.6
PGDG 1.6
PGDG 1.6
el8.aarch64
PGDG 1.6
PGDG 1.6
PGDG 1.6
PGDG 1.6
PGDG 1.6
el9.x86_64
PGDG 1.6
PGDG 1.6
PGDG 1.6
PGDG 1.6
PGDG 1.6
el9.aarch64
PGDG 1.6
PGDG 1.6
PGDG 1.6
PGDG 1.6
PGDG 1.6
el10.x86_64
PGDG 1.6
PGDG 1.6
PGDG 1.6
PGDG 1.6
PGDG 1.6
el10.aarch64
PGDG 1.6
PGDG 1.6
PGDG 1.6
PGDG 1.6
PGDG 1.6
d12.x86_64
PIGSTY 1.5
PIGSTY 1.5
PIGSTY 1.5
PIGSTY 1.5
PIGSTY 1.5
d12.aarch64
PIGSTY 1.5
PIGSTY 1.5
PIGSTY 1.5
PIGSTY 1.5
PIGSTY 1.5
d13.x86_64
PIGSTY 1.5
PIGSTY 1.5
PIGSTY 1.5
PIGSTY 1.5
PIGSTY 1.5
d13.aarch64
PIGSTY 1.5
PIGSTY 1.5
PIGSTY 1.5
PIGSTY 1.5
PIGSTY 1.5
u22.x86_64
PIGSTY 1.5
PIGSTY 1.5
PIGSTY 1.5
PIGSTY 1.5
PIGSTY 1.5
u22.aarch64
PIGSTY 1.5
PIGSTY 1.5
PIGSTY 1.5
PIGSTY 1.5
PIGSTY 1.5
u24.x86_64
PIGSTY 1.5
PIGSTY 1.5
PIGSTY 1.5
PIGSTY 1.5
PIGSTY 1.5
u24.aarch64
PIGSTY 1.5
PIGSTY 1.5
PIGSTY 1.5
PIGSTY 1.5
PIGSTY 1.5
u26.x86_64
PIGSTY 1.5
PIGSTY 1.5
PIGSTY 1.5
PIGSTY 1.5
PIGSTY 1.5
u26.aarch64
PIGSTY 1.5
PIGSTY 1.5
PIGSTY 1.5
PIGSTY 1.5
PIGSTY 1.5
Package Version OS ORG SIZE File URL
pg_statement_rollback_18 1.6 el8.x86_64 pgdg 20.5 KiB pg_statement_rollback_18-1.6-1PGDG.rhel8.10.x86_64.rpm
pg_statement_rollback_18 1.5 el8.x86_64 pgdg 20.1 KiB pg_statement_rollback_18-1.5-1PGDG.rhel8.x86_64.rpm
pg_statement_rollback_18 1.6 el8.aarch64 pgdg 20.3 KiB pg_statement_rollback_18-1.6-1PGDG.rhel8.10.aarch64.rpm
pg_statement_rollback_18 1.5 el8.aarch64 pgdg 19.8 KiB pg_statement_rollback_18-1.5-1PGDG.rhel8.aarch64.rpm
pg_statement_rollback_18 1.6 el9.x86_64 pgdg 19.8 KiB pg_statement_rollback_18-1.6-1PGDG.rhel9.8.x86_64.rpm
pg_statement_rollback_18 1.5 el9.x86_64 pgdg 19.6 KiB pg_statement_rollback_18-1.5-3PGDG.rhel9.8.x86_64.rpm
pg_statement_rollback_18 1.5 el9.x86_64 pgdg 19.5 KiB pg_statement_rollback_18-1.5-1PGDG.rhel9.x86_64.rpm
pg_statement_rollback_18 1.6 el9.aarch64 pgdg 19.6 KiB pg_statement_rollback_18-1.6-1PGDG.rhel9.8.aarch64.rpm
pg_statement_rollback_18 1.5 el9.aarch64 pgdg 19.4 KiB pg_statement_rollback_18-1.5-3PGDG.rhel9.8.aarch64.rpm
pg_statement_rollback_18 1.5 el9.aarch64 pgdg 19.1 KiB pg_statement_rollback_18-1.5-1PGDG.rhel9.aarch64.rpm
pg_statement_rollback_18 1.6 el10.x86_64 pgdg 19.9 KiB pg_statement_rollback_18-1.6-1PGDG.rhel10.2.x86_64.rpm
pg_statement_rollback_18 1.5 el10.x86_64 pgdg 19.8 KiB pg_statement_rollback_18-1.5-3PGDG.rhel10.2.x86_64.rpm
pg_statement_rollback_18 1.5 el10.x86_64 pgdg 19.8 KiB pg_statement_rollback_18-1.5-1PGDG.rhel10.x86_64.rpm
pg_statement_rollback_18 1.6 el10.aarch64 pgdg 19.9 KiB pg_statement_rollback_18-1.6-1PGDG.rhel10.2.aarch64.rpm
pg_statement_rollback_18 1.5 el10.aarch64 pgdg 19.8 KiB pg_statement_rollback_18-1.5-3PGDG.rhel10.2.aarch64.rpm
pg_statement_rollback_18 1.5 el10.aarch64 pgdg 19.8 KiB pg_statement_rollback_18-1.5-1PGDG.rhel10.aarch64.rpm
postgresql-18-pg-statement-rollback 1.5 d12.x86_64 pigsty 28.1 KiB postgresql-18-pg-statement-rollback_1.5-2PIGSTY~bookworm_amd64.deb
postgresql-18-pg-statement-rollback 1.5 d12.aarch64 pigsty 27.9 KiB postgresql-18-pg-statement-rollback_1.5-2PIGSTY~bookworm_arm64.deb
postgresql-18-pg-statement-rollback 1.5 d13.x86_64 pigsty 28.1 KiB postgresql-18-pg-statement-rollback_1.5-2PIGSTY~trixie_amd64.deb
postgresql-18-pg-statement-rollback 1.5 d13.aarch64 pigsty 28.0 KiB postgresql-18-pg-statement-rollback_1.5-2PIGSTY~trixie_arm64.deb
postgresql-18-pg-statement-rollback 1.5 u22.x86_64 pigsty 28.5 KiB postgresql-18-pg-statement-rollback_1.5-2PIGSTY~jammy_amd64.deb
postgresql-18-pg-statement-rollback 1.5 u22.aarch64 pigsty 28.6 KiB postgresql-18-pg-statement-rollback_1.5-2PIGSTY~jammy_arm64.deb
postgresql-18-pg-statement-rollback 1.5 u24.x86_64 pigsty 28.4 KiB postgresql-18-pg-statement-rollback_1.5-2PIGSTY~noble_amd64.deb
postgresql-18-pg-statement-rollback 1.5 u24.aarch64 pigsty 28.4 KiB postgresql-18-pg-statement-rollback_1.5-2PIGSTY~noble_arm64.deb
postgresql-18-pg-statement-rollback 1.5 u26.x86_64 pigsty 28.0 KiB postgresql-18-pg-statement-rollback_1.5-2PIGSTY~resolute_amd64.deb
postgresql-18-pg-statement-rollback 1.5 u26.aarch64 pigsty 28.2 KiB postgresql-18-pg-statement-rollback_1.5-2PIGSTY~resolute_arm64.deb

Source

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

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

Config this extension to shared_preload_libraries:

shared_preload_libraries = 'pg_statement_rollback';

This extension does not need CREATE EXTENSION DDL command

Usage

Sources:

pg_statement_rollback keeps an explicit transaction usable after a statement error by creating an automatic savepoint before each eligible statement. It emulates the statement-level rollback behavior familiar from some other databases, but the client must still issue ROLLBACK TO SAVEPOINT after an error.

The module is loaded into a backend and does not require CREATE EXTENSION.

Load the Module

Load it for one session:

LOAD 'pg_statement_rollback.so';

For a selected role or database, add it to session_preload_libraries and reconnect:

session_preload_libraries = 'pg_statement_rollback'

Use shared_preload_libraries only if the deployment specifically needs server-wide loading; changing either preload list at server scope requires the corresponding restart or reconnect boundary.

Recover from a Failed Statement

BEGIN;
INSERT INTO accounts(id, balance) VALUES (1, 100);
INSERT INTO accounts(id, balance) VALUES (1, 200);
-- duplicate-key error
ROLLBACK TO SAVEPOINT "PgSLRAutoSvpt";
UPDATE accounts SET balance = 150 WHERE id = 1;
COMMIT;

The savepoint name is case-sensitive when quoted. Applications must detect the statement error and send the rollback command before continuing.

Configuration Index

  • pg_statement_rollback.enabled enables automatic savepoints for the current session.
  • pg_statement_rollback.savepoint_name changes the automatic savepoint name and is superuser-controlled.
  • pg_statement_rollback.enable_writeonly limits savepoint creation to statements that can write.

Version 1.6 Behavior

Version 1.6 adds PostgreSQL 19 build support and improves detection of read-only transactions. The module no longer creates automatic savepoints in read-only transactions and releases its initial savepoint before SET TRANSACTION … READ ONLY, which avoids interfering with dump and other read-only sessions.

Caveats

  • This is not transparent retry logic: clients must explicitly roll back to the automatic savepoint.
  • Savepoints add overhead to every covered statement. Measure write-heavy workloads before enabling the module broadly.
  • The upstream README warns of a crash with assertion-enabled PostgreSQL builds; do not treat development-build behavior as production-safe without testing.
  • Transaction-wide errors, connection failures, and errors that invalidate the session cannot be repaired by a savepoint.
Last updated on