pg_basebackup.patch
application/octet-stream
Filename: pg_basebackup.patch
Type: application/octet-stream
Part: 0
Message:
Re: filenames in pg_basebackup
Patch
Same data as JSON:
GET /api/v1/attachments/:id/patch
the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes.
API reference →
Format: context
| File | + | − |
|---|---|---|
| src/bin/pg_basebackup/pg_basebackup.c | 15 | 0 |
| src/bin/pg_basebackup/pg_receivexlog.c | 9 | 0 |
| src/bin/pg_basebackup/receivelog.c | 30 | 0 |
*** a/src/bin/pg_basebackup/pg_basebackup.c
--- b/src/bin/pg_basebackup/pg_basebackup.c
***************
*** 121,127 **** usage(void)
printf(_(" -V, --version output version information, then exit\n"));
printf(_(" -?, --help show this help, then exit\n"));
printf(_("\nConnection options:\n"));
! printf(_(" -s, --statusint=INTERVAL time between status packets sent to server (in seconds)\n"));
printf(_(" -h, --host=HOSTNAME database server host or socket directory\n"));
printf(_(" -p, --port=PORT database server port number\n"));
printf(_(" -U, --username=NAME connect as specified database user\n"));
--- 121,128 ----
printf(_(" -V, --version output version information, then exit\n"));
printf(_(" -?, --help show this help, then exit\n"));
printf(_("\nConnection options:\n"));
! printf(_(" -s, --statusint=INTERVAL time between status packets sent to server\n"
! " (in seconds)\n"));
printf(_(" -h, --host=HOSTNAME database server host or socket directory\n"));
printf(_(" -p, --port=PORT database server port number\n"));
printf(_(" -U, --username=NAME connect as specified database user\n"));
***************
*** 174,180 **** reached_end_position(XLogRecPtr segendpos, uint32 timeline, bool segment_finishe
if (sscanf(xlogend, "%X/%X", &xlogendptr.xlogid, &xlogendptr.xrecoff) != 2)
{
! fprintf(stderr, _("%s: could not parse xlog end position \"%s\"\n"),
progname, xlogend);
exit(1);
}
--- 175,181 ----
if (sscanf(xlogend, "%X/%X", &xlogendptr.xlogid, &xlogendptr.xrecoff) != 2)
{
! fprintf(stderr, _("%s: could not parse transaction log location \"%s\"\n"),
progname, xlogend);
exit(1);
}
***************
*** 263,269 **** StartLogStreamer(char *startpos, uint32 timeline, char *sysidentifier)
/* Convert the starting position */
if (sscanf(startpos, "%X/%X", ¶m->startptr.xlogid, ¶m->startptr.xrecoff) != 2)
{
! fprintf(stderr, _("%s: invalid format of xlog location: %s\n"),
progname, startpos);
disconnect_and_exit(1);
}
--- 264,270 ----
/* Convert the starting position */
if (sscanf(startpos, "%X/%X", ¶m->startptr.xlogid, ¶m->startptr.xrecoff) != 2)
{
! fprintf(stderr, _("%s: could not parse transaction log location \"%s\"\n"),
progname, startpos);
disconnect_and_exit(1);
}
***************
*** 931,944 **** BaseBackup(void)
res = PQexec(conn, "IDENTIFY_SYSTEM");
if (PQresultStatus(res) != PGRES_TUPLES_OK)
{
! fprintf(stderr, _("%s: could not identify system: %s"),
! progname, PQerrorMessage(conn));
disconnect_and_exit(1);
}
if (PQntuples(res) != 1 || PQnfields(res) != 3)
{
! fprintf(stderr, _("%s: could not identify system, got %d rows and %d fields\n"),
! progname, PQntuples(res), PQnfields(res));
disconnect_and_exit(1);
}
sysidentifier = strdup(PQgetvalue(res, 0, 0));
--- 932,945 ----
res = PQexec(conn, "IDENTIFY_SYSTEM");
if (PQresultStatus(res) != PGRES_TUPLES_OK)
{
! fprintf(stderr, _("%s: could not send replication command \"%s\": %s"),
! progname, "IDENTIFY_SYSTEM", PQerrorMessage(conn));
disconnect_and_exit(1);
}
if (PQntuples(res) != 1 || PQnfields(res) != 3)
{
! fprintf(stderr, _("%s: could not identify system: got %d rows and %d fields, expected %d rows and %d fields\n"),
! progname, PQntuples(res), PQnfields(res), 1, 3);
disconnect_and_exit(1);
}
sysidentifier = strdup(PQgetvalue(res, 0, 0));
***************
*** 958,965 **** BaseBackup(void)
if (PQsendQuery(conn, current_path) == 0)
{
! fprintf(stderr, _("%s: could not send base backup command: %s"),
! progname, PQerrorMessage(conn));
disconnect_and_exit(1);
}
--- 959,966 ----
if (PQsendQuery(conn, current_path) == 0)
{
! fprintf(stderr, _("%s: could not send replication command \"%s\": %s"),
! progname, "BASE_BACKUP", PQerrorMessage(conn));
disconnect_and_exit(1);
}
***************
*** 981,987 **** BaseBackup(void)
}
strcpy(xlogstart, PQgetvalue(res, 0, 0));
if (verbose && includewal)
! fprintf(stderr, "xlog start point: %s\n", xlogstart);
PQclear(res);
MemSet(xlogend, 0, sizeof(xlogend));
--- 982,988 ----
}
strcpy(xlogstart, PQgetvalue(res, 0, 0));
if (verbose && includewal)
! fprintf(stderr, "transaction log start point: %s\n", xlogstart);
PQclear(res);
MemSet(xlogend, 0, sizeof(xlogend));
***************
*** 1066,1084 **** BaseBackup(void)
res = PQgetResult(conn);
if (PQresultStatus(res) != PGRES_TUPLES_OK)
{
! fprintf(stderr, _("%s: could not get WAL end position from server: %s"),
progname, PQerrorMessage(conn));
disconnect_and_exit(1);
}
if (PQntuples(res) != 1)
{
! fprintf(stderr, _("%s: no WAL end position returned from server\n"),
progname);
disconnect_and_exit(1);
}
strcpy(xlogend, PQgetvalue(res, 0, 0));
if (verbose && includewal)
! fprintf(stderr, "xlog end point: %s\n", xlogend);
PQclear(res);
res = PQgetResult(conn);
--- 1067,1085 ----
res = PQgetResult(conn);
if (PQresultStatus(res) != PGRES_TUPLES_OK)
{
! fprintf(stderr, _("%s: could not get transaction log end position from server: %s"),
progname, PQerrorMessage(conn));
disconnect_and_exit(1);
}
if (PQntuples(res) != 1)
{
! fprintf(stderr, _("%s: no transaction log end position returned from server\n"),
progname);
disconnect_and_exit(1);
}
strcpy(xlogend, PQgetvalue(res, 0, 0));
if (verbose && includewal)
! fprintf(stderr, "transaction log end point: %s\n", xlogend);
PQclear(res);
res = PQgetResult(conn);
***************
*** 1145,1151 **** BaseBackup(void)
*/
if (sscanf(xlogend, "%X/%X", &xlogendptr.xlogid, &xlogendptr.xrecoff) != 2)
{
! fprintf(stderr, _("%s: could not parse xlog end position \"%s\"\n"),
progname, xlogend);
disconnect_and_exit(1);
}
--- 1146,1152 ----
*/
if (sscanf(xlogend, "%X/%X", &xlogendptr.xlogid, &xlogendptr.xrecoff) != 2)
{
! fprintf(stderr, _("%s: could not parse transaction log location \"%s\"\n"),
progname, xlogend);
disconnect_and_exit(1);
}
*** a/src/bin/pg_basebackup/pg_receivexlog.c
--- b/src/bin/pg_basebackup/pg_receivexlog.c
***************
*** 63,69 **** usage(void)
printf(_(" -V, --version output version information, then exit\n"));
printf(_(" -?, --help show this help, then exit\n"));
printf(_("\nConnection options:\n"));
! printf(_(" -s, --statusint=INTERVAL time between status packets sent to server (in seconds)\n"));
printf(_(" -h, --host=HOSTNAME database server host or socket directory\n"));
printf(_(" -p, --port=PORT database server port number\n"));
printf(_(" -U, --username=NAME connect as specified database user\n"));
--- 63,70 ----
printf(_(" -V, --version output version information, then exit\n"));
printf(_(" -?, --help show this help, then exit\n"));
printf(_("\nConnection options:\n"));
! printf(_(" -s, --statusint=INTERVAL time between status packets sent to server\n"
! " (in seconds)\n"));
printf(_(" -h, --host=HOSTNAME database server host or socket directory\n"));
printf(_(" -p, --port=PORT database server port number\n"));
printf(_(" -U, --username=NAME connect as specified database user\n"));
***************
*** 147,153 **** FindStreamingStart(XLogRecPtr currentpos, uint32 currenttimeline)
*/
if (sscanf(dirent->d_name, "%08X%08X%08X", &tli, &log, &seg) != 3)
{
! fprintf(stderr, _("%s: could not parse xlog filename \"%s\"\n"),
progname, dirent->d_name);
disconnect_and_exit(1);
}
--- 148,154 ----
*/
if (sscanf(dirent->d_name, "%08X%08X%08X", &tli, &log, &seg) != 3)
{
! fprintf(stderr, _("%s: could not parse transaction log file name \"%s\"\n"),
progname, dirent->d_name);
disconnect_and_exit(1);
}
***************
*** 178,184 **** FindStreamingStart(XLogRecPtr currentpos, uint32 currenttimeline)
}
else
{
! fprintf(stderr, _("%s: segment file '%s' is incorrect size %d, skipping\n"),
progname, dirent->d_name, (int) statbuf.st_size);
continue;
}
--- 179,185 ----
}
else
{
! fprintf(stderr, _("%s: segment file \"%s\" has incorrect size %d, skipping\n"),
progname, dirent->d_name, (int) statbuf.st_size);
continue;
}
***************
*** 230,249 **** StreamLog(void)
res = PQexec(conn, "IDENTIFY_SYSTEM");
if (PQresultStatus(res) != PGRES_TUPLES_OK)
{
! fprintf(stderr, _("%s: could not identify system: %s\n"),
! progname, PQerrorMessage(conn));
disconnect_and_exit(1);
}
if (PQntuples(res) != 1 || PQnfields(res) != 3)
{
! fprintf(stderr, _("%s: could not identify system, got %d rows and %d fields\n"),
! progname, PQntuples(res), PQnfields(res));
disconnect_and_exit(1);
}
timeline = atoi(PQgetvalue(res, 0, 1));
if (sscanf(PQgetvalue(res, 0, 2), "%X/%X", &startpos.xlogid, &startpos.xrecoff) != 2)
{
! fprintf(stderr, _("%s: could not parse log start position from value \"%s\"\n"),
progname, PQgetvalue(res, 0, 2));
disconnect_and_exit(1);
}
--- 231,250 ----
res = PQexec(conn, "IDENTIFY_SYSTEM");
if (PQresultStatus(res) != PGRES_TUPLES_OK)
{
! fprintf(stderr, _("%s: could not send replication command \"%s\": %s"),
! progname, "IDENTIFY_SYSTEM", PQerrorMessage(conn));
disconnect_and_exit(1);
}
if (PQntuples(res) != 1 || PQnfields(res) != 3)
{
! fprintf(stderr, _("%s: could not identify system: got %d rows and %d fields, expected %d rows and %d fields\n"),
! progname, PQntuples(res), PQnfields(res), 1, 3);
disconnect_and_exit(1);
}
timeline = atoi(PQgetvalue(res, 0, 1));
if (sscanf(PQgetvalue(res, 0, 2), "%X/%X", &startpos.xlogid, &startpos.xrecoff) != 2)
{
! fprintf(stderr, _("%s: could not parse transaction log location \"%s\"\n"),
progname, PQgetvalue(res, 0, 2));
disconnect_and_exit(1);
}
*** a/src/bin/pg_basebackup/receivelog.c
--- b/src/bin/pg_basebackup/receivelog.c
***************
*** 63,69 **** open_walfile(XLogRecPtr startpoint, uint32 timeline, char *basedir, char *namebu
f = open(fn, O_WRONLY | O_CREAT | PG_BINARY, S_IRUSR | S_IWUSR);
if (f == -1)
{
! fprintf(stderr, _("%s: could not open WAL segment %s: %s\n"),
progname, fn, strerror(errno));
return -1;
}
--- 63,69 ----
f = open(fn, O_WRONLY | O_CREAT | PG_BINARY, S_IRUSR | S_IWUSR);
if (f == -1)
{
! fprintf(stderr, _("%s: could not open transaction log file \"%s\": %s\n"),
progname, fn, strerror(errno));
return -1;
}
***************
*** 74,80 **** open_walfile(XLogRecPtr startpoint, uint32 timeline, char *basedir, char *namebu
*/
if (fstat(f, &statbuf) != 0)
{
! fprintf(stderr, _("%s: could not stat WAL segment %s: %s\n"),
progname, fn, strerror(errno));
close(f);
return -1;
--- 74,80 ----
*/
if (fstat(f, &statbuf) != 0)
{
! fprintf(stderr, _("%s: could not stat transaction log file \"%s\": %s\n"),
progname, fn, strerror(errno));
close(f);
return -1;
***************
*** 83,89 **** open_walfile(XLogRecPtr startpoint, uint32 timeline, char *basedir, char *namebu
return f; /* File is open and ready to use */
if (statbuf.st_size != 0)
{
! fprintf(stderr, _("%s: WAL segment %s is %d bytes, should be 0 or %d\n"),
progname, fn, (int) statbuf.st_size, XLogSegSize);
close(f);
return -1;
--- 83,89 ----
return f; /* File is open and ready to use */
if (statbuf.st_size != 0)
{
! fprintf(stderr, _("%s: transaction log file \"%s\" has %d bytes, should be 0 or %d\n"),
progname, fn, (int) statbuf.st_size, XLogSegSize);
close(f);
return -1;
***************
*** 95,101 **** open_walfile(XLogRecPtr startpoint, uint32 timeline, char *basedir, char *namebu
{
if (write(f, zerobuf, XLOG_BLCKSZ) != XLOG_BLCKSZ)
{
! fprintf(stderr, _("%s: could not pad WAL segment %s: %s\n"),
progname, fn, strerror(errno));
close(f);
unlink(fn);
--- 95,101 ----
{
if (write(f, zerobuf, XLOG_BLCKSZ) != XLOG_BLCKSZ)
{
! fprintf(stderr, _("%s: could not pad transaction log file \"%s\": %s\n"),
progname, fn, strerror(errno));
close(f);
unlink(fn);
***************
*** 106,112 **** open_walfile(XLogRecPtr startpoint, uint32 timeline, char *basedir, char *namebu
if (lseek(f, SEEK_SET, 0) != 0)
{
! fprintf(stderr, _("%s: could not seek back to beginning of WAL segment %s: %s\n"),
progname, fn, strerror(errno));
close(f);
return -1;
--- 106,112 ----
if (lseek(f, SEEK_SET, 0) != 0)
{
! fprintf(stderr, _("%s: could not seek to beginning of transaction log file \"%s\": %s\n"),
progname, fn, strerror(errno));
close(f);
return -1;
***************
*** 127,147 **** close_walfile(int walfile, char *basedir, char *walname, bool segment_complete)
if (currpos == -1)
{
! fprintf(stderr, _("%s: could not get current position in file %s: %s\n"),
progname, walname, strerror(errno));
return false;
}
if (fsync(walfile) != 0)
{
! fprintf(stderr, _("%s: could not fsync file %s: %s\n"),
progname, walname, strerror(errno));
return false;
}
if (close(walfile) != 0)
{
! fprintf(stderr, _("%s: could not close file %s: %s\n"),
progname, walname, strerror(errno));
return false;
}
--- 127,147 ----
if (currpos == -1)
{
! fprintf(stderr, _("%s: could not determine seek position in file \"%s\": %s\n"),
progname, walname, strerror(errno));
return false;
}
if (fsync(walfile) != 0)
{
! fprintf(stderr, _("%s: could not fsync file \"%s\": %s\n"),
progname, walname, strerror(errno));
return false;
}
if (close(walfile) != 0)
{
! fprintf(stderr, _("%s: could not close file \"%s\": %s\n"),
progname, walname, strerror(errno));
return false;
}
***************
*** 159,171 **** close_walfile(int walfile, char *basedir, char *walname, bool segment_complete)
snprintf(newfn, sizeof(newfn), "%s/%s", basedir, walname);
if (rename(oldfn, newfn) != 0)
{
! fprintf(stderr, _("%s: could not rename file %s: %s\n"),
progname, walname, strerror(errno));
return false;
}
}
else
! fprintf(stderr, _("%s: not renaming %s, segment is not complete.\n"),
progname, walname);
return true;
--- 159,171 ----
snprintf(newfn, sizeof(newfn), "%s/%s", basedir, walname);
if (rename(oldfn, newfn) != 0)
{
! fprintf(stderr, _("%s: could not rename file \"%s\": %s\n"),
progname, walname, strerror(errno));
return false;
}
}
else
! fprintf(stderr, _("%s: not renaming \"%s\", segment is not complete.\n"),
progname, walname);
return true;
***************
*** 265,271 **** localTimestampDifferenceExceeds(TimestampTz start_time,
* Note: The log position *must* be at a log segment start!
*/
bool
! ReceiveXlogStream(PGconn *conn, XLogRecPtr startpos, uint32 timeline, char *sysidentifier, char *basedir, stream_stop_callback stream_stop, int standby_message_timeout, bool rename_partial)
{
char query[128];
char current_walfile_name[MAXPGPATH];
--- 265,274 ----
* Note: The log position *must* be at a log segment start!
*/
bool
! ReceiveXlogStream(PGconn *conn, XLogRecPtr startpos, uint32 timeline,
! char *sysidentifier, char *basedir,
! stream_stop_callback stream_stop,
! int standby_message_timeout, bool rename_partial)
{
char query[128];
char current_walfile_name[MAXPGPATH];
***************
*** 281,295 **** ReceiveXlogStream(PGconn *conn, XLogRecPtr startpos, uint32 timeline, char *sysi
res = PQexec(conn, "IDENTIFY_SYSTEM");
if (PQresultStatus(res) != PGRES_TUPLES_OK)
{
! fprintf(stderr, _("%s: could not identify system: %s\n"),
! progname, PQerrorMessage(conn));
PQclear(res);
return false;
}
if (PQnfields(res) != 3 || PQntuples(res) != 1)
{
! fprintf(stderr, _("%s: could not identify system, got %d rows and %d fields\n"),
! progname, PQntuples(res), PQnfields(res));
PQclear(res);
return false;
}
--- 284,299 ----
res = PQexec(conn, "IDENTIFY_SYSTEM");
if (PQresultStatus(res) != PGRES_TUPLES_OK)
{
! fprintf(stderr, _("%s: could not send replication command \"%s\": %s"),
! progname, "IDENTIFY_SYSTEM", PQerrorMessage(conn));
PQclear(res);
return false;
}
if (PQnfields(res) != 3 || PQntuples(res) != 1)
{
! fprintf(stderr,
! _("%s: could not identify system: got %d rows and %d fields, expected %d rows and %d fields\n"),
! progname, PQntuples(res), PQnfields(res), 1, 3);
PQclear(res);
return false;
}
***************
*** 313,320 **** ReceiveXlogStream(PGconn *conn, XLogRecPtr startpos, uint32 timeline, char *sysi
res = PQexec(conn, query);
if (PQresultStatus(res) != PGRES_COPY_BOTH)
{
! fprintf(stderr, _("%s: could not start replication: %s\n"),
! progname, PQresultErrorMessage(res));
return false;
}
PQclear(res);
--- 317,324 ----
res = PQexec(conn, query);
if (PQresultStatus(res) != PGRES_COPY_BOTH)
{
! fprintf(stderr, _("%s: could not send replication command \"%s\": %s"),
! progname, "START_REPLICATION", PQresultErrorMessage(res));
return false;
}
PQclear(res);
***************
*** 343,349 **** ReceiveXlogStream(PGconn *conn, XLogRecPtr startpos, uint32 timeline, char *sysi
{
if (walfile != -1)
/* Potential error message is written by close_walfile */
! return close_walfile(walfile, basedir, current_walfile_name, rename_partial);
return true;
}
--- 347,354 ----
{
if (walfile != -1)
/* Potential error message is written by close_walfile */
! return close_walfile(walfile, basedir, current_walfile_name,
! rename_partial);
return true;
}
***************
*** 426,432 **** ReceiveXlogStream(PGconn *conn, XLogRecPtr startpos, uint32 timeline, char *sysi
/* Else there is actually data on the socket */
if (PQconsumeInput(conn) == 0)
{
! fprintf(stderr, _("%s: could not receive data from WAL stream: %s\n"),
progname, PQerrorMessage(conn));
return false;
}
--- 431,437 ----
/* Else there is actually data on the socket */
if (PQconsumeInput(conn) == 0)
{
! fprintf(stderr, _("%s: could not receive data from WAL stream: %s"),
progname, PQerrorMessage(conn));
return false;
}
***************
*** 437,443 **** ReceiveXlogStream(PGconn *conn, XLogRecPtr startpos, uint32 timeline, char *sysi
break;
if (r == -2)
{
! fprintf(stderr, _("%s: could not read copy data: %s\n"),
progname, PQerrorMessage(conn));
return false;
}
--- 442,448 ----
break;
if (r == -2)
{
! fprintf(stderr, _("%s: could not read COPY data: %s"),
progname, PQerrorMessage(conn));
return false;
}
***************
*** 449,455 **** ReceiveXlogStream(PGconn *conn, XLogRecPtr startpos, uint32 timeline, char *sysi
*/
if (r != STREAMING_KEEPALIVE_SIZE)
{
! fprintf(stderr, _("%s: keepalive message is incorrect size: %d\n"),
progname, r);
return false;
}
--- 454,460 ----
*/
if (r != STREAMING_KEEPALIVE_SIZE)
{
! fprintf(stderr, _("%s: keepalive message has incorrect size %d\n"),
progname, r);
return false;
}
***************
*** 481,487 **** ReceiveXlogStream(PGconn *conn, XLogRecPtr startpos, uint32 timeline, char *sysi
/* No file open yet */
if (xlogoff != 0)
{
! fprintf(stderr, _("%s: received xlog record for offset %u with no file open\n"),
progname, xlogoff);
return false;
}
--- 486,492 ----
/* No file open yet */
if (xlogoff != 0)
{
! fprintf(stderr, _("%s: received transaction log record for offset %u with no file open\n"),
progname, xlogoff);
return false;
}
***************
*** 527,533 **** ReceiveXlogStream(PGconn *conn, XLogRecPtr startpos, uint32 timeline, char *sysi
copybuf + STREAMING_HEADER_SIZE + bytes_written,
bytes_to_write) != bytes_to_write)
{
! fprintf(stderr, _("%s: could not write %u bytes to WAL file %s: %s\n"),
progname,
bytes_to_write,
current_walfile_name,
--- 532,539 ----
copybuf + STREAMING_HEADER_SIZE + bytes_written,
bytes_to_write) != bytes_to_write)
{
! fprintf(stderr,
! _("%s: could not write %u bytes to WAL file \"%s\": %s\n"),
progname,
bytes_to_write,
current_walfile_name,
***************
*** 575,581 **** ReceiveXlogStream(PGconn *conn, XLogRecPtr startpos, uint32 timeline, char *sysi
res = PQgetResult(conn);
if (PQresultStatus(res) != PGRES_COMMAND_OK)
{
! fprintf(stderr, _("%s: unexpected termination of replication stream: %s\n"),
progname, PQresultErrorMessage(res));
return false;
}
--- 581,587 ----
res = PQgetResult(conn);
if (PQresultStatus(res) != PGRES_COMMAND_OK)
{
! fprintf(stderr, _("%s: unexpected termination of replication stream: %s"),
progname, PQresultErrorMessage(res));
return false;
}