Re: Make CLUSTER MVCC-safe - Mailing list pgsql-patches

From Bruce Momjian
Subject Re: Make CLUSTER MVCC-safe
Date
Msg-id 200703291608.l2TG8Y818015@momjian.us
Whole thread Raw
In response to Re: Make CLUSTER MVCC-safe  (Heikki Linnakangas <heikki@enterprisedb.com>)
List pgsql-patches
Your patch has been added to the PostgreSQL unapplied patches list at:

    http://momjian.postgresql.org/cgi-bin/pgpatches

It will be applied as soon as one of the PostgreSQL committers reviews
and approves it.

---------------------------------------------------------------------------


Heikki Linnakangas wrote:
> Here's an update, fixing conflict by Tom's recent commit of Simon's
> patch to skip WAL-inserts when archiving is not enabled.
>
> Heikki Linnakangas wrote:
> > This patch makes CLUSTER MVCC-safe. Visibility information and update
> > chains are preserved like in VACUUM FULL.
> >
> > I created a new generic rewriteheap-facility to handle rewriting tables
> > in a visibility-preserving manner. All the update chain tracking is done
> > in rewriteheap.c, the caller is responsible for supplying the stream of
> > tuples.
> >
> > CLUSTER is currently the only user of the facility, but I'm envisioning
> > we might have other users in the future. For example, a version of
> > VACUUM FULL that rewrites the whole table. We could also use it to make
> > ALTER TABLE MVCC-safe, but there's some issues with that. For example,
> > what to do if RECENTLY_DEAD tuples don't satisfy a newly added constraint.
> >
> > One complication in the implementation was the fact that heap_insert
> > overwrites the visibility information, and it doesn't write the full
> > tuple header to WAL. I ended up implementing a special-purpose
> > raw_heap_insert function instead, which is optimized for bulk inserting
> > a lot of tuples, knowing that we have exclusive access to the heap.
> > raw_heap_insert keeps the current buffer locked over calls, until it
> > gets full, and inserts the whole page to WAL as a single record using
> > the existing XLOG_HEAP_NEWPAGE record type.
> >
> > This makes CLUSTER a more viable alternative to VACUUM FULL. One
> > motivation for making CLUSTER MVCC-safe is that if some poor soul runs
> > pg_dump to make a backup concurrently with CLUSTER, the clustered tables
> > will appear to be empty in the dump file.
> >
> > The documentation doesn't anything about CLUSTER not being MVCC-safe, so
> > I suppose there's no need to touch the docs. I sent a doc patch earlier
> > to add a note about it, that doc patch should still be applied to older
> > release branches, IMO.
>
> --
>    Heikki Linnakangas
>    EnterpriseDB   http://www.enterprisedb.com


>
> ---------------------------(end of broadcast)---------------------------
> TIP 6: explain analyze is your friend

--
  Bruce Momjian  <bruce@momjian.us>          http://momjian.us
  EnterpriseDB                               http://www.enterprisedb.com

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

pgsql-patches by date:

Previous
From: Magnus Hagander
Date:
Subject: bgwriter stats
Next
From: Tom Lane
Date:
Subject: Re: bgwriter stats