From: Tom Lane <tgl@sss.pgh.pa.us>
To: Martín Fernández <fmartin91@gmail.com>
Cc: pgsql-generallists.postgresql.org <pgsql-general@lists.postgresql.org>
Subject: Re: Transaction Id Space, Freezing and Wraparound
Date: Tue, 20 Nov 2018 16:00:17 -0500
Message-ID: <31771.1542747617@sss.pgh.pa.us> (raw)
In-Reply-To: <5bf45ed1ab1e814ed9000008@polymail.io>
References: <5bf45ed1ab1e814ed9000008@polymail.io>
=?UTF-8?q?Mart=C3=ADn_Fern=C3=A1ndez?= <fmartin91@gmail.com> writes:
> First thing that generated a lot of noise in my head was the following, if pg assigns contiguous numeric values for the txid, how does pg deal with fragmentation issues ? Then I later found that the txid space is actually circular and not linearly as I originally thought it was. This exposed me to the fact that the txid is actually exported as a 64bit value where the last 32bits are an epoch. My understanding is that the epoch is the component that allows the circularity of the data structure. I then started analyzing how pg decides if a given tuple is eligible for freezing. I found out that pg will compare a cutoff_tx (I assume this is the last committed tx) with the xmin value of the given tuple, if xmin precedes the cutoff_tx the tuple is eligible (I’m ignoring HEAP_XMAX_IS_MULTI and HEAP_MOVED cases). Now, the xmin of a tuple is an 32 bit integer, so, how is the epoch part of an exported txid considered here ? What if we had a database really old where a txid with integer value 10 is greater than a txid of value 1000 ?
Actually, XID epoch is an artifact that's bolted on for possible use by
replication or what have you. So far as the core database is concerned,
XIDs are 32 bits in a circular space, and the way that we deal with your
question is we don't let the case arise. Every old tuple must be marked
"frozen" before its XID gets to be 2 billion XIDs old; after that, we
don't particularly care just how old it is. The whole "wraparound"
business just exists to make sure that happens in time.
If the stored XIDs were 64 bits wide, we'd not have to bother with all
of this mess ... but adding another 64 bits to tuple headers would be
a painful space cost, not to mention the storage compatibility issues.
regards, tom lane
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: tgl@sss.pgh.pa.us, fmartin91@gmail.com
Subject: Re: Transaction Id Space, Freezing and Wraparound
In-Reply-To: <31771.1542747617@sss.pgh.pa.us>
References: <5bf45ed1ab1e814ed9000008@polymail.io> <31771.1542747617@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox