企业🤖AI Agent构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
       在Postgres中,每一个事务都会得到一个被称作为 **txid** 的事务ID。PostgreSQL的txid是一个32位无符号整数,约为42亿(万亿)。如果在事务启动后执行内置的txid_current()函数,该函数将返回当前的txid。 ``` // 每个操作都会开启事务,默认auto commit postgres=# SELECT txid_current(); txid_current -------------- 485 (1 row) postgres=# SELECT txid_current(); txid_current -------------- 486 (1 row) // 手动开启事务,在同一个事务中,txid是相同的 postgres=# begin; BEGIN postgres=*# select txid_current(); txid_current -------------- 489 (1 row) postgres=*# select txid_current(); txid_current -------------- 489 (1 row) postgres=*# commit; COMMIT postgres=# select txid_current(); txid_current -------------- 490 (1 row) ``` PostgreSQL保留以下三种特殊TXID: * 0表示无效的txid。 * 1表示引导txid,它仅用于数据库集群的初始化。 * 2指第5.10.1节所述的冷冻TXI。        TXID可以相互比较。例如,对于 txid 值为 100 的事务而言,所有小于 100 的事务是发生在过去的,可见的;而所有大于 100 的事务,是发生在未来,即不可见的。 ![](https://img.kancloud.cn/ac/63/ac63e11c80f8f9c74e65018e033cfc14_1050x443.png)