Commit 2f29f011 authored by Alvaro Herrera's avatar Alvaro Herrera

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.
parent 04d2956f
...@@ -346,7 +346,7 @@ PostgreSQL documentation ...@@ -346,7 +346,7 @@ PostgreSQL documentation
<variablelist> <variablelist>
<varlistentry> <varlistentry>
<term><option>-s <replaceable class="parameter">interval</replaceable></option></term> <term><option>-s <replaceable class="parameter">interval</replaceable></option></term>
<term><option>--statusint=<replaceable class="parameter">interval</replaceable></option></term> <term><option>--status-interval=<replaceable class="parameter">interval</replaceable></option></term>
<listitem> <listitem>
<para> <para>
Specifies the number of seconds between status packets sent back to the Specifies the number of seconds between status packets sent back to the
......
...@@ -96,7 +96,7 @@ PostgreSQL documentation ...@@ -96,7 +96,7 @@ PostgreSQL documentation
<variablelist> <variablelist>
<varlistentry> <varlistentry>
<term><option>-n</option></term> <term><option>-n</option></term>
<term><option>--noloop</option></term> <term><option>--no-loop</option></term>
<listitem> <listitem>
<para> <para>
Don't loop on connection errors. Instead, exit right away with Don't loop on connection errors. Instead, exit right away with
...@@ -124,7 +124,7 @@ PostgreSQL documentation ...@@ -124,7 +124,7 @@ PostgreSQL documentation
<variablelist> <variablelist>
<varlistentry> <varlistentry>
<term><option>-s <replaceable class="parameter">interval</replaceable></option></term> <term><option>-s <replaceable class="parameter">interval</replaceable></option></term>
<term><option>--statusint=<replaceable class="parameter">interval</replaceable></option></term> <term><option>--status-interval=<replaceable class="parameter">interval</replaceable></option></term>
<listitem> <listitem>
<para> <para>
Specifies the number of seconds between status packets sent back to the Specifies the number of seconds between status packets sent back to the
......
This diff is collapsed.
...@@ -45,9 +45,11 @@ volatile bool time_to_abort = false; ...@@ -45,9 +45,11 @@ volatile bool time_to_abort = false;
static void usage(void); static void usage(void);
static XLogRecPtr FindStreamingStart(XLogRecPtr currentpos, uint32 currenttimeline); static XLogRecPtr FindStreamingStart(XLogRecPtr currentpos,
uint32 currenttimeline);
static void StreamLog(); 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 static void
usage(void) usage(void)
...@@ -57,18 +59,19 @@ usage(void) ...@@ -57,18 +59,19 @@ usage(void)
printf(_("Usage:\n")); printf(_("Usage:\n"));
printf(_(" %s [OPTION]...\n"), progname); printf(_(" %s [OPTION]...\n"), progname);
printf(_("\nOptions:\n")); printf(_("\nOptions:\n"));
printf(_(" -D, --directory=DIR receive transaction log files into this directory\n")); printf(_(" -D, --directory=DIR receive transaction log files into this directory\n"));
printf(_(" -n, --noloop do not loop on connection lost\n")); printf(_(" -n, --no-loop do not loop on connection lost\n"));
printf(_(" -v, --verbose output verbose messages\n")); printf(_(" -v, --verbose output verbose messages\n"));
printf(_(" -V, --version output version information, then exit\n")); printf(_(" -V, --version output version information, then exit\n"));
printf(_(" -?, --help show this help, then exit\n")); printf(_(" -?, --help show this help, then exit\n"));
printf(_("\nConnection options:\n")); printf(_("\nConnection options:\n"));
printf(_(" -s, --statusint=INTERVAL time between status packets sent to server (in seconds)\n")); printf(_(" -s, --status-interval=INTERVAL\n"
printf(_(" -h, --host=HOSTNAME database server host or socket directory\n")); " time between status packets sent to server (in seconds)\n"));
printf(_(" -p, --port=PORT database server port number\n")); printf(_(" -h, --host=HOSTNAME database server host or socket directory\n"));
printf(_(" -U, --username=NAME connect as specified database user\n")); printf(_(" -p, --port=PORT database server port number\n"));
printf(_(" -w, --no-password never prompt for password\n")); printf(_(" -U, --username=NAME connect as specified database user\n"));
printf(_(" -W, --password force password prompt (should happen automatically)\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")); printf(_("\nReport bugs to <pgsql-bugs@postgresql.org>.\n"));
} }
...@@ -123,7 +126,8 @@ FindStreamingStart(XLogRecPtr currentpos, uint32 currenttimeline) ...@@ -123,7 +126,8 @@ FindStreamingStart(XLogRecPtr currentpos, uint32 currenttimeline)
seg; seg;
XLogSegNo segno; 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; continue;
/* xlog files are always 24 characters */ /* xlog files are always 24 characters */
...@@ -149,7 +153,8 @@ FindStreamingStart(XLogRecPtr currentpos, uint32 currenttimeline) ...@@ -149,7 +153,8 @@ FindStreamingStart(XLogRecPtr currentpos, uint32 currenttimeline)
*/ */
if (sscanf(dirent->d_name, "%08X%08X%08X", &tli, &log, &seg) != 3) 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); progname, dirent->d_name);
disconnect_and_exit(1); disconnect_and_exit(1);
} }
...@@ -179,7 +184,8 @@ FindStreamingStart(XLogRecPtr currentpos, uint32 currenttimeline) ...@@ -179,7 +184,8 @@ FindStreamingStart(XLogRecPtr currentpos, uint32 currenttimeline)
} }
else 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); progname, dirent->d_name, (int) statbuf.st_size);
continue; continue;
} }
...@@ -232,20 +238,22 @@ StreamLog(void) ...@@ -232,20 +238,22 @@ StreamLog(void)
res = PQexec(conn, "IDENTIFY_SYSTEM"); res = PQexec(conn, "IDENTIFY_SYSTEM");
if (PQresultStatus(res) != PGRES_TUPLES_OK) if (PQresultStatus(res) != PGRES_TUPLES_OK)
{ {
fprintf(stderr, _("%s: could not identify system: %s\n"), fprintf(stderr, _("%s: could not send replication command \"%s\": %s"),
progname, PQerrorMessage(conn)); progname, "IDENTIFY_SYSTEM", PQerrorMessage(conn));
disconnect_and_exit(1); disconnect_and_exit(1);
} }
if (PQntuples(res) != 1 || PQnfields(res) != 3) if (PQntuples(res) != 1 || PQnfields(res) != 3)
{ {
fprintf(stderr, _("%s: could not identify system, got %d rows and %d fields\n"), fprintf(stderr,
progname, PQntuples(res), PQnfields(res)); _("%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); disconnect_and_exit(1);
} }
timeline = atoi(PQgetvalue(res, 0, 1)); timeline = atoi(PQgetvalue(res, 0, 1));
if (sscanf(PQgetvalue(res, 0, 2), "%X/%X", &hi, &lo) != 2) 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)); progname, PQgetvalue(res, 0, 2));
disconnect_and_exit(1); disconnect_and_exit(1);
} }
...@@ -266,14 +274,13 @@ StreamLog(void) ...@@ -266,14 +274,13 @@ StreamLog(void)
* Start the replication * Start the replication
*/ */
if (verbose) if (verbose)
fprintf(stderr, _("%s: starting log streaming at %X/%X (timeline %u)\n"), fprintf(stderr,
progname, _("%s: starting log streaming at %X/%X (timeline %u)\n"),
(uint32) (startpos >> 32), (uint32) startpos, progname, (uint32) (startpos >> 32), (uint32) startpos,
timeline); timeline);
ReceiveXlogStream(conn, startpos, timeline, NULL, basedir, ReceiveXlogStream(conn, startpos, timeline, NULL, basedir,
stop_streaming, stop_streaming, standby_message_timeout, false);
standby_message_timeout, false);
PQfinish(conn); PQfinish(conn);
} }
...@@ -301,15 +308,14 @@ main(int argc, char **argv) ...@@ -301,15 +308,14 @@ main(int argc, char **argv)
{"host", required_argument, NULL, 'h'}, {"host", required_argument, NULL, 'h'},
{"port", required_argument, NULL, 'p'}, {"port", required_argument, NULL, 'p'},
{"username", required_argument, NULL, 'U'}, {"username", required_argument, NULL, 'U'},
{"noloop", no_argument, NULL, 'n'}, {"no-loop", no_argument, NULL, 'n'},
{"no-password", no_argument, NULL, 'w'}, {"no-password", no_argument, NULL, 'w'},
{"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'}, {"verbose", no_argument, NULL, 'v'},
{NULL, 0, NULL, 0} {NULL, 0, NULL, 0}
}; };
int c; int c;
int option_index; int option_index;
progname = get_progname(argv[0]); progname = get_progname(argv[0]);
...@@ -322,8 +328,8 @@ main(int argc, char **argv) ...@@ -322,8 +328,8 @@ main(int argc, char **argv)
usage(); usage();
exit(0); exit(0);
} }
else if (strcmp(argv[1], "-V") == 0 else if (strcmp(argv[1], "-V") == 0 ||
|| strcmp(argv[1], "--version") == 0) strcmp(argv[1], "--version") == 0)
{ {
puts("pg_receivexlog (PostgreSQL) " PG_VERSION); puts("pg_receivexlog (PostgreSQL) " PG_VERSION);
exit(0); exit(0);
...@@ -417,12 +423,13 @@ main(int argc, char **argv) ...@@ -417,12 +423,13 @@ main(int argc, char **argv)
{ {
StreamLog(); StreamLog();
if (time_to_abort) if (time_to_abort)
{
/* /*
* We've been Ctrl-C'ed. That's not an error, so exit without an * We've been Ctrl-C'ed. That's not an error, so exit without an
* errorcode. * errorcode.
*/ */
exit(0); exit(0);
}
else if (noloop) else if (noloop)
{ {
fprintf(stderr, _("%s: disconnected.\n"), progname); fprintf(stderr, _("%s: disconnected.\n"), progname);
...@@ -430,7 +437,8 @@ main(int argc, char **argv) ...@@ -430,7 +437,8 @@ main(int argc, char **argv)
} }
else 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); progname, RECONNECT_SLEEP_TIME);
pg_usleep(RECONNECT_SLEEP_TIME * 1000000); pg_usleep(RECONNECT_SLEEP_TIME * 1000000);
} }
......
This diff is collapsed.
...@@ -184,7 +184,8 @@ GetConnection(void) ...@@ -184,7 +184,8 @@ GetConnection(void)
tmpparam = PQparameterStatus(tmpconn, "integer_datetimes"); tmpparam = PQparameterStatus(tmpconn, "integer_datetimes");
if (!tmpparam) if (!tmpparam)
{ {
fprintf(stderr, _("%s: could not determine server setting for integer_datetimes\n"), fprintf(stderr,
_("%s: could not determine server setting for integer_datetimes\n"),
progname); progname);
PQfinish(tmpconn); PQfinish(tmpconn);
exit(1); exit(1);
...@@ -196,7 +197,8 @@ GetConnection(void) ...@@ -196,7 +197,8 @@ GetConnection(void)
if (strcmp(tmpparam, "off") != 0) if (strcmp(tmpparam, "off") != 0)
#endif #endif
{ {
fprintf(stderr, _("%s: integer_datetimes compile flag does not match server\n"), fprintf(stderr,
_("%s: integer_datetimes compile flag does not match server\n"),
progname); progname);
PQfinish(tmpconn); PQfinish(tmpconn);
exit(1); exit(1);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment