diff -cprN head/src/backend/commands/tablecmds.c work/src/backend/commands/tablecmds.c
*** head/src/backend/commands/tablecmds.c	2009-10-15 10:26:48.573966000 +0900
--- work/src/backend/commands/tablecmds.c	2009-10-15 13:06:11.271226497 +0900
*************** ATRewriteTable(AlteredTableInfo *tab, Oi
*** 3037,3042 ****
--- 3037,3043 ----
  	int			i;
  	ListCell   *l;
  	EState	   *estate;
+ 	int			hi_options = HEAP_INSERT_SKIP_FSM;
  
  	/*
  	 * Open the relation(s).  We have surely already locked the existing
*************** ATRewriteTable(AlteredTableInfo *tab, Oi
*** 3129,3134 ****
--- 3130,3137 ----
  		MemoryContext oldCxt;
  		List	   *dropped_attrs = NIL;
  		ListCell   *lc;
+ 		CommandId	mycid = GetCurrentCommandId(true);
+ 		BulkInsertState bistate;
  
  		econtext = GetPerTupleExprContext(estate);
  
*************** ATRewriteTable(AlteredTableInfo *tab, Oi
*** 3158,3163 ****
--- 3161,3171 ----
  				dropped_attrs = lappend_int(dropped_attrs, i);
  		}
  
+ 		if (!XLogArchivingActive() || newrel->rd_istemp)
+ 			hi_options |= HEAP_INSERT_SKIP_WAL;
+ 
+ 		bistate = GetBulkInsertState();
+ 
  		/*
  		 * Scan through the rows, generating a new row if needed and then
  		 * checking all the constraints.
*************** ATRewriteTable(AlteredTableInfo *tab, Oi
*** 3252,3258 ****
  
  			/* Write the tuple out to the new relation */
  			if (newrel)
! 				simple_heap_insert(newrel, tuple);
  
  			ResetExprContext(econtext);
  
--- 3260,3266 ----
  
  			/* Write the tuple out to the new relation */
  			if (newrel)
! 				heap_insert(newrel, tuple, mycid, hi_options, bistate);
  
  			ResetExprContext(econtext);
  
*************** ATRewriteTable(AlteredTableInfo *tab, Oi
*** 3262,3267 ****
--- 3270,3277 ----
  		MemoryContextSwitchTo(oldCxt);
  		heap_endscan(scan);
  
+ 		FreeBulkInsertState(bistate);
+ 
  		ExecDropSingleTupleTableSlot(oldslot);
  		ExecDropSingleTupleTableSlot(newslot);
  	}
*************** ATRewriteTable(AlteredTableInfo *tab, Oi
*** 3270,3276 ****
--- 3280,3291 ----
  
  	heap_close(oldrel, NoLock);
  	if (newrel)
+ 	{
+ 		/* If we skipped writing WAL, then we need to sync the heap. */
+ 		if (hi_options & HEAP_INSERT_SKIP_WAL)
+ 			heap_sync(newrel);
  		heap_close(newrel, NoLock);
+ 	}
  }
  
  /*
