Received: from localhost (maia-1.hub.org [200.46.204.191]) by postgresql.org (Postfix) with ESMTP id 2F9519FBD03 for ; Tue, 15 May 2007 23:02:43 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.191]) (amavisd-maia, port 10024) with ESMTP id 35284-08 for ; Tue, 15 May 2007 23:02:39 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from lists.commandprompt.com (host-254.commandprompt.net [207.173.203.254]) by postgresql.org (Postfix) with ESMTP id E39479FBCF4 for ; Tue, 15 May 2007 23:02:39 -0300 (ADT) Received: from perhan.alvh.no-ip.org (201-221-217-243.bk12-dsl.surnet.cl [201.221.217.243]) (authenticated bits=0) by lists.commandprompt.com (8.13.7/8.13.6) with ESMTP id l4G22Or3031228; Tue, 15 May 2007 19:02:26 -0700 Received: by perhan.alvh.no-ip.org (Postfix, from userid 1000) id 8AADD32A13; Tue, 15 May 2007 22:02:18 -0400 (CLT) Date: Tue, 15 May 2007 22:02:18 -0400 From: Alvaro Herrera To: "Jim C. Nasby" Cc: Tom Lane , Chris Browne , pgsql-patches@postgresql.org, Heikki Linnakangas Subject: Re: [DOCS] Autovacuum and XID wraparound Message-ID: <20070516020218.GX12731@alvh.no-ip.org> References: <20070514011740.GH14860@fetter.org> <23394.1179108400@sss.pgh.pa.us> <1179117269.6047.3.camel@goldbach> <60sl9z6tln.fsf@dba2.int.libertyrms.com> <20070514221619.GC8916@alvh.no-ip.org> <857.1179184222@sss.pgh.pa.us> <20070515221347.GT12731@alvh.no-ip.org> <20070516002500.GG20707@nasby.net> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="f0KYrhQ4vYSV2aJu" Content-Disposition: inline In-Reply-To: <20070516002500.GG20707@nasby.net> User-Agent: Mutt/1.5.13 (2006-08-11) X-Virus-Scanned: ClamAV version 0.88.5, clamav-milter version 0.88.5 on projects.commandprompt.com X-Virus-Status: Clean X-Greylist: Sender succeded SMTP AUTH authentication, not delayed by milter-greylist-1.6 (lists.commandprompt.com [192.168.2.159]); Tue, 15 May 2007 19:02:31 -0700 (PDT) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200705/226 X-Sequence-Number: 2326 --f0KYrhQ4vYSV2aJu Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Jim C. Nasby wrote: > On Tue, May 15, 2007 at 06:13:47PM -0400, Alvaro Herrera wrote: > > Tom Lane wrote: > > > Alvaro Herrera 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. --f0KYrhQ4vYSV2aJu Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="cluster-relfrozenxid.patch" 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; } /* --f0KYrhQ4vYSV2aJu--