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

柔情痞子 提交于 2020-01-06 02:21:26

问题


What does the fractions in column XID and TX stand for. This is a screenshot of the postgres's pgadmin tool.

I understand that TX and XID mean transaction and transaction ID respectively, however I don't understand what the fraction notation means.


回答1:


Virtual transaction IDs have the "n/nnnn" format. Real XIDs are just integers. The first part of the virtual xid is a backend identifier that's unique to each connection; the second part is a temporary transaction id assigned by that connection's backend for its transactions.

See the definition of VirtualTransactionId in src/include/storage/lock.h for details.


Those columns appear to correspond to the virtualxid and/or transactionid and virtualtransaction columns in pg_locks. See the docs.

If I'm correct in that then:

  • "TX" is the virtual transaction ID of the transaction holding or awaiting the lock.
  • "XID" is the virtual transaction ID of the transaction targeted by the waiting transaction, if the target is a virtual xid. In PgAdmin it might also show the xid of the target if it's a normal xid.

Virtual transaction IDs are temporary, transient transaction IDs that PostgreSQL allocates to every transaction at transaction start. They aren't recorded on disk. A real xid is only allocated when the transaction does something that requires a transactional write to disk.

Per the linked manual:

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.



来源:https://stackoverflow.com/questions/33621510/what-do-tx-and-xid-fractions-stand-for-in-the-postgres-pgadmin-tool

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!