Skip site navigation (1) Skip section navigation (2)

Improvement of procArray.xmin for VACUUM

From: Bruce Momjian <bruce(at)momjian(dot)us>
To: PostgreSQL-patches <pgsql-patches(at)postgresql(dot)org>
Subject: Improvement of procArray.xmin for VACUUM
Date: 2007-03-23 21:02:41
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-patches
VACUUM treats dead tuple with an xmax less than all procArray.xmin's as
invisible with space ready to be reused.

Right now, we set procArray.xmin at transaction start to the required
SERIALIZABLE value.  We currently don't update procArray.xmin when we
know we are in a READ COMMITTED transaction, even though we already call

This means that if a transaction completes that was active when our
transaction started, we don't update our procArray.xmin during the next
multi-statement transaction command to indicate that we don't care about
the completed transaction anymore.

I have been thinking we could improve how quickly VACUUM can expire rows
if we update procArray.xmin more frequently for non-SERIALIZABLE

The attached patch updates procArray.xmin in this manner.  Here is an
example of how the patch improves dead row reuse:

Session #:
        1                               2               3

        CREATE TABLE test(x int);
        INSERT INTO test VALUES (1);
        DELETE FROM test;
                                        SELECT 1;
                                                        VACUUM VERBOSE test;
                                                        (row not reused)
                                        SELECT 1;

                                        (At this point #2 doesn't see
                                         the test row anymore.  Patch 
                                         updates procArray.xmin.)

                                                        VACUUM VERBOSE test;
                                                        (row reused with patch)
                                                        VACUUM VERBOSE test;
                                                        (normal row reuse)

What the patch does is to recompute procArray.xmin during the second
SELECT, which is then used by the next VACUUM.

The patch has debug code that prints the procArray.xmin assignments.  I
am not sure if I have all the boolean calls to GetTransactionSnapshot()
correct.  The set_procArray_xmin parameter should be true only when we
are sure we aren't going to be resetting the session back to an earlier

The major affect of the patch is to set the minimum procArray.xmin to be
the earliest in-process transaction, rather than the earliest in-process
transaction at transaction start.

  Bruce Momjian  <bruce(at)momjian(dot)us>

  + If your life is a hard drive, Christ can be your backup. +

Attachment: /pgpatches/xid
Description: text/x-diff (17.6 KB)


pgsql-patches by date

Next:From: Alvaro HerreraDate: 2007-03-23 21:13:14
Subject: Re: Improvement of procArray.xmin for VACUUM
Previous:From: Magnus HaganderDate: 2007-03-23 19:18:43
Subject: Re: seg regression failures

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group