Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Transactions and savepoints

Each command has a dedicated page: BEGIN, START TRANSACTION, COMMIT, ROLLBACK, SAVEPOINT, RELEASE SAVEPOINT, and SET TRANSACTION.

Supported isolation levels are READ UNCOMMITTED, READ COMMITTED, REPEATABLE READ, and SERIALIZABLE.

Two-phase transactions (2PC)

With max_prepared_transactions greater than zero in amphi.conf and after restarting the server, an explicit transaction with an XID can be detached from the session that began it:

BEGIN;
INSERT INTO orders VALUES (42);
PREPARE TRANSACTION 'coordinator-order-42';

-- In another session, including after a server restart:
COMMIT PREPARED 'coordinator-order-42';
-- Or: ROLLBACK PREPARED 'coordinator-order-42';

PREPARE TRANSACTION writes and synchronizes the state before it responds. The GID is cluster-unique; XIDs and row locks stay active and are rebuilt during recovery until the final decision. sys.prepared_transactions lists pending transactions.

The current subset rejects preparation with catalog DDL, savepoints, pending extensions, queue operations, deferred foreign keys, or RESTART IDENTITY (0A000). A transaction without an XID or outside an explicit block fails with 25001; a duplicate GID fails with 42710; and an unknown GID in COMMIT PREPARED/ROLLBACK PREPARED fails with 42704. nextval remains non-transactional.

Logical backup cannot decide a coordinator transaction: ampdump refuses a dump while a prepared transaction exists. After it is resolved, dump and restore use the normal flow; they neither export nor recreate 2PC state.

Commit durability

The default is commit_durability = local: the server synchronizes commit WAL before acknowledging COMMIT. For ordinary DML, a session may opt into SET commit_durability = async; the response then follows WAL append without waiting for fsync, and a crash may lose already acknowledged commits. They remain visible while the process is alive. DDL, catalog operations, and every 2PC step continue to use local. wal_writer_delay limits the normal loss window but provides no absolute guarantee. The default is a recommendation; different environments may achieve better results with other settings. For a registered synchronous physical replica, SET commit_durability = 'replicas(1)' waits for one persisted replica ACK; replicas(n) waits for n synchronous replicas. If the quorum is not available, the commit fails in this first cut.