Diagnostic step 1
List prepared transactions: SELECT * FROM pg_prepared_xacts; note gid, prepared timestamp and owner.
Generated Oct 24, 2026, 9:21:01 AM
List prepared transactions: SELECT * FROM pg_prepared_xacts; note gid, prepared timestamp and owner.
If you can verify a prepared transaction is abandoned, run ROLLBACK PREPARED 'gid' on the primary to remove it; do this for one transaction at a time and monitor relfrozenxid/pg_stat_all_tables.
If multiple abandoned prepared txns exist, coordinate with application owners before ROLLBACK PREPARED. For emergency cleanup, ROLLBACK PREPARED is safe for abandoned work but will lose prepared updates.
Prevent recurrence: add application safeguards (ensure COMMIT/ROLLBACK PREPARED on failures), consider enabling idle_in_transaction_session_timeout for normal txns, and add monitoring/alerting for pg_prepared_xacts count.
Longer-term: avoid two-phase commits unless necessary; use idempotent design or outbox patterns for cross-service transactions.