Re: a few questions (and doubts) about xid - Mailing list pgsql-general

From Alvaro Herrera
Subject Re: a few questions (and doubts) about xid
Date
Msg-id 20070725154609.GD2581@alvh.no-ip.org
Whole thread Raw
In response to Re: a few questions (and doubts) about xid  (Gregory Stark <stark@enterprisedb.com>)
Responses Re: a few questions (and doubts) about xid  (Gregory Stark <stark@enterprisedb.com>)
List pgsql-general
Gregory Stark wrote:

> > Just for confirmation: the relfrozenxid of a fresh table is the xid of the
> > transaction that created it, isn't it?
>
> Yes, easily enough checked:
>
> postgres=# create table xyz (i integer);
> CREATE TABLE
> postgres=# select xmin,relfrozenxid from pg_class where relname = 'xyz';
>   xmin   | relfrozenxid
> ---------+--------------
>  4971524 |      4971524
> (1 row)

No it's not.  It's the XID of the earliest transaction that was open at
the time you created the table (known as RecentXid).

The idea of relfrozenxid is to be "the earliest XID that is written
anywhere on a tuple on this table".  When the table is created, the
earliest XID is not the one of the creating transaction, because there
can be an older transaction that inserts a new tuple when the creating
transaction commits.

When VACUUM scans the table, it uses a "freeze cutoff point" (meaning
the XID before which all XIDs are going to be folded into FrozenXid)
which is what stored into relfrozenxid.  In 8.3, the rewriting forms of
ALTER TABLE, CLUSTER and TRUNCATE also advance the relfrozenxid.

--
Alvaro Herrera                                http://www.CommandPrompt.com/
PostgreSQL Replication, Consulting, Custom Development, 24x7 support

pgsql-general by date:

Previous
From: Michael Fuhr
Date:
Subject: Re: Backslah in encrypt function.
Next
From: "L. Berger"
Date:
Subject: More than one characters in DELIMITER (for COPY)