Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"files.associations": {
"pg_authid.h": "c",
"builtins.h": "c",
"slot.h": "c"
}
}
56 changes: 46 additions & 10 deletions src/bin/pg_resetwal/pg_resetwal.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ static uint32 minXlogTli = 0;
static XLogSegNo minXlogSegNo = 0;
static int WalSegSz;
static int set_wal_segsize;
static uint64 set_sysid = 0;

static uint64 GenerateSystemIdentifier(void);
static void CheckDataVersion(void);
static bool ReadControlFile(void);
static void GuessControlValues(void);
Expand Down Expand Up @@ -105,6 +107,7 @@ main(int argc, char *argv[])
{"oldest-transaction-id", required_argument, NULL, 'u'},
{"next-transaction-id", required_argument, NULL, 'x'},
{"wal-segsize", required_argument, NULL, 1},
{"sysid", required_argument, NULL, 's'},
{NULL, 0, NULL, 0}
};

Expand Down Expand Up @@ -137,7 +140,7 @@ main(int argc, char *argv[])
}


while ((c = getopt_long(argc, argv, "c:D:e:fl:m:no:O:u:x:", long_options, NULL)) != -1)
while ((c = getopt_long(argc, argv, "c:D:e:fl:m:no:O:u:x:s:", long_options, NULL)) != -1)
{
switch (c)
{
Expand Down Expand Up @@ -328,6 +331,22 @@ main(int argc, char *argv[])
}
break;

case 's':
if (endptr == optarg || *endptr != '\0')
{
if (sscanf(optarg, UINT64_FORMAT, &set_sysid) != 1)
{
fprintf(stderr, _("%s: invalid argument for option -s\n"), progname);
fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
exit(1);
}
}
else
{
set_sysid = GenerateSystemIdentifier();
}
break;

default:
fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
exit(1);
Expand Down Expand Up @@ -492,6 +511,9 @@ main(int argc, char *argv[])
if (minXlogSegNo > newXlogSegNo)
newXlogSegNo = minXlogSegNo;

if (set_sysid != 0)
ControlFile.system_identifier = set_sysid;

/*
* If we had to guess anything, and -f was not given, just print the
* guessed values and exit. Also print if -n is given.
Expand Down Expand Up @@ -596,6 +618,26 @@ CheckDataVersion(void)
}


/*
* Create a new unique installation identifier.
*
* See notes in resetwal.c about the algorithm.
*/
static uint64
GenerateSystemIdentifier(void)
{
uint64 sysidentifier;
struct timeval tv;

gettimeofday(&tv, NULL);
sysidentifier = ((uint64) tv.tv_sec) << 32;
sysidentifier |= ((uint64) tv.tv_usec) << 12;
sysidentifier |= getpid() & 0xFFF;

return sysidentifier;
}


/*
* Try to read the existing pg_control file.
*
Expand Down Expand Up @@ -687,9 +729,6 @@ ReadControlFile(void)
static void
GuessControlValues(void)
{
uint64 sysidentifier;
struct timeval tv;

/*
* Set up a completely default set of pg_control values.
*/
Expand All @@ -701,14 +740,10 @@ GuessControlValues(void)

/*
* Create a new unique installation identifier, since we can no longer use
* any old XLOG records. See notes in xlog.c about the algorithm.
* any old XLOG records.
*/
gettimeofday(&tv, NULL);
sysidentifier = ((uint64) tv.tv_sec) << 32;
sysidentifier |= ((uint64) tv.tv_usec) << 12;
sysidentifier |= getpid() & 0xFFF;

ControlFile.system_identifier = sysidentifier;
ControlFile.system_identifier = GenerateSystemIdentifier();

ControlFile.checkPointCopy.redo = SizeOfXLogLongPHD;
ControlFile.checkPointCopy.ThisTimeLineID = 1;
Expand Down Expand Up @@ -1332,6 +1367,7 @@ usage(void)
printf(_(" -O, --multixact-offset=OFFSET set next multitransaction offset\n"));
printf(_(" -u, --oldest-transaction-id=XID set oldest transaction ID\n"));
printf(_(" -V, --version output version information, then exit\n"));
printf(_(" -s [SYSID] set system identifier (or generate one)\n"));
printf(_(" -x, --next-transaction-id=XID set next transaction ID\n"));
printf(_(" --wal-segsize=SIZE size of WAL segments, in megabytes\n"));
printf(_(" -?, --help show this help, then exit\n"));
Expand Down