postgresql - What does backend_xmin and backend_xid represent in pg_stat_activity?
问题描述
Postgresql exposes the view pg_stat_activity
. As per the documentation,
backend_xid
means Top-level transaction identifier of this backend, if any.
backend_xmin
means The current backend's xmin horizon.
Let us take an example:
BEGIN;
# INSERT Statement1
# INSERT Statement2
COMMIT;
backend_xid
represents the transaction identifier allotted to the full transaction while if pg_stat_activity
shows the statement2 in its row, then backend_xmin
corresponds to the xmin
for statement2.
Is the understanding correct?
解决方案
These two values represent the snapshot of the transaction.
Whenever a query starts (or, with REPEATABLE READ
isolation level, when the first query in the transaction starts), PostgreSQL takes a snapshot of the database. That means that the query (or the transaction) sees a certain state of the database, no matter what concurrent data modifications happened in the meantime.
Such a snapshot consists of the oldest transaction ID of any active transaction at the time (xmin
), the transaction ID of the newest active transaction (xmax
) and a list of the transaction IDs of all currently active transactions. With the aid of these numbers, PostgreSQL can determine if a tuple (a row version) is visible or not.
backend_xmin
is relevant because (together with other values) the oldest one determines the xmin
horizon, which is the cut-off point for dead tuples that autovacuum can safely remove.
推荐阅读
- c++ - 额外的行作为 C++ 中的输出出现
- c++ - 如何在 wxRichToolTip、wxWidgets 中添加按钮?
- python - 删除重复项并使用最旧的值完成 nan 并优化运行时间
- javascript - 拖入反应后如何显示下一张幻灯片?
- amazon-web-services - 如何将变量导入 AWS ApiGateway 的 Swagger 文件
- mysql - 在 WHERE 子句中使用计数值
- javascript - 在 HTML 字段中复制/粘贴字符串
- javascript - Discord.js 将单词嵌入
- ios - iOS 中的内存泄漏 Kotlin Native 库
- c# - Sharepoint online - 不返回列表中特定视图中的项目