static void ReceiveAndUnpackTarFile(PGconn *conn, PGresult *res, int rownum);
static void BaseBackup(void);
-static bool reached_end_position(XLogRecPtr segendpos, uint32 timeline, bool segment_finished);
+static bool reached_end_position(XLogRecPtr segendpos, uint32 timeline,
+ bool segment_finished);
#ifdef HAVE_LIBZ
static const char *
}
#endif
-
static void
usage(void)
{
printf(_("Usage:\n"));
printf(_(" %s [OPTION]...\n"), progname);
printf(_("\nOptions controlling the output:\n"));
- printf(_(" -D, --pgdata=DIRECTORY receive base backup into directory\n"));
- printf(_(" -F, --format=p|t output format (plain (default), tar)\n"));
- printf(_(" -x, --xlog include required WAL files in backup (fetch mode)\n"));
+ printf(_(" -D, --pgdata=DIRECTORY receive base backup into directory\n"));
+ printf(_(" -F, --format=p|t output format (plain (default), tar)\n"));
+ printf(_(" -x, --xlog include required WAL files in backup (fetch mode)\n"));
printf(_(" -X, --xlog-method=fetch|stream\n"
- " include required WAL files with specified method\n"));
- printf(_(" -z, --gzip compress tar output\n"));
- printf(_(" -Z, --compress=0-9 compress tar output with given compression level\n"));
+ " include required WAL files with specified method\n"));
+ printf(_(" -z, --gzip compress tar output\n"));
+ printf(_(" -Z, --compress=0-9 compress tar output with given compression level\n"));
printf(_("\nGeneral options:\n"));
printf(_(" -c, --checkpoint=fast|spread\n"
- " set fast or spread checkpointing\n"));
- printf(_(" -l, --label=LABEL set backup label\n"));
- printf(_(" -P, --progress show progress information\n"));
- printf(_(" -v, --verbose output verbose messages\n"));
- printf(_(" -V, --version output version information, then exit\n"));
- printf(_(" -?, --help show this help, then exit\n"));
+ " set fast or spread checkpointing\n"));
+ printf(_(" -l, --label=LABEL set backup label\n"));
+ printf(_(" -P, --progress show progress information\n"));
+ printf(_(" -v, --verbose output verbose messages\n"));
+ 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"));
- printf(_(" -w, --no-password never prompt for password\n"));
- printf(_(" -W, --password force password prompt (should happen automatically)\n"));
+ printf(_(" -s, --status-interval=INTERVAL\n"
+ " 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"));
+ printf(_(" -w, --no-password never prompt for password\n"));
+ printf(_(" -W, --password force password prompt (should happen automatically)\n"));
printf(_("\nReport bugs to <pgsql-bugs@postgresql.org>.\n"));
}
* time to stop.
*/
static bool
-reached_end_position(XLogRecPtr segendpos, uint32 timeline, bool segment_finished)
+reached_end_position(XLogRecPtr segendpos, uint32 timeline,
+ bool segment_finished)
{
if (!has_xlogendptr)
{
if (sscanf(xlogend, "%X/%X", &hi, &lo) != 2)
{
- fprintf(stderr, _("%s: could not parse xlog end position \"%s\"\n"),
+ fprintf(stderr,
+ _("%s: could not parse transaction log location \"%s\"\n"),
progname, xlogend);
exit(1);
}
{
if (!ReceiveXlogStream(param->bgconn, param->startptr, param->timeline,
param->sysidentifier, param->xlogdir,
- reached_end_position, standby_message_timeout, true))
+ reached_end_position, standby_message_timeout,
+ true))
/*
* Any errors will already have been reported in the function process,
/* Convert the starting position */
if (sscanf(startpos, "%X/%X", &hi, &lo) != 2)
{
- fprintf(stderr, _("%s: invalid format of xlog location: %s\n"),
+ fprintf(stderr,
+ _("%s: could not parse transaction log location \"%s\"\n"),
progname, startpos);
disconnect_and_exit(1);
}
/* Create our background pipe */
if (pipe(bgpipe) < 0)
{
- fprintf(stderr, _("%s: could not create pipe for background process: %s\n"),
+ fprintf(stderr,
+ _("%s: could not create pipe for background process: %s\n"),
progname, strerror(errno));
disconnect_and_exit(1);
}
* translatable strings. And we only test for INT64_FORMAT availability
* in snprintf, not fprintf.
*/
- snprintf(totaldone_str, sizeof(totaldone_str), INT64_FORMAT, totaldone / 1024);
+ snprintf(totaldone_str, sizeof(totaldone_str), INT64_FORMAT,
+ totaldone / 1024);
snprintf(totalsize_str, sizeof(totalsize_str), INT64_FORMAT, totalsize);
if (verbose)
ngettext("%s/%s kB (100%%), %d/%d tablespace %35s",
"%s/%s kB (100%%), %d/%d tablespaces %35s",
tablespacecount),
- totaldone_str, totalsize_str, tablespacenum, tablespacecount, "");
+ totaldone_str, totalsize_str,
+ tablespacenum, tablespacecount, "");
else
fprintf(stderr,
ngettext("%s/%s kB (%d%%), %d/%d tablespace (%-30.30s)",
"%s/%s kB (%d%%), %d/%d tablespaces (%-30.30s)",
tablespacecount),
- totaldone_str, totalsize_str, percent, tablespacenum, tablespacecount, filename);
+ totaldone_str, totalsize_str, percent,
+ tablespacenum, tablespacecount, filename);
}
else
fprintf(stderr,
ngettext("%s/%s kB (%d%%), %d/%d tablespace",
"%s/%s kB (%d%%), %d/%d tablespaces",
tablespacecount),
- totaldone_str, totalsize_str, percent, tablespacenum, tablespacecount);
+ totaldone_str, totalsize_str, percent,
+ tablespacenum, tablespacecount);
fprintf(stderr, "\r");
}
#endif
if (PQgetisnull(res, rownum, 0))
-
+ {
/*
* Base tablespaces
*/
if (compresslevel != 0)
{
ztarfile = gzdopen(dup(fileno(stdout)), "wb");
- if (gzsetparams(ztarfile, compresslevel, Z_DEFAULT_STRATEGY) != Z_OK)
+ if (gzsetparams(ztarfile, compresslevel,
+ Z_DEFAULT_STRATEGY) != Z_OK)
{
- fprintf(stderr, _("%s: could not set compression level %d: %s\n"),
+ fprintf(stderr,
+ _("%s: could not set compression level %d: %s\n"),
progname, compresslevel, get_gz_error(ztarfile));
disconnect_and_exit(1);
}
{
snprintf(filename, sizeof(filename), "%s/base.tar.gz", basedir);
ztarfile = gzopen(filename, "wb");
- if (gzsetparams(ztarfile, compresslevel, Z_DEFAULT_STRATEGY) != Z_OK)
+ if (gzsetparams(ztarfile, compresslevel,
+ Z_DEFAULT_STRATEGY) != Z_OK)
{
- fprintf(stderr, _("%s: could not set compression level %d: %s\n"),
+ fprintf(stderr,
+ _("%s: could not set compression level %d: %s\n"),
progname, compresslevel, get_gz_error(ztarfile));
disconnect_and_exit(1);
}
tarfile = fopen(filename, "wb");
}
}
+ }
else
{
/*
#ifdef HAVE_LIBZ
if (compresslevel != 0)
{
- snprintf(filename, sizeof(filename), "%s/%s.tar.gz", basedir, PQgetvalue(res, rownum, 0));
+ snprintf(filename, sizeof(filename), "%s/%s.tar.gz", basedir,
+ PQgetvalue(res, rownum, 0));
ztarfile = gzopen(filename, "wb");
- if (gzsetparams(ztarfile, compresslevel, Z_DEFAULT_STRATEGY) != Z_OK)
+ if (gzsetparams(ztarfile, compresslevel,
+ Z_DEFAULT_STRATEGY) != Z_OK)
{
- fprintf(stderr, _("%s: could not set compression level %d: %s\n"),
+ fprintf(stderr,
+ _("%s: could not set compression level %d: %s\n"),
progname, compresslevel, get_gz_error(ztarfile));
disconnect_and_exit(1);
}
else
#endif
{
- snprintf(filename, sizeof(filename), "%s/%s.tar", basedir, PQgetvalue(res, rownum, 0));
+ snprintf(filename, sizeof(filename), "%s/%s.tar", basedir,
+ PQgetvalue(res, rownum, 0));
tarfile = fopen(filename, "wb");
}
}
if (!ztarfile)
{
/* Compression is in use */
- fprintf(stderr, _("%s: could not create compressed file \"%s\": %s\n"),
+ fprintf(stderr,
+ _("%s: could not create compressed file \"%s\": %s\n"),
progname, filename, get_gz_error(ztarfile));
disconnect_and_exit(1);
}
#ifdef HAVE_LIBZ
if (ztarfile != NULL)
{
- if (gzwrite(ztarfile, zerobuf, sizeof(zerobuf)) != sizeof(zerobuf))
+ if (gzwrite(ztarfile, zerobuf, sizeof(zerobuf)) !=
+ sizeof(zerobuf))
{
- fprintf(stderr, _("%s: could not write to compressed file \"%s\": %s\n"),
+ fprintf(stderr,
+ _("%s: could not write to compressed file \"%s\": %s\n"),
progname, filename, get_gz_error(ztarfile));
disconnect_and_exit(1);
}
{
if (fwrite(zerobuf, sizeof(zerobuf), 1, tarfile) != 1)
{
- fprintf(stderr, _("%s: could not write to file \"%s\": %s\n"),
+ fprintf(stderr,
+ _("%s: could not write to file \"%s\": %s\n"),
progname, filename, strerror(errno));
disconnect_and_exit(1);
}
{
if (gzclose(ztarfile) != 0)
{
- fprintf(stderr, _("%s: could not close compressed file \"%s\": %s\n"),
+ fprintf(stderr,
+ _("%s: could not close compressed file \"%s\": %s\n"),
progname, filename, get_gz_error(ztarfile));
disconnect_and_exit(1);
}
{
if (fclose(tarfile) != 0)
{
- fprintf(stderr, _("%s: could not close file \"%s\": %s\n"),
+ fprintf(stderr,
+ _("%s: could not close file \"%s\": %s\n"),
progname, filename, strerror(errno));
disconnect_and_exit(1);
}
{
if (gzwrite(ztarfile, copybuf, r) != r)
{
- fprintf(stderr, _("%s: could not write to compressed file \"%s\": %s\n"),
+ fprintf(stderr,
+ _("%s: could not write to compressed file \"%s\": %s\n"),
progname, filename, get_gz_error(ztarfile));
disconnect_and_exit(1);
}
/*
* First part of header is zero terminated filename
*/
- snprintf(filename, sizeof(filename), "%s/%s", current_path, copybuf);
+ snprintf(filename, sizeof(filename), "%s/%s", current_path,
+ copybuf);
if (filename[strlen(filename) - 1] == '/')
{
/*
}
#ifndef WIN32
if (chmod(filename, (mode_t) filemode))
- fprintf(stderr, _("%s: could not set permissions on directory \"%s\": %s\n"),
+ fprintf(stderr,
+ _("%s: could not set permissions on directory \"%s\": %s\n"),
progname, filename, strerror(errno));
#endif
}
}
else
{
- fprintf(stderr, _("%s: unrecognized link indicator \"%c\"\n"),
+ fprintf(stderr,
+ _("%s: unrecognized link indicator \"%c\"\n"),
progname, copybuf[156]);
disconnect_and_exit(1);
}
if (file != NULL)
{
- fprintf(stderr, _("%s: COPY stream ended before last file was finished\n"), progname);
+ fprintf(stderr,
+ _("%s: COPY stream ended before last file was finished\n"),
+ progname);
disconnect_and_exit(1);
}
res = PQexec(conn, "IDENTIFY_SYSTEM");
if (PQresultStatus(res) != PGRES_TUPLES_OK)
{
- fprintf(stderr, _("%s: could not identify system: %s"),
- progname, PQerrorMessage(conn));
+ 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\n"),
- progname, PQntuples(res), PQnfields(res));
+ 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));
* Start the actual backup
*/
PQescapeStringConn(conn, escaped_label, label, sizeof(escaped_label), &i);
- snprintf(current_path, sizeof(current_path), "BASE_BACKUP LABEL '%s' %s %s %s %s",
+ snprintf(current_path, sizeof(current_path),
+ "BASE_BACKUP LABEL '%s' %s %s %s %s",
escaped_label,
showprogress ? "PROGRESS" : "",
includewal && !streamwal ? "WAL" : "",
if (PQsendQuery(conn, current_path) == 0)
{
- fprintf(stderr, _("%s: could not send base backup command: %s"),
- progname, PQerrorMessage(conn));
+ fprintf(stderr, _("%s: could not send replication command \"%s\": %s"),
+ progname, "BASE_BACKUP", PQerrorMessage(conn));
disconnect_and_exit(1);
}
}
strcpy(xlogstart, PQgetvalue(res, 0, 0));
if (verbose && includewal)
- fprintf(stderr, "xlog start point: %s\n", xlogstart);
+ fprintf(stderr, "transaction log start point: %s\n", xlogstart);
PQclear(res);
MemSet(xlogend, 0, sizeof(xlogend));
*/
if (format == 't' && strcmp(basedir, "-") == 0 && PQntuples(res) > 1)
{
- fprintf(stderr, _("%s: can only write single tablespace to stdout, database has %d\n"),
+ fprintf(stderr,
+ _("%s: can only write single tablespace to stdout, database has %d\n"),
progname, PQntuples(res));
disconnect_and_exit(1);
}
res = PQgetResult(conn);
if (PQresultStatus(res) != PGRES_TUPLES_OK)
{
- fprintf(stderr, _("%s: could not get WAL end position from server: %s"),
+ 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 WAL end position returned from server\n"),
+ 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, "xlog end point: %s\n", xlogend);
+ fprintf(stderr, "transaction log end point: %s\n", xlogend);
PQclear(res);
res = PQgetResult(conn);
#endif
if (verbose)
- fprintf(stderr, _("%s: waiting for background process to finish streaming...\n"), progname);
+ fprintf(stderr,
+ _("%s: waiting for background process to finish streaming...\n"), progname);
#ifndef WIN32
if (write(bgpipe[1], xlogend, strlen(xlogend)) != strlen(xlogend))
{
- fprintf(stderr, _("%s: could not send command to background pipe: %s\n"),
+ fprintf(stderr,
+ _("%s: could not send command to background pipe: %s\n"),
progname, strerror(errno));
disconnect_and_exit(1);
}
*/
if (sscanf(xlogend, "%X/%X", &hi, &lo) != 2)
{
- fprintf(stderr, _("%s: could not parse xlog end position \"%s\"\n"),
+ fprintf(stderr,
+ _("%s: could not parse transaction log location \"%s\"\n"),
progname, xlogend);
disconnect_and_exit(1);
}
InterlockedIncrement(&has_xlogendptr);
/* First wait for the thread to exit */
- if (WaitForSingleObjectEx((HANDLE) bgchild, INFINITE, FALSE) != WAIT_OBJECT_0)
+ if (WaitForSingleObjectEx((HANDLE) bgchild, INFINITE, FALSE) !=
+ WAIT_OBJECT_0)
{
_dosmaperr(GetLastError());
fprintf(stderr, _("%s: could not wait for child thread: %s\n"),
{"username", required_argument, NULL, 'U'},
{"no-password", no_argument, NULL, 'w'},
{"password", no_argument, NULL, 'W'},
- {"statusint", required_argument, NULL, 's'},
+ {"status-interval", required_argument, NULL, 's'},
{"verbose", no_argument, NULL, 'v'},
{"progress", no_argument, NULL, 'P'},
{NULL, 0, NULL, 0}
format = 't';
else
{
- fprintf(stderr, _("%s: invalid output format \"%s\", must be \"plain\" or \"tar\"\n"),
+ fprintf(stderr,
+ _("%s: invalid output format \"%s\", must be \"plain\" or \"tar\"\n"),
progname, optarg);
exit(1);
}
case 'x':
if (includewal)
{
- fprintf(stderr, _("%s: cannot specify both --xlog and --xlog-method\n"),
+ fprintf(stderr,
+ _("%s: cannot specify both --xlog and --xlog-method\n"),
progname);
exit(1);
}
case 'X':
if (includewal)
{
- fprintf(stderr, _("%s: cannot specify both --xlog and --xlog-method\n"),
+ fprintf(stderr,
+ _("%s: cannot specify both --xlog and --xlog-method\n"),
progname);
exit(1);
}
streamwal = true;
else
{
- fprintf(stderr, _("%s: invalid xlog-method option \"%s\", must be empty, \"fetch\", or \"stream\"\n"),
+ fprintf(stderr,
+ _("%s: invalid xlog-method option \"%s\", must be empty, \"fetch\", or \"stream\"\n"),
progname, optarg);
exit(1);
}
if (format == 'p' || strcmp(basedir, "-") != 0)
verify_dir_is_empty_or_create(basedir);
-
BaseBackup();
return 0;
static void usage(void);
-static XLogRecPtr FindStreamingStart(XLogRecPtr currentpos, uint32 currenttimeline);
+static XLogRecPtr FindStreamingStart(XLogRecPtr currentpos,
+ uint32 currenttimeline);
static void StreamLog();
-static bool stop_streaming(XLogRecPtr segendpos, uint32 timeline, bool segment_finished);
+static bool stop_streaming(XLogRecPtr segendpos, uint32 timeline,
+ bool segment_finished);
static void
usage(void)
printf(_("Usage:\n"));
printf(_(" %s [OPTION]...\n"), progname);
printf(_("\nOptions:\n"));
- printf(_(" -D, --directory=DIR receive transaction log files into this directory\n"));
- printf(_(" -n, --noloop do not loop on connection lost\n"));
- printf(_(" -v, --verbose output verbose messages\n"));
- printf(_(" -V, --version output version information, then exit\n"));
- printf(_(" -?, --help show this help, then exit\n"));
+ printf(_(" -D, --directory=DIR receive transaction log files into this directory\n"));
+ printf(_(" -n, --no-loop do not loop on connection lost\n"));
+ printf(_(" -v, --verbose output verbose messages\n"));
+ 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"));
- printf(_(" -w, --no-password never prompt for password\n"));
- printf(_(" -W, --password force password prompt (should happen automatically)\n"));
+ printf(_(" -s, --status-interval=INTERVAL\n"
+ " 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"));
+ printf(_(" -w, --no-password never prompt for password\n"));
+ printf(_(" -W, --password force password prompt (should happen automatically)\n"));
printf(_("\nReport bugs to <pgsql-bugs@postgresql.org>.\n"));
}
seg;
XLogSegNo segno;
- if (strcmp(dirent->d_name, ".") == 0 || strcmp(dirent->d_name, "..") == 0)
+ if (strcmp(dirent->d_name, ".") == 0 ||
+ strcmp(dirent->d_name, "..") == 0)
continue;
/* xlog files are always 24 characters */
*/
if (sscanf(dirent->d_name, "%08X%08X%08X", &tli, &log, &seg) != 3)
{
- fprintf(stderr, _("%s: could not parse xlog filename \"%s\"\n"),
+ fprintf(stderr,
+ _("%s: could not parse transaction log file name \"%s\"\n"),
progname, dirent->d_name);
disconnect_and_exit(1);
}
}
else
{
- fprintf(stderr, _("%s: segment file '%s' is incorrect size %d, skipping\n"),
+ fprintf(stderr,
+ _("%s: segment file \"%s\" has incorrect size %d, skipping\n"),
progname, dirent->d_name, (int) statbuf.st_size);
continue;
}
res = PQexec(conn, "IDENTIFY_SYSTEM");
if (PQresultStatus(res) != PGRES_TUPLES_OK)
{
- fprintf(stderr, _("%s: could not identify system: %s\n"),
- progname, PQerrorMessage(conn));
+ 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\n"),
- progname, PQntuples(res), PQnfields(res));
+ 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", &hi, &lo) != 2)
{
- fprintf(stderr, _("%s: could not parse log start position from value \"%s\"\n"),
+ fprintf(stderr,
+ _("%s: could not parse transaction log location \"%s\"\n"),
progname, PQgetvalue(res, 0, 2));
disconnect_and_exit(1);
}
* Start the replication
*/
if (verbose)
- fprintf(stderr, _("%s: starting log streaming at %X/%X (timeline %u)\n"),
- progname,
- (uint32) (startpos >> 32), (uint32) startpos,
+ fprintf(stderr,
+ _("%s: starting log streaming at %X/%X (timeline %u)\n"),
+ progname, (uint32) (startpos >> 32), (uint32) startpos,
timeline);
ReceiveXlogStream(conn, startpos, timeline, NULL, basedir,
- stop_streaming,
- standby_message_timeout, false);
+ stop_streaming, standby_message_timeout, false);
PQfinish(conn);
}
{"host", required_argument, NULL, 'h'},
{"port", required_argument, NULL, 'p'},
{"username", required_argument, NULL, 'U'},
- {"noloop", no_argument, NULL, 'n'},
+ {"no-loop", no_argument, NULL, 'n'},
{"no-password", no_argument, NULL, 'w'},
{"password", no_argument, NULL, 'W'},
- {"statusint", required_argument, NULL, 's'},
+ {"status-interval", required_argument, NULL, 's'},
{"verbose", no_argument, NULL, 'v'},
{NULL, 0, NULL, 0}
};
int c;
-
int option_index;
progname = get_progname(argv[0]);
usage();
exit(0);
}
- else if (strcmp(argv[1], "-V") == 0
- || strcmp(argv[1], "--version") == 0)
+ else if (strcmp(argv[1], "-V") == 0 ||
+ strcmp(argv[1], "--version") == 0)
{
puts("pg_receivexlog (PostgreSQL) " PG_VERSION);
exit(0);
{
StreamLog();
if (time_to_abort)
-
+ {
/*
* We've been Ctrl-C'ed. That's not an error, so exit without an
* errorcode.
*/
exit(0);
+ }
else if (noloop)
{
fprintf(stderr, _("%s: disconnected.\n"), progname);
}
else
{
- fprintf(stderr, _("%s: disconnected. Waiting %d seconds to try again\n"),
+ fprintf(stderr,
+ _("%s: disconnected. Waiting %d seconds to try again\n"),
progname, RECONNECT_SLEEP_TIME);
pg_usleep(RECONNECT_SLEEP_TIME * 1000000);
}
#define STREAMING_KEEPALIVE_SIZE (1+sizeof(PrimaryKeepaliveMessage))
/* fd for currently open WAL file */
-static int walfile = -1;
+static int walfile = -1;
/*
* The file will be padded to 16Mb with zeroes.
*/
static int
-open_walfile(XLogRecPtr startpoint, uint32 timeline, char *basedir, char *namebuf)
+open_walfile(XLogRecPtr startpoint, uint32 timeline, char *basedir,
+ char *namebuf)
{
int f;
char fn[MAXPGPATH];
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"),
+ fprintf(stderr,
+ _("%s: could not open transaction log file \"%s\": %s\n"),
progname, fn, strerror(errno));
return -1;
}
*/
if (fstat(f, &statbuf) != 0)
{
- fprintf(stderr, _("%s: could not stat WAL segment %s: %s\n"),
+ fprintf(stderr,
+ _("%s: could not stat transaction log file \"%s\": %s\n"),
progname, fn, strerror(errno));
close(f);
return -1;
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"),
+ 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;
{
if (write(f, zerobuf, XLOG_BLCKSZ) != XLOG_BLCKSZ)
{
- fprintf(stderr, _("%s: could not pad WAL segment %s: %s\n"),
+ fprintf(stderr,
+ _("%s: could not pad transaction log file \"%s\": %s\n"),
progname, fn, strerror(errno));
free(zerobuf);
close(f);
if (lseek(f, SEEK_SET, 0) != 0)
{
- fprintf(stderr, _("%s: could not seek back to beginning of WAL segment %s: %s\n"),
+ fprintf(stderr,
+ _("%s: could not seek to beginning of transaction log file \"%s\": %s\n"),
progname, fn, strerror(errno));
close(f);
return -1;
}
/*
- * Close the current WAL file, and rename it to the correct filename if it's complete.
+ * Close the current WAL file, and rename it to the correct filename if it's
+ * complete.
*
* If segment_complete is true, rename the current WAL file even if we've not
* completed writing the whole segment.
if (currpos == -1)
{
- fprintf(stderr, _("%s: could not get current position in file %s: %s\n"),
+ 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"),
+ 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"),
+ fprintf(stderr, _("%s: could not close file \"%s\": %s\n"),
progname, walname, strerror(errno));
walfile = -1;
return false;
snprintf(newfn, sizeof(newfn), "%s/%s", basedir, walname);
if (rename(oldfn, newfn) != 0)
{
- fprintf(stderr, _("%s: could not rename file %s: %s\n"),
+ 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"),
+ fprintf(stderr,
+ _("%s: not renaming \"%s\", segment is not complete.\n"),
progname, walname);
return true;
* 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)
+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];
res = PQexec(conn, "IDENTIFY_SYSTEM");
if (PQresultStatus(res) != PGRES_TUPLES_OK)
{
- fprintf(stderr, _("%s: could not identify system: %s\n"),
- progname, PQerrorMessage(conn));
+ 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\n"),
- progname, PQntuples(res), PQnfields(res));
+ 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;
}
if (strcmp(sysidentifier, PQgetvalue(res, 0, 0)) != 0)
{
- fprintf(stderr, _("%s: system identifier does not match between base backup and streaming connection\n"), progname);
+ fprintf(stderr,
+ _("%s: system identifier does not match between base backup and streaming connection\n"),
+ progname);
PQclear(res);
return false;
}
if (timeline != atoi(PQgetvalue(res, 0, 1)))
{
- fprintf(stderr, _("%s: timeline does not match between base backup and streaming connection\n"), progname);
+ fprintf(stderr,
+ _("%s: timeline does not match between base backup and streaming connection\n"),
+ progname);
PQclear(res);
return false;
}
res = PQexec(conn, query);
if (PQresultStatus(res) != PGRES_COPY_BOTH)
{
- fprintf(stderr, _("%s: could not start replication: %s\n"),
- progname, PQresultErrorMessage(res));
+ fprintf(stderr, _("%s: could not send replication command \"%s\": %s"),
+ progname, "START_REPLICATION", PQresultErrorMessage(res));
PQclear(res);
return false;
}
*/
if (stream_stop && stream_stop(blockpos, timeline, false))
{
- if (walfile != -1 && !close_walfile(basedir, current_walfile_name, rename_partial))
+ if (walfile != -1 && !close_walfile(basedir, current_walfile_name,
+ rename_partial))
/* Potential error message is written by close_walfile */
goto error;
return true;
{
/* Time to send feedback! */
char replybuf[sizeof(StandbyReplyMessage) + 1];
- StandbyReplyMessage *replymsg = (StandbyReplyMessage *) (replybuf + 1);
+ StandbyReplyMessage *replymsg;
+ replymsg = (StandbyReplyMessage *) (replybuf + 1);
replymsg->write = blockpos;
replymsg->flush = InvalidXLogRecPtr;
replymsg->apply = InvalidXLogRecPtr;
/* Else there is actually data on the socket */
if (PQconsumeInput(conn) == 0)
{
- fprintf(stderr, _("%s: could not receive data from WAL stream: %s\n"),
+ fprintf(stderr,
+ _("%s: could not receive data from WAL stream: %s"),
progname, PQerrorMessage(conn));
goto error;
}
break;
if (r == -2)
{
- fprintf(stderr, _("%s: could not read copy data: %s\n"),
+ fprintf(stderr, _("%s: could not read COPY data: %s"),
progname, PQerrorMessage(conn));
goto error;
}
*/
if (r != STREAMING_KEEPALIVE_SIZE)
{
- fprintf(stderr, _("%s: keepalive message is incorrect size: %d\n"),
+ fprintf(stderr,
+ _("%s: keepalive message has incorrect size %d\n"),
progname, r);
goto error;
}
/* No file open yet */
if (xlogoff != 0)
{
- fprintf(stderr, _("%s: received xlog record for offset %u with no file open\n"),
+ fprintf(stderr,
+ _("%s: received transaction log record for offset %u with no file open\n"),
progname, xlogoff);
goto error;
}
/* XXX: store seek value don't reseek all the time */
if (lseek(walfile, 0, SEEK_CUR) != xlogoff)
{
- fprintf(stderr, _("%s: got WAL data offset %08x, expected %08x\n"),
+ fprintf(stderr,
+ _("%s: got WAL data offset %08x, expected %08x\n"),
progname, xlogoff, (int) lseek(walfile, 0, SEEK_CUR));
goto error;
}
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,
+ fprintf(stderr,
+ _("%s: could not write %u bytes to WAL file \"%s\": %s\n"),
+ progname, bytes_to_write, current_walfile_name,
strerror(errno));
goto error;
}
res = PQgetResult(conn);
if (PQresultStatus(res) != PGRES_COMMAND_OK)
{
- fprintf(stderr, _("%s: unexpected termination of replication stream: %s\n"),
+ fprintf(stderr,
+ _("%s: unexpected termination of replication stream: %s"),
progname, PQresultErrorMessage(res));
goto error;
}