Two-phase commit (2PC) coordinates an atomic transaction across database nodes: participants prepare first, then commit or abort according to the coordinator’s decision. PostgreSQL can protect each local transaction while an application still violates atomicity across nodes. section 5.6
The split account update
Suppose alpha debits an account from 100 to 90 while beta applies a gift and records 150. The business loses 10 while the customer receives an unintended 50: local ACID guarantees did not make the cross-node operation atomic. PREPARE TRANSACTION and its associated commands provide the two-phase mechanism, but prepared transactions should remain short-lived. section 5.6
Treat 2PC as a constrained operational tool:
- Expect latency and replication lag to complicate prepared transactions. section 5.6
- Run prepared transactions exclusively on the primary, potentially eliminating read-replica benefits. section 5.6
- Clean up incomplete transactions because they retain locks and may delay applications after crashes or restarts. section 5.6



