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.5 |
SIM
|
ISC
|
C
|
| Attribute | Has Binary | Has Library | Need Load | Has DDL | Relocatable | Trusted |
|---|---|---|---|---|---|---|
--sL---
|
No
|
Yes
|
Yes
|
No
|
no
|
no
|
| Relationships | |
|---|---|
| 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.5 |
18
17
16
15
14
|
pg_statement_rollback |
- |
| RPM | PGDG
|
1.5 |
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.5
|
PGDG 1.4
|
PGDG 1.4
|
PGDG 1.4
|
PGDG 1.4
|
el8.aarch64
|
PGDG 1.5
|
PGDG 1.4
|
PGDG 1.4
|
PGDG 1.4
|
PGDG 1.4
|
el9.x86_64
|
PGDG 1.5
|
PGDG 1.4
|
PGDG 1.4
|
PGDG 1.4
|
PGDG 1.4
|
el9.aarch64
|
PGDG 1.5
|
PGDG 1.4
|
PGDG 1.4
|
PGDG 1.4
|
PGDG 1.4
|
el10.x86_64
|
PGDG 1.5
|
PGDG 1.4
|
PGDG 1.4
|
PGDG 1.4
|
PGDG 1.4
|
el10.aarch64
|
PGDG 1.5
|
PGDG 1.4
|
PGDG 1.4
|
PGDG 1.4
|
PGDG 1.4
|
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
|
Source
pig build pkg pg_statement_rollback; # build debInstall
Make sure PGDG and PIGSTY repo available:
pig repo add pgsql -u # add both repo and update cacheInstall 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 14Config this extension to shared_preload_libraries:
shared_preload_libraries = 'pg_statement_rollback';This extension does not need CREATE EXTENSION DDL command
Usage
pg_statement_rollback: Server side rollback at statement level for PostgreSQL like Oracle or DB2
Provides automatic server-side savepoints before each statement, allowing individual statement failures without aborting the entire transaction.
Enabling
LOAD 'pg_statement_rollback.so';
SET pg_statement_rollback.enabled TO on;Or in postgresql.conf for all sessions:
session_preload_libraries = 'pg_statement_rollback'
pg_statement_rollback.enabled = onBasic Usage
BEGIN;
CREATE TABLE test(id integer);
INSERT INTO test SELECT 1;
SELECT COUNT(*) FROM test; -- returns 1
INSERT INTO test SELECT 'wrong'; -- ERROR: invalid input syntax
ROLLBACK TO SAVEPOINT "PgSLRAutoSvpt"; -- rollback only the failed statement
SELECT COUNT(*) FROM test; -- still returns 1
COMMIT;Without this extension, the error would abort the entire transaction and all subsequent statements would fail with “current transaction is aborted”.
Configuration
-- Enable/disable at any time in a session
SET pg_statement_rollback.enabled TO off;
-- Change the savepoint name (superuser only)
SET pg_statement_rollback.savepoint_name TO 'my_savepoint';
-- Limit savepoints to write-only statements (default: on)
SET pg_statement_rollback.enable_writeonly TO off;Key Behaviors
- Automatic savepoints are created server-side with minimal performance overhead
- By default, savepoints are only created after write statements (INSERT, UPDATE, DELETE, etc.)
- When
enable_writeonlyis on, SELECT statements do not trigger automatic savepoints - The client must still call
ROLLBACK TO SAVEPOINT "PgSLRAutoSvpt"when handling errors
Last updated on