PostgreSQL

Prepared transactions hold locks indefinitely until commit or rollback

critical
Resource ContentionUpdated Feb 26, 2026
Technologies:
How to detect:

Prepared transactions continue to hold all locks acquired during the transaction but can never be in a waiting state. If a prepared transaction is not committed or rolled back, it will hold locks indefinitely, potentially blocking other processes.

Recommended action:

Query pg_locks joined with pg_prepared_xacts to identify locks held by prepared transactions: SELECT * FROM pg_locks pl LEFT JOIN pg_prepared_xacts ppx ON pl.virtualtransaction = '-1/' || ppx.transaction. Review prepared transactions and commit or rollback any that are no longer needed. Monitor age of prepared transactions and alert on those open longer than expected duration.