本文介绍了postgresql中txid_current()中的epoch是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

https://www.postgresql.org/docs/10/static/functions-info.html#FUNCTIONS-TXID-SNAPSHOT

内部事务 ID 类型 (xid) 为 32 位宽,每 40 亿个事务环绕一次.但是,这些函数导出 64 位格式,该格式使用纪元"计数器进行扩展,因此它不会在安装的生命周期内回绕

这个纪元在这句话中是什么意思?这是 xid 达到 40 亿次交易并被重置为零的次数吗?

What is the meaning of this epoch in this sentence? Is this a counter of how many times the xid reached 4billion transactions and was reseted to zero?

我是否正确理解 txid_current() 返回一个 64 位数字,它基本上由两个 32 位数字连接在一起组成?前 32 位是纪元计数器(从 0 开始),后 32 位是 xid?

Do I understand correctly that txid_current() returns a 64-bit number which is basically composed from two 32 bit numbers concatenated together? This first 32 bits are an epoch counter (which starts at 0) and the last 32 bits are xid?

我假设当 xid 达到其最大值时,纪元计数器将变为 0 并且 xid 重置为 0.我认为,这基本上使 txid_current() 表现得像一个普通的 64 位数字.

I assume that when xid reaches its maximum value the epoch counter will be bumped to 0 and the xid resets to 0. Which, I assume, basically makes the txid_current() behave like a normal 64-bit numer.

它是这样工作的吗?我很难理解这一点.

Is that how it works? I have a hard time understanding this.

推荐答案

Epoch 用于防止 txid_current() 环绕并从零开始(或者准确地说是从 3 开始,因为值 0,1,2 在内部使用).

Epoch is used to prevent txid_current() from wrapping around and starting from zero (or to be exact from 3 because values 0,1,2 re used internally).

所以它很简单:

Postgres 有一个内部 32 位 xid 计数器,它与 txid_current() 返回的值不同.内部 xid 环绕并在每次环绕时重置其计数.

Postgres has an internal 32bit xid counter which is different than the value returned by txid_current(). The internal xid wraps around and resets its counting at every wraparound.

另一方面,txid_current() 返回 64 位(bigint),其中高位是一个纪元增量,每个 xid 环绕发生一次并且不从零开始.

The txid_current(), on the other hand, returns 64bit (bigint) in which the high bits are an epoch increment which happens once per xid wrap around and does not start from zero.

因此,在每次环绕时,epoch 都会开始,txid_current() 的高位会被修改以防止 txids 重置,并且 txids 会不断增加,直到达到 64 位限制(有时在我们都死后很长一段时间内)).

So at every wraparound the epoch kicks in and the high bits of txid_current() get modified to prevent txids from resetting, and instead txids keep incrementing until the 64bit limit is reached (sometimes in a very far future long after we all die).

这篇关于postgresql中txid_current()中的epoch是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-15 22:37