PostgreSQLDBA(24)-MVCC#4(快照中的xmax)

本节通过源码解释了snapshot中的xmax的具体含义.

成都创新互联公司专业IDC数据服务器托管提供商,专业提供成都服务器托管,服务器租用,成都服务器托管成都服务器托管,成都多线服务器托管等服务器托管服务。

一、xmax

上一节提到PostgreSQL通过txid_current_snapshot()函数获取快照,格式为xmin : xmax : xip_list,其中xmax应理解为最后已完结事务(COMMITTED/ABORTED)的txid + 1。
详见以下PG源码:


Snapshot
GetSnapshotData(Snapshot snapshot)
{
    /* xmax is always latestCompletedXid + 1 */
    xmax = ShmemVariableCache->latestCompletedXid;
    Assert(TransactionIdIsNormal(xmax));
    TransactionIdAdvance(xmax);
    /* initialize xmin calculation with xmax */
    globalxmin = xmin = xmax;
    ...
    snapshot->xmax = xmax;
    ...
    return snapshot;
}

xmax is always latestCompletedXid + 1,最后已完结事务(COMMITTED/ABORTED)的txid + 1(ShmemVariableCache->latestCompletedXid + 1)。

二、参考资料

PostgreSQL Source Code


名称栏目:PostgreSQLDBA(24)-MVCC#4(快照中的xmax)
本文路径:http://csdahua.cn/article/pcoged.html
扫二维码与项目经理沟通

我们在微信上24小时期待你的声音

解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流