Received: from localhost (maia-1.hub.org [200.46.204.191]) by postgresql.org (Postfix) with ESMTP id 9D30A9FBCEE for ; Tue, 15 May 2007 19:14:05 -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 80885-07 for ; Tue, 15 May 2007 19:13:59 -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 E16C49FBCB5 for ; Tue, 15 May 2007 19:13:58 -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 l4FMDqGT025479; Tue, 15 May 2007 15:13:53 -0700 Received: by perhan.alvh.no-ip.org (Postfix, from userid 1000) id 46F5432A13; Tue, 15 May 2007 18:13:47 -0400 (CLT) Date: Tue, 15 May 2007 18:13:47 -0400 From: Alvaro Herrera To: Tom Lane Cc: Chris Browne , pgsql-patches@postgresql.org Subject: Re: [DOCS] Autovacuum and XID wraparound Message-ID: <20070515221347.GT12731@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> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="nVMJ2NtxeReIH9PS" Content-Disposition: inline In-Reply-To: <857.1179184222@sss.pgh.pa.us> 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 15:13:54 -0700 (PDT) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200705/219 X-Sequence-Number: 2319 --nVMJ2NtxeReIH9PS Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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. -- Alvaro Herrera http://www.CommandPrompt.com/ The PostgreSQL Company - Command Prompt, Inc. --nVMJ2NtxeReIH9PS Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="truncate-relfrozenxid.patch" Index: src/backend/catalog/index.c =================================================================== RCS file: /home/alvherre/Code/cvs/pgsql/src/backend/catalog/index.c,v retrieving revision 1.282 diff -c -p -r1.282 index.c *** src/backend/catalog/index.c 29 Mar 2007 00:15:37 -0000 1.282 --- src/backend/catalog/index.c 15 May 2007 22:06:12 -0000 *************** index_update_stats(Relation rel, bool ha *** 1188,1196 **** * setNewRelfilenode - assign a new relfilenode value to the relation * * Caller must already hold exclusive lock on the relation. */ void ! setNewRelfilenode(Relation relation) { Oid newrelfilenode; RelFileNode newrnode; --- 1188,1199 ---- * setNewRelfilenode - assign a new relfilenode value to the relation * * Caller must already hold exclusive lock on the relation. + * + * The relation is marked with relfrozenxid=freezeXid (InvalidTransactionId + * must be passed for indexes) */ void ! setNewRelfilenode(Relation relation, TransactionId freezeXid) { Oid newrelfilenode; RelFileNode newrnode; *************** setNewRelfilenode(Relation relation) *** 1204,1209 **** --- 1207,1216 ---- relation->rd_rel->relkind == RELKIND_INDEX); /* Can't change for shared tables or indexes */ Assert(!relation->rd_rel->relisshared); + /* Indexes must have Invalid frozenxid; other relations must not */ + Assert((relation->rd_rel->relkind == RELKIND_INDEX && + freezeXid == InvalidTransactionId) || + TransactionIdIsNormal(freezeXid)); /* Allocate a new relfilenode */ newrelfilenode = GetNewRelFileNode(relation->rd_rel->reltablespace, *************** setNewRelfilenode(Relation relation) *** 1241,1246 **** --- 1248,1254 ---- rd_rel->relfilenode = newrelfilenode; rd_rel->relpages = 0; /* it's empty until further notice */ rd_rel->reltuples = 0; + rd_rel->relfrozenxid = freezeXid; simple_heap_update(pg_class, &tuple->t_self, tuple); CatalogUpdateIndexes(pg_class, tuple); *************** reindex_index(Oid indexId) *** 1957,1963 **** /* * We'll build a new physical relation for the index. */ ! setNewRelfilenode(iRel); } /* Initialize the index and rebuild */ --- 1965,1971 ---- /* * We'll build a new physical relation for the index. */ ! setNewRelfilenode(iRel, InvalidTransactionId); } /* Initialize the index and rebuild */ Index: src/backend/commands/tablecmds.c =================================================================== RCS file: /home/alvherre/Code/cvs/pgsql/src/backend/commands/tablecmds.c,v retrieving revision 1.223 diff -c -p -r1.223 tablecmds.c *** src/backend/commands/tablecmds.c 14 May 2007 20:24:41 -0000 1.223 --- src/backend/commands/tablecmds.c 15 May 2007 22:08:33 -0000 *************** ExecuteTruncate(TruncateStmt *stmt) *** 616,622 **** * the relfilenode value. The old storage file is scheduled for * deletion at commit. */ ! setNewRelfilenode(rel); heap_relid = RelationGetRelid(rel); toast_relid = rel->rd_rel->reltoastrelid; --- 616,622 ---- * the relfilenode value. The old storage file is scheduled for * deletion at commit. */ ! setNewRelfilenode(rel, RecentXmin); heap_relid = RelationGetRelid(rel); toast_relid = rel->rd_rel->reltoastrelid; *************** ExecuteTruncate(TruncateStmt *stmt) *** 629,635 **** if (OidIsValid(toast_relid)) { rel = relation_open(toast_relid, AccessExclusiveLock); ! setNewRelfilenode(rel); heap_close(rel, NoLock); } --- 629,635 ---- if (OidIsValid(toast_relid)) { rel = relation_open(toast_relid, AccessExclusiveLock); ! setNewRelfilenode(rel, RecentXmin); heap_close(rel, NoLock); } Index: src/include/catalog/index.h =================================================================== RCS file: /home/alvherre/Code/cvs/pgsql/src/include/catalog/index.h,v retrieving revision 1.73 diff -c -p -r1.73 index.h *** src/include/catalog/index.h 9 Jan 2007 02:14:15 -0000 1.73 --- src/include/catalog/index.h 15 May 2007 21:59:31 -0000 *************** extern void FormIndexDatum(IndexInfo *in *** 53,59 **** Datum *values, bool *isnull); ! extern void setNewRelfilenode(Relation relation); extern void index_build(Relation heapRelation, Relation indexRelation, --- 53,59 ---- Datum *values, bool *isnull); ! extern void setNewRelfilenode(Relation relation, TransactionId freezeXid); extern void index_build(Relation heapRelation, Relation indexRelation, --nVMJ2NtxeReIH9PS--