mirror of
https://github.com/postgres/postgres.git
synced 2025-04-25 21:42:33 +03:00
Add new -x XID option to /contrib/pg_resetxlog for future pg_upgrade use.
This commit is contained in:
parent
7955f98774
commit
f6e603cffa
@ -21,6 +21,9 @@ module pg_controldata and run it to be sure the DB state is SHUTDOWN).
|
|||||||
Then run pg_resetxlog, and finally install and start the new version of
|
Then run pg_resetxlog, and finally install and start the new version of
|
||||||
the database software.
|
the database software.
|
||||||
|
|
||||||
|
A tertiary purpose it its use by pg_upgrade to set the next transaction
|
||||||
|
id in pg_control.
|
||||||
|
|
||||||
To run the program, make sure your postmaster is not running, then
|
To run the program, make sure your postmaster is not running, then
|
||||||
(as the Postgres admin user) do
|
(as the Postgres admin user) do
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
|
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
|
||||||
* Portions Copyright (c) 1994, Regents of the University of California
|
* Portions Copyright (c) 1994, Regents of the University of California
|
||||||
*
|
*
|
||||||
* $Header: /cvsroot/pgsql/contrib/pg_resetxlog/Attic/pg_resetxlog.c,v 1.10 2001/11/05 17:46:23 momjian Exp $
|
* $Header: /cvsroot/pgsql/contrib/pg_resetxlog/Attic/pg_resetxlog.c,v 1.11 2002/01/10 17:51:52 momjian Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -709,11 +709,13 @@ PrintControlValues(void)
|
|||||||
* Write out the new pg_control file.
|
* Write out the new pg_control file.
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
RewriteControlFile(void)
|
RewriteControlFile(TransactionId set_xid)
|
||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
char buffer[BLCKSZ]; /* need not be aligned */
|
char buffer[BLCKSZ]; /* need not be aligned */
|
||||||
|
|
||||||
|
if (set_xid == 0)
|
||||||
|
{
|
||||||
/*
|
/*
|
||||||
* Adjust fields as needed to force an empty XLOG starting at the next
|
* Adjust fields as needed to force an empty XLOG starting at the next
|
||||||
* available segment.
|
* available segment.
|
||||||
@ -736,6 +738,9 @@ RewriteControlFile(void)
|
|||||||
ControlFile.checkPoint = ControlFile.checkPointCopy.redo;
|
ControlFile.checkPoint = ControlFile.checkPointCopy.redo;
|
||||||
ControlFile.prevCheckPoint.xlogid = 0;
|
ControlFile.prevCheckPoint.xlogid = 0;
|
||||||
ControlFile.prevCheckPoint.xrecoff = 0;
|
ControlFile.prevCheckPoint.xrecoff = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
ControlFile.checkPointCopy.nextXid = set_xid;
|
||||||
|
|
||||||
/* Contents are protected with a CRC */
|
/* Contents are protected with a CRC */
|
||||||
INIT_CRC64(ControlFile.crc);
|
INIT_CRC64(ControlFile.crc);
|
||||||
@ -926,9 +931,10 @@ WriteEmptyXLOG(void)
|
|||||||
static void
|
static void
|
||||||
usage(void)
|
usage(void)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Usage: pg_resetxlog [-f] [-n] PGDataDirectory\n\n"
|
fprintf(stderr, "Usage: pg_resetxlog [-f] [-n] [-x xid] PGDataDirectory\n"
|
||||||
" -f\tforce update to be done\n"
|
" -f\tforce update to be done\n"
|
||||||
" -n\tno update, just show extracted pg_control values (for testing)\n");
|
" -n\tno update, just show extracted pg_control values (for testing)\n"
|
||||||
|
" -x XID\tset XID in pg_control\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -939,6 +945,7 @@ main(int argc, char **argv)
|
|||||||
int argn;
|
int argn;
|
||||||
bool force = false;
|
bool force = false;
|
||||||
bool noupdate = false;
|
bool noupdate = false;
|
||||||
|
TransactionId set_xid = 0;
|
||||||
int fd;
|
int fd;
|
||||||
char path[MAXPGPATH];
|
char path[MAXPGPATH];
|
||||||
|
|
||||||
@ -950,6 +957,18 @@ main(int argc, char **argv)
|
|||||||
force = true;
|
force = true;
|
||||||
else if (strcmp(argv[argn], "-n") == 0)
|
else if (strcmp(argv[argn], "-n") == 0)
|
||||||
noupdate = true;
|
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
|
else
|
||||||
usage();
|
usage();
|
||||||
}
|
}
|
||||||
@ -992,6 +1011,20 @@ main(int argc, char **argv)
|
|||||||
if (!ReadControlFile())
|
if (!ReadControlFile())
|
||||||
GuessControlValues();
|
GuessControlValues();
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Set XID in pg_control and exit
|
||||||
|
*/
|
||||||
|
if (set_xid)
|
||||||
|
{
|
||||||
|
if (guessed)
|
||||||
|
{
|
||||||
|
printf("\npg_control appears corrupt. Can not update XID.\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
RewriteControlFile(set_xid);
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If we had to guess anything, and -f was not given, just print the
|
* If we had to guess anything, and -f was not given, just print the
|
||||||
* guessed values and exit. Also print if -n is given.
|
* guessed values and exit. Also print if -n is given.
|
||||||
@ -1018,7 +1051,7 @@ main(int argc, char **argv)
|
|||||||
/*
|
/*
|
||||||
* Else, do the dirty deed.
|
* Else, do the dirty deed.
|
||||||
*/
|
*/
|
||||||
RewriteControlFile();
|
RewriteControlFile(0);
|
||||||
KillExistingXLOG();
|
KillExistingXLOG();
|
||||||
WriteEmptyXLOG();
|
WriteEmptyXLOG();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user