Hi,

I stumbled across a minor issue in xlog.c:1030: the WAL_DEBUG code block
there passes rdata->data to the rm_desc() methode. However, that's only
the first XLogRecData struct, not the entire XLog record. So the
rm_desc() method effectively reports spurious data for any subsequent part.

Take a commit record with subxacts as an example: during XLogInsert,
Postgres reports the following:

LOG:  INSERT @ 0/16F3270: prev 0/16F3234; xid 688; len 16: Transaction -
commit: 2012-10-11 09:31:17.790368-07; subxacts: 3214563816

Note that the xid in subxacts is way off. During recovery from WAL, the
record is logged correctly:

LOG:  REDO @ 0/16F3270; LSN 0/16F329C: prev 0/16F3234; xid 688; len 16:
Transaction - commit: 2012-10-11 09:31:17.790368-07; subxacts: 689

Attached is a possible fix.

Regards

Markus Wanner
*** a/src/backend/access/transam/xlog.c
--- b/src/backend/access/transam/xlog.c
***************
*** 1033,1039 **** begin:;
  #ifdef WAL_DEBUG
  	if (XLOG_DEBUG)
  	{
! 		StringInfoData buf;
  
  		initStringInfo(&buf);
  		appendStringInfo(&buf, "INSERT @ %X/%X: ",
--- 1033,1056 ----
  #ifdef WAL_DEBUG
  	if (XLOG_DEBUG)
  	{
! 		StringInfoData	buf;
! 		char		   *full_rec = palloc(write_len), *ins_ptr;
! 
! 		/*
! 		 * We need assemble the entire record once, to be able to dump it out
! 		 * properly.
! 		 */
! 		rdt = rdata;
! 		ins_ptr = full_rec;
! 		while (rdt)
! 		{
! 			if (rdt->data != NULL)
! 			{
! 				memcpy(ins_ptr, rdt->data, rdt->len);
! 				ins_ptr += rdt->len;
! 			}
! 			rdt = rdt->next;
! 		}
  
  		initStringInfo(&buf);
  		appendStringInfo(&buf, "INSERT @ %X/%X: ",
***************
*** 1042,1051 **** begin:;
  		if (rdata->data != NULL)
  		{
  			appendStringInfo(&buf, " - ");
! 			RmgrTable[rechdr->xl_rmid].rm_desc(&buf, rechdr->xl_info, rdata->data);
  		}
  		elog(LOG, "%s", buf.data);
  		pfree(buf.data);
  	}
  #endif
  
--- 1059,1069 ----
  		if (rdata->data != NULL)
  		{
  			appendStringInfo(&buf, " - ");
! 			RmgrTable[rechdr->xl_rmid].rm_desc(&buf, rechdr->xl_info, full_rec);
  		}
  		elog(LOG, "%s", buf.data);
  		pfree(buf.data);
+ 		pfree(full_rec);
  	}
  #endif
  
-- 
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