Index: pg_resetxlog.c
===================================================================
RCS file: /cvsroot/pgsql/contrib/pg_resetxlog/pg_resetxlog.c,v
retrieving revision 1.10
diff -c -r1.10 pg_resetxlog.c
*** pg_resetxlog.c	2001/11/05 17:46:23	1.10
--- pg_resetxlog.c	2002/01/10 18:01:51
***************
*** 23,29 ****
   * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
   * Portions Copyright (c) 1994, Regents of the University of California
   *
!  * $Header: /cvsroot/pgsql/contrib/pg_resetxlog/pg_resetxlog.c,v 1.10 2001/11/05 17:46:23 momjian Exp $
   *
   *-------------------------------------------------------------------------
   */
--- 23,29 ----
   * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
   * Portions Copyright (c) 1994, Regents of the University of California
   *
!  * $Header: /cvsroot/pgsql/contrib/pg_resetxlog/pg_resetxlog.c,v 1.11 2002/01/10 17:51:52 momjian Exp $
   *
   *-------------------------------------------------------------------------
   */
***************
*** 709,715 ****
   * Write out the new pg_control file.
   */
  static void
! RewriteControlFile(void)
  {
  	int			fd;
  	char		buffer[BLCKSZ]; /* need not be aligned */
--- 709,715 ----
   * Write out the new pg_control file.
   */
  static void
! RewriteControlFile(TransactionId set_xid)
  {
  	int			fd;
  	char		buffer[BLCKSZ]; /* need not be aligned */
***************
*** 737,742 ****
--- 737,745 ----
  	ControlFile.prevCheckPoint.xlogid = 0;
  	ControlFile.prevCheckPoint.xrecoff = 0;
  
+ 	if (set_xid != 0)
+ 		ControlFile.checkPointCopy.nextXid = set_xid;
+ 	
  	/* Contents are protected with a CRC */
  	INIT_CRC64(ControlFile.crc);
  	COMP_CRC64(ControlFile.crc,
***************
*** 926,934 ****
  static void
  usage(void)
  {
! 	fprintf(stderr, "Usage: pg_resetxlog [-f] [-n] PGDataDirectory\n\n"
! 			"  -f\tforce update to be done\n"
! 			"  -n\tno update, just show extracted pg_control values (for testing)\n");
  	exit(1);
  }
  
--- 929,938 ----
  static void
  usage(void)
  {
! 	fprintf(stderr, "Usage: pg_resetxlog [-f] [-n] [-x xid] PGDataDirectory\n"
! 			" -f\tforce update to be done\n"
! 			" -n\tno update, just show extracted pg_control values (for testing)\n"
! 			" -x XID\tset XID in pg_control\n");
  	exit(1);
  }
  
***************
*** 939,944 ****
--- 943,949 ----
  	int			argn;
  	bool		force = false;
  	bool		noupdate = false;
+ 	TransactionId set_xid = 0;
  	int			fd;
  	char		path[MAXPGPATH];
  
***************
*** 950,955 ****
--- 955,972 ----
  			force = true;
  		else if (strcmp(argv[argn], "-n") == 0)
  			noupdate = true;
+ 		else if (strcmp(argv[argn], "-x") == 0)
+ 		{
+ 			argn++;
+ 			if (argn == argc)
+ 				usage();
+ 			set_xid = strtoul(argv[argn], NULL, 0);
+ 			if (set_xid == 0)
+ 			{
+ 				fprintf(stderr, "XID can not be 0.");
+ 				exit(1);
+ 			}
+ 		}
  		else
  			usage();
  	}
***************
*** 1018,1024 ****
  	/*
  	 * Else, do the dirty deed.
  	 */
! 	RewriteControlFile();
  	KillExistingXLOG();
  	WriteEmptyXLOG();
  
--- 1035,1041 ----
  	/*
  	 * Else, do the dirty deed.
  	 */
! 	RewriteControlFile(set_xid);
  	KillExistingXLOG();
  	WriteEmptyXLOG();
  
