Tom Lane wrote:
> Alvaro Herrera <[EMAIL PROTECTED]> writes:

> > I wonder if we can get away with simply renaming the new toast table and
> > index after the data has been copied.
> 
> Yeah, that seems like the best answer.

Seems like this patch fixes it.

How far back should be backpatched?  Given the lack of field complaints
I'd say "just to HEAD" but maybe others have different opinions.  FWIW
the patch applies cleanly (modulo header changes) back to 8.0.

-- 
Alvaro Herrera                                http://www.CommandPrompt.com/
The PostgreSQL Company - Command Prompt, Inc.
Index: src/backend/commands/cluster.c
===================================================================
RCS file: /home/alvherre/cvs/pgsql/src/backend/commands/cluster.c,v
retrieving revision 1.177
diff -c -p -r1.177 cluster.c
*** src/backend/commands/cluster.c	19 Jun 2008 00:46:04 -0000	1.177
--- src/backend/commands/cluster.c	9 Oct 2008 21:15:55 -0000
***************
*** 29,34 ****
--- 29,35 ----
  #include "catalog/index.h"
  #include "catalog/indexing.h"
  #include "catalog/namespace.h"
+ #include "catalog/pg_namespace.h"
  #include "catalog/toasting.h"
  #include "commands/cluster.h"
  #include "commands/tablecmds.h"
*************** rebuild_relation(Relation OldHeap, Oid i
*** 568,573 ****
--- 569,576 ----
  	char		NewHeapName[NAMEDATALEN];
  	TransactionId frozenXid;
  	ObjectAddress object;
+ 	char		NewToastName[NAMEDATALEN];
+ 	Relation	newrel;
  
  	/* Mark the correct index as clustered */
  	mark_index_clustered(OldHeap, indexOid);
*************** rebuild_relation(Relation OldHeap, Oid i
*** 622,627 ****
--- 625,645 ----
  	 * because reindex_relation does it.
  	 */
  	reindex_relation(tableOid, false);
+ 
+ 	/*
+ 	 * At this point, everything is kosher except that the toast table's name
+ 	 * corresponds to the temporary table.  The name is irrelevant to
+ 	 * the backend because it's referenced by OID, but users looking at the
+ 	 * catalogs could be confused.  Rename it to prevent this problem.
+ 	 *
+ 	 * Note no lock required on the relation, because we already hold an
+ 	 * exclusive lock on it.
+ 	 */
+ 	newrel = relation_open(tableOid, NoLock);
+ 	snprintf(NewToastName, NAMEDATALEN, "pg_toast_%u", tableOid);
+ 	RenameRelationInternal(newrel->rd_rel->reltoastrelid, NewToastName,
+ 						   PG_TOAST_NAMESPACE);
+ 	relation_close(newrel, NoLock);
  }
  
  /*
-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Reply via email to