On Mon, Feb 1, 2010 at 7:40 PM, Heikki Linnakangas
<heikki.linnakan...@enterprisedb.com> wrote:
> So you get those messages when the table is *not* a temporary table. I
> can see now what Fujii was trying to say. His patch seems Ok, though
> perhaps it would be better to move the responsibility of calling
> XLogReportUnloggedStatement() to the callers of heap_sync(). When I put
> it in heap_sync(), I didn't take into account that it's sometimes called
> just to flush buffers from buffer cache, not to fsync() non-WAL-logged
> operations.

As you said, I moved the responsibility of calling XLogReportUnloggedStatement()
to the callers of heap_sync(). Here is the patch.

Regards,

-- 
Fujii Masao
NIPPON TELEGRAPH AND TELEPHONE CORPORATION
NTT Open Source Software Center
*** a/src/backend/access/heap/heapam.c
--- b/src/backend/access/heap/heapam.c
***************
*** 5074,5089 **** heap2_desc(StringInfo buf, uint8 xl_info, char *rec)
  void
  heap_sync(Relation rel)
  {
- 	char reason[NAMEDATALEN + 30];
- 
  	/* temp tables never need fsync */
  	if (rel->rd_istemp)
  		return;
  
- 	snprintf(reason, sizeof(reason), "heap inserts on \"%s\"",
- 			 RelationGetRelationName(rel));
- 	XLogReportUnloggedStatement(reason);
- 
  	/* main heap */
  	FlushRelationBuffers(rel);
  	/* FlushRelationBuffers will have opened rd_smgr */
--- 5074,5083 ----
*** a/src/backend/access/heap/rewriteheap.c
--- b/src/backend/access/heap/rewriteheap.c
***************
*** 246,252 **** begin_heap_rewrite(Relation new_heap, TransactionId oldest_xmin,
   * state and any other resources are freed.
   */
  void
! end_heap_rewrite(RewriteState state)
  {
  	HASH_SEQ_STATUS seq_status;
  	UnresolvedTup unresolved;
--- 246,252 ----
   * state and any other resources are freed.
   */
  void
! end_heap_rewrite(RewriteState state, bool use_wal)
  {
  	HASH_SEQ_STATUS seq_status;
  	UnresolvedTup unresolved;
***************
*** 278,283 **** end_heap_rewrite(RewriteState state)
--- 278,292 ----
  				   (char *) state->rs_buffer, true);
  	}
  
+ 	/* Write an XLOG UNLOGGED record if WAL-logging was skipped */
+ 	if (!use_wal && !state->rs_new_rel->rd_istemp)
+ 	{
+ 		char reason[NAMEDATALEN + 30];
+ 		snprintf(reason, sizeof(reason), "heap rewrite on \"%s\"",
+ 				 RelationGetRelationName(state->rs_new_rel));
+ 		XLogReportUnloggedStatement(reason);
+ 	}
+ 
  	/*
  	 * If the rel isn't temp, must fsync before commit.  We use heap_sync to
  	 * ensure that the toast table gets fsync'd too.
*** a/src/backend/commands/cluster.c
--- b/src/backend/commands/cluster.c
***************
*** 998,1004 **** copy_heap_data(Oid OIDNewHeap, Oid OIDOldHeap, Oid OIDOldIndex,
  		heap_endscan(heapScan);
  
  	/* Write out any remaining tuples, and fsync if needed */
! 	end_heap_rewrite(rwstate);
  
  	pfree(values);
  	pfree(isnull);
--- 998,1004 ----
  		heap_endscan(heapScan);
  
  	/* Write out any remaining tuples, and fsync if needed */
! 	end_heap_rewrite(rwstate, use_wal);
  
  	pfree(values);
  	pfree(isnull);
*** a/src/backend/commands/copy.c
--- b/src/backend/commands/copy.c
***************
*** 2225,2231 **** CopyFrom(CopyState cstate)
--- 2225,2237 ----
  	 * indexes since those use WAL anyway)
  	 */
  	if (hi_options & HEAP_INSERT_SKIP_WAL)
+ 	{
+ 		char reason[NAMEDATALEN + 30];
+ 		snprintf(reason, sizeof(reason), "COPY FROM on \"%s\"",
+ 				 RelationGetRelationName(cstate->rel));
+ 		XLogReportUnloggedStatement(reason);
  		heap_sync(cstate->rel);
+ 	}
  }
  
  
*** a/src/backend/commands/tablecmds.c
--- b/src/backend/commands/tablecmds.c
***************
*** 3297,3303 **** ATRewriteTable(AlteredTableInfo *tab, Oid OIDNewHeap)
--- 3297,3309 ----
  
  		/* If we skipped writing WAL, then we need to sync the heap. */
  		if (hi_options & HEAP_INSERT_SKIP_WAL)
+ 		{
+ 			char reason[NAMEDATALEN + 30];
+ 			snprintf(reason, sizeof(reason), "table rewrite on \"%s\"",
+ 					 RelationGetRelationName(newrel));
+ 			XLogReportUnloggedStatement(reason);
  			heap_sync(newrel);
+ 		}
  
  		heap_close(newrel, NoLock);
  	}
*** a/src/backend/executor/execMain.c
--- b/src/backend/executor/execMain.c
***************
*** 2240,2246 **** CloseIntoRel(QueryDesc *queryDesc)
--- 2240,2252 ----
  
  		/* If we skipped using WAL, must heap_sync before commit */
  		if (myState->hi_options & HEAP_INSERT_SKIP_WAL)
+ 		{
+ 			char reason[NAMEDATALEN + 30];
+ 			snprintf(reason, sizeof(reason), "SELECT INTO on \"%s\"",
+ 					 RelationGetRelationName(myState->rel));
+ 			XLogReportUnloggedStatement(reason);
  			heap_sync(myState->rel);
+ 		}
  
  		/* close rel, but keep lock until commit */
  		heap_close(myState->rel, NoLock);
*** a/src/include/access/rewriteheap.h
--- b/src/include/access/rewriteheap.h
***************
*** 22,28 **** typedef struct RewriteStateData *RewriteState;
  extern RewriteState begin_heap_rewrite(Relation NewHeap,
  				   TransactionId OldestXmin, TransactionId FreezeXid,
  				   bool use_wal);
! extern void end_heap_rewrite(RewriteState state);
  extern void rewrite_heap_tuple(RewriteState state, HeapTuple oldTuple,
  				   HeapTuple newTuple);
  extern void rewrite_heap_dead_tuple(RewriteState state, HeapTuple oldTuple);
--- 22,28 ----
  extern RewriteState begin_heap_rewrite(Relation NewHeap,
  				   TransactionId OldestXmin, TransactionId FreezeXid,
  				   bool use_wal);
! extern void end_heap_rewrite(RewriteState state, bool use_wal);
  extern void rewrite_heap_tuple(RewriteState state, HeapTuple oldTuple,
  				   HeapTuple newTuple);
  extern void rewrite_heap_dead_tuple(RewriteState state, HeapTuple oldTuple);
-- 
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