Index: src/backend/access/transam/xlog.c
===================================================================
RCS file: /projects/cvsroot/pgsql/src/backend/access/transam/xlog.c,v
retrieving revision 1.247
diff -c -r1.247 xlog.c
*** src/backend/access/transam/xlog.c	7 Aug 2006 16:57:56 -0000	1.247
--- src/backend/access/transam/xlog.c	15 Aug 2006 14:27:00 -0000
***************
*** 6336,6346 ****
--- 6336,6383 ----
  
  /*
   * Report the current WAL location (same format as pg_start_backup etc)
+  *
+  * This is the current Write pointer, so is useful for determining the
+  * current byte offset within a WAL file that has valid data written to it. 
+  * Note that data written is not always committed yet, see XLogInsert()
   */
  Datum
  pg_current_xlog_location(PG_FUNCTION_ARGS)
  {
  	text	   *result;
+ 	char		location[MAXFNAMELEN];
+ 
+ 	/*
+ 	 * Get the current end-of-WAL position by updating LogwrtResult
+ 	 */
+ 	{
+ 		/* use volatile pointer to prevent code rearrangement */
+ 		volatile XLogCtlData *xlogctl = XLogCtl;
+ 
+ 		SpinLockAcquire(&xlogctl->info_lck);
+ 		LogwrtResult = xlogctl->LogwrtResult;
+ 		SpinLockRelease(&xlogctl->info_lck);
+ 	}
+ 
+ 	snprintf(location, sizeof(location), "%X/%X",
+ 			 LogwrtResult.Write.xlogid, LogwrtResult.Write.xrecoff);
+ 
+ 	result = DatumGetTextP(DirectFunctionCall1(textin,
+ 											   CStringGetDatum(location)));
+ 	PG_RETURN_TEXT_P(result);
+ }
+ 
+ /*
+  * Report the current WAL location (same format as pg_start_backup etc)
+  *
+  * This is the current Insert pointer. The name is deliberately chosen
+  * to be different from pg_current_xlog_location so people do not confuse
+  * the two functions. This function is mostly for debugging purposes.
+  */
+ Datum
+ pg_current_wal_insert_pointer(PG_FUNCTION_ARGS)
+ {
+ 	text	   *result;
  	XLogCtlInsert *Insert = &XLogCtl->Insert;
  	XLogRecPtr	current_recptr;
  	char		location[MAXFNAMELEN];
Index: src/include/access/xlog_internal.h
===================================================================
RCS file: /projects/cvsroot/pgsql/src/include/access/xlog_internal.h,v
retrieving revision 1.15
diff -c -r1.15 xlog_internal.h
*** src/include/access/xlog_internal.h	7 Aug 2006 16:57:57 -0000	1.15
--- src/include/access/xlog_internal.h	15 Aug 2006 14:27:01 -0000
***************
*** 244,249 ****
--- 244,250 ----
  extern Datum pg_stop_backup(PG_FUNCTION_ARGS);
  extern Datum pg_switch_xlog(PG_FUNCTION_ARGS);
  extern Datum pg_current_xlog_location(PG_FUNCTION_ARGS);
+ extern Datum pg_current_wal_insert_pointer(PG_FUNCTION_ARGS);
  extern Datum pg_xlogfile_name_offset(PG_FUNCTION_ARGS);
  extern Datum pg_xlogfile_name(PG_FUNCTION_ARGS);
  
Index: src/include/catalog/pg_proc.h
===================================================================
RCS file: /projects/cvsroot/pgsql/src/include/catalog/pg_proc.h,v
retrieving revision 1.420
diff -c -r1.420 pg_proc.h
*** src/include/catalog/pg_proc.h	6 Aug 2006 03:53:44 -0000	1.420
--- src/include/catalog/pg_proc.h	15 Aug 2006 14:27:06 -0000
***************
*** 3105,3110 ****
--- 3105,3112 ----
  DESCR("Switch to new xlog file");
  DATA(insert OID = 2849 ( pg_current_xlog_location	PGNSP PGUID 12 f f t f v 0 25 "" _null_ _null_ _null_ pg_current_xlog_location - _null_ ));
  DESCR("current xlog location");
+ DATA(insert OID = 2852 ( pg_current_wal_insert_pointer	PGNSP PGUID 12 f f t f v 0 25 "" _null_ _null_ _null_ pg_current_wal_insert_pointer - _null_ ));
+ DESCR("current wal insert pointer");
  DATA(insert OID = 2850 ( pg_xlogfile_name_offset	PGNSP PGUID 12 f f t f i 1 25 "25" _null_ _null_ _null_ pg_xlogfile_name_offset - _null_ ));
  DESCR("xlog filename and byte offset, given an xlog location");
  DATA(insert OID = 2851 ( pg_xlogfile_name			PGNSP PGUID 12 f f t f i 1 25 "25" _null_ _null_ _null_ pg_xlogfile_name - _null_ ));
