Postgresql 中文操作指南
74.4. Two-Phase Transactions #
PostgreSQL 支持两阶段提交 (2PC) 协议,该协议允许多个分布式系统以事务方式协同工作。该命令是 PREPARE TRANSACTION、COMMIT PREPARED 和 ROLLBACK PREPARED。两阶段事务旨在供外部事务管理系统使用。PostgreSQL 遵循 X/Open XA 标准提出的特性和模型,但不实现一些较少使用的方面。
PostgreSQL supports a two-phase commit (2PC) protocol that allows multiple distributed systems to work together in a transactional manner. The commands are PREPARE TRANSACTION, COMMIT PREPARED and ROLLBACK PREPARED. Two-phase transactions are intended for use by external transaction management systems. PostgreSQL follows the features and model proposed by the X/Open XA standard, but does not implement some less often used aspects.
当用户执行 PREPARE TRANSACTION 时,唯一可能的下一条命令是 COMMIT PREPARED 或 ROLLBACK PREPARED 。一般情况下,此准备状态旨在持续非常短的时间,但外部可用性问题可能意味着事务在此状态下停留较长时间。短暂的已准备事务仅存储在共享内存和 WAL 中。跨越检查点的交易会记录在 pg_twophase 目录中。可使用 pg_prepared_xacts 检查当前已准备的事务。
When the user executes PREPARE TRANSACTION, the only possible next commands are COMMIT PREPARED or ROLLBACK PREPARED. In general, this prepared state is intended to be of very short duration, but external availability issues might mean transactions stay in this state for an extended interval. Short-lived prepared transactions are stored only in shared memory and WAL. Transactions that span checkpoints are recorded in the pg_twophase directory. Transactions that are currently prepared can be inspected using pg_prepared_xacts.