TX 和 XID 分数在 postgres pgadmin 工具中代表什么

What do TX and XID fractions stand for in the postgres pgadmin tool

XID 和 TX 列中的分数代表什么。这是postgres的pgadmin工具的截图。

我明白TX和XID分别是交易和交易ID的意思,但是我不明白分数符号是什么意思。

虚拟交易 ID 的格式为 "n/nnnn"。真正的 XID 只是整数。虚拟 xid 的第一部分是每个连接唯一的后端标识符;第二部分是该连接的后端为其交易分配的临时交易 ID。

详见src/include/storage/lock.hVirtualTransactionId的定义


这些列似乎对应于 pg_locks 中的 virtualxid and/or transactionidvirtualtransaction 列。参见 the docs

如果我是对的,那么:

  • "TX"是持有或等待锁的事务的虚拟事务ID。
  • "XID" 是等待事务的目标事务的虚拟事务 ID,如果目标是虚拟 xid。在 PgAdmin 中,如果它是一个正常的 xid,它也可能会显示目标的 xid。

虚拟事务 ID 是 PostgreSQL 在事务开始时分配给每个事务的临时事务 ID。它们没有记录在磁盘上。真正的 xid 仅在事务执行需要事务写入磁盘的操作时分配。

根据链接手册:

Every transaction holds an exclusive lock on its virtual transaction ID for its entire duration. If a permanent ID is assigned to the transaction (which normally happens only if the transaction changes the state of the database), it also holds an exclusive lock on its permanent transaction ID until it ends. When one transaction finds it necessary to wait specifically for another transaction, it does so by attempting to acquire share lock on the other transaction ID (either virtual or permanent ID depending on the situation). That will succeed only when the other transaction terminates and releases its locks.