summaryrefslogtreecommitdiff
path: root/src/bin/pg_basebackup/pg_receivexlog.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/bin/pg_basebackup/pg_receivexlog.c')
-rw-r--r--src/bin/pg_basebackup/pg_receivexlog.c73
1 files changed, 42 insertions, 31 deletions
diff --git a/src/bin/pg_basebackup/pg_receivexlog.c b/src/bin/pg_basebackup/pg_receivexlog.c
index 20adb653cf1..df971b24f49 100644
--- a/src/bin/pg_basebackup/pg_receivexlog.c
+++ b/src/bin/pg_basebackup/pg_receivexlog.c
@@ -45,9 +45,11 @@ volatile bool time_to_abort = false;
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)
@@ -57,18 +59,19 @@ 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"));
}
@@ -121,7 +124,8 @@ FindStreamingStart(XLogRecPtr currentpos, uint32 currenttimeline)
log,
seg;
- 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 */
@@ -147,7 +151,8 @@ 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"),
+ fprintf(stderr,
+ _("%s: could not parse transaction log file name \"%s\"\n"),
progname, dirent->d_name);
disconnect_and_exit(1);
}
@@ -178,7 +183,8 @@ FindStreamingStart(XLogRecPtr currentpos, uint32 currenttimeline)
}
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;
}
@@ -230,20 +236,24 @@ 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));
+ 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", &startpos.xlogid, &startpos.xrecoff) != 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);
}
@@ -263,12 +273,12 @@ StreamLog(void)
* Start the replication
*/
if (verbose)
- fprintf(stderr, _("%s: starting log streaming at %X/%X (timeline %u)\n"),
+ fprintf(stderr,
+ _("%s: starting log streaming at %X/%X (timeline %u)\n"),
progname, startpos.xlogid, startpos.xrecoff, timeline);
ReceiveXlogStream(conn, startpos, timeline, NULL, basedir,
- stop_streaming,
- standby_message_timeout, false);
+ stop_streaming, standby_message_timeout, false);
PQfinish(conn);
}
@@ -296,15 +306,14 @@ main(int argc, char **argv)
{"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]);
@@ -317,8 +326,8 @@ main(int argc, char **argv)
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);
@@ -412,12 +421,13 @@ main(int argc, char **argv)
{
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);
@@ -425,7 +435,8 @@ main(int argc, char **argv)
}
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);
}