aboutsummaryrefslogtreecommitdiff
path: root/src/bin/pg_basebackup/pg_receivexlog.c
diff options
context:
space:
mode:
authorAlvaro Herrera <alvherre@alvh.no-ip.org>2012-07-31 10:11:11 -0400
committerAlvaro Herrera <alvherre@alvh.no-ip.org>2012-07-31 11:02:39 -0400
commit2f29f011c82310235c8dfb25f7e648601276a802 (patch)
tree6dfae946b892ab0b00d8b0595e72ad279ee79a66 /src/bin/pg_basebackup/pg_receivexlog.c
parent04d2956f0df0d95da3dd2d202b9482d24822cc71 (diff)
downloadpostgresql-2f29f011c82310235c8dfb25f7e648601276a802.tar.gz
postgresql-2f29f011c82310235c8dfb25f7e648601276a802.zip
pg_basebackup: stylistic adjustments
The most user-visible part of this is to change the long options --statusint and --noloop to --status-interval and --no-loop, respectively, per discussion. Also, consistently enclose file names in double quotes, per our conventions; and consistently use the term "transaction log file" to talk about WAL segments. (Someday we may need to go over this terminology and make it consistent across the whole source code.) Finally, reflow the code to better fit in 80 columns, and have pgindent fix it up some more.
Diffstat (limited to 'src/bin/pg_basebackup/pg_receivexlog.c')
-rw-r--r--src/bin/pg_basebackup/pg_receivexlog.c74
1 files changed, 41 insertions, 33 deletions
diff --git a/src/bin/pg_basebackup/pg_receivexlog.c b/src/bin/pg_basebackup/pg_receivexlog.c
index c4e1d2a682e..3a30a135403 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"));
}
@@ -123,7 +126,8 @@ FindStreamingStart(XLogRecPtr currentpos, uint32 currenttimeline)
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 */
@@ -149,7 +153,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);
}
@@ -179,7 +184,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;
}
@@ -232,20 +238,22 @@ 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", &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);
}
@@ -266,14 +274,13 @@ StreamLog(void)
* 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);
}
@@ -301,15 +308,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]);
@@ -322,8 +328,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);
@@ -417,12 +423,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);
@@ -430,7 +437,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);
}