public inbox for [email protected]  
help / color / mirror / Atom feed
From: Alvaro Herrera <[email protected]>
To: Jim C. Nasby <[email protected]>
Cc: Tom Lane <[email protected]>
Cc: Chris Browne <[email protected]>
Cc: [email protected]
Cc: Heikki Linnakangas <[email protected]>
Subject: Re: [DOCS] Autovacuum and XID wraparound
Date: Tue, 15 May 2007 22:02:18 -0400
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>
References: <[email protected]>
	<[email protected]>
	<1179117269.6047.3.camel@goldbach>
	<[email protected]>
	<[email protected]>
	<[email protected]>
	<[email protected]>
	<[email protected]>

Jim C. Nasby wrote:
> On Tue, May 15, 2007 at 06:13:47PM -0400, Alvaro Herrera wrote:
> > Tom Lane wrote:
> > > Alvaro Herrera <[email protected]> writes:
> > > > I suppose it would be pretty trivial to set the relfrozenxid to
> > > > RecentXmin or something during TRUNCATE.
> > > 
> > > I had the idea we were doing that already --- at least I'm pretty sure I
> > > remember it being discussed.  But I see it's not being done in HEAD.
> > 
> > Patch to do it attached.  I am thinking we can do something similar in
> > CLUSTER as well.
> 
> Actually, it already happens for CLUSTER because cluster calls
> heap_create_with_catalog, which calls AddNewRelationTuple. See
> backend/catalog/heap.c line 716.

Right, but that heap is dropped later, and only the relfilenode remains,
because they are swapped.

In any case the change is a very small patch, which I attach but I
haven't tested.  This only works if the new rewriteheap stuff actually
changes Xids to follow OldestXmin, i.e. all tuples that have older
Xmin/Xmax are frozen (or marked with the current Xid).  Heikki, can you
confirm that this is the case?

-- 
Alvaro Herrera                                http://www.CommandPrompt.com/
The PostgreSQL Company - Command Prompt, Inc.


Attachments:

  [text/x-diff] cluster-relfrozenxid.patch (2.9K, 2-cluster-relfrozenxid.patch)
  download | inline diff:
Index: src/backend/commands/cluster.c
===================================================================
RCS file: /home/alvherre/Code/cvs/pgsql/src/backend/commands/cluster.c,v
retrieving revision 1.159
diff -c -p -r1.159 cluster.c
*** src/backend/commands/cluster.c	8 Apr 2007 01:26:28 -0000	1.159
--- src/backend/commands/cluster.c	15 May 2007 22:55:22 -0000
*************** typedef struct
*** 54,60 ****
  
  static void cluster_rel(RelToCluster *rv, bool recheck);
  static void rebuild_relation(Relation OldHeap, Oid indexOid);
! static void copy_heap_data(Oid OIDNewHeap, Oid OIDOldHeap, Oid OIDOldIndex);
  static List *get_tables_to_cluster(MemoryContext cluster_context);
  
  
--- 54,60 ----
  
  static void cluster_rel(RelToCluster *rv, bool recheck);
  static void rebuild_relation(Relation OldHeap, Oid indexOid);
! static TransactionId copy_heap_data(Oid OIDNewHeap, Oid OIDOldHeap, Oid OIDOldIndex);
  static List *get_tables_to_cluster(MemoryContext cluster_context);
  
  
*************** rebuild_relation(Relation OldHeap, Oid i
*** 512,517 ****
--- 512,518 ----
  	Oid			tableSpace = OldHeap->rd_rel->reltablespace;
  	Oid			OIDNewHeap;
  	char		NewHeapName[NAMEDATALEN];
+ 	TransactionId frozenXid;
  	ObjectAddress object;
  
  	/* Mark the correct index as clustered */
*************** rebuild_relation(Relation OldHeap, Oid i
*** 538,548 ****
  	/*
  	 * Copy the heap data into the new table in the desired order.
  	 */
! 	copy_heap_data(OIDNewHeap, tableOid, indexOid);
  
  	/* To make the new heap's data visible (probably not needed?). */
  	CommandCounterIncrement();
  
  	/* Swap the physical files of the old and new heaps. */
  	swap_relation_files(tableOid, OIDNewHeap);
  
--- 539,556 ----
  	/*
  	 * Copy the heap data into the new table in the desired order.
  	 */
! 	frozenXid = copy_heap_data(OIDNewHeap, tableOid, indexOid);
  
  	/* To make the new heap's data visible (probably not needed?). */
  	CommandCounterIncrement();
  
+ 	/*
+ 	 * update the relation's freeze Xid.  We don't need to change the 
+ 	 * actual tuple on disk, because swap_relation_files will do it for
+ 	 * us.
+ 	 */
+ 	OldHeap->rd_rel->relfrozenxid = frozenXid;
+ 
  	/* Swap the physical files of the old and new heaps. */
  	swap_relation_files(tableOid, OIDNewHeap);
  
*************** make_new_heap(Oid OIDOldHeap, const char
*** 640,648 ****
  }
  
  /*
!  * Do the physical copying of heap data.
   */
! static void
  copy_heap_data(Oid OIDNewHeap, Oid OIDOldHeap, Oid OIDOldIndex)
  {
  	Relation	NewHeap,
--- 648,657 ----
  }
  
  /*
!  * Do the physical copying of heap data.  Returns the transaction ID used as
!  * cutoff point.
   */
! static TransactionId
  copy_heap_data(Oid OIDNewHeap, Oid OIDOldHeap, Oid OIDOldIndex)
  {
  	Relation	NewHeap,
*************** copy_heap_data(Oid OIDNewHeap, Oid OIDOl
*** 809,814 ****
--- 818,825 ----
  	index_close(OldIndex, NoLock);
  	heap_close(OldHeap, NoLock);
  	heap_close(NewHeap, NoLock);
+ 
+ 	return OldestXmin;
  }
  
  /*


view thread (34+ messages)  latest in thread

reply

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 using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected], [email protected], [email protected], [email protected], [email protected]
  Subject: Re: [DOCS] Autovacuum and XID wraparound
  In-Reply-To: <[email protected]>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox