Diagnostic Queries
Symptoms
A COMMIT PREPARED/ROLLBACK PREPARED referenced a two-phase transaction identifier that does not exist. PostgreSQL raises SQLSTATE 3B000 (savepoint_exception).
- The named prepared (2PC) transaction isn’t present.
- Common after it was already committed/rolled back.
- Often a transaction-manager bookkeeping mismatch.
What the server log shows
ERROR: prepared transaction with identifier "txn-001" does not exist
Why PostgreSQL raises this — what the manual says
the COMMIT PREPARED reference (Description):
“commit a transaction that was earlier prepared for two-phase commit”
Prepared (two-phase) transactions are tracked by a global identifier in pg_prepared_xacts. Referencing an id that was never prepared (or already finalized) cannot be resolved, so PostgreSQL reports 3B000.
Common causes
- The prepared transaction was already committed/rolled back.
- A typo or stale id in the transaction manager.
- Connecting to the wrong cluster/node.
How to fix it
- List prepared transactions:
SELECT gid FROM pg_prepared_xacts;and use a valid id. - Make the transaction manager track 2PC state accurately.
- Verify you are on the correct database server.
Related & next steps
Reference: PostgreSQL 18 — COMMIT PREPARED.
Thanks — noted. This helps keep the database accurate.