summaryrefslogtreecommitdiff
path: root/src/bin/pg_basebackup/pg_receivewal.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/bin/pg_basebackup/pg_receivewal.c')
-rw-r--r--src/bin/pg_basebackup/pg_receivewal.c122
1 files changed, 50 insertions, 72 deletions
diff --git a/src/bin/pg_basebackup/pg_receivewal.c b/src/bin/pg_basebackup/pg_receivewal.c
index aa114f1563d..9e4d296129c 100644
--- a/src/bin/pg_basebackup/pg_receivewal.c
+++ b/src/bin/pg_basebackup/pg_receivewal.c
@@ -20,6 +20,7 @@
#include <unistd.h>
#include "common/file_perm.h"
+#include "fe_utils/logging.h"
#include "libpq-fe.h"
#include "access/xlog_internal.h"
#include "getopt_long.h"
@@ -114,16 +115,16 @@ stop_streaming(XLogRecPtr xlogpos, uint32 timeline, bool segment_finished)
/* we assume that we get called once at the end of each segment */
if (verbose && segment_finished)
- fprintf(stderr, _("%s: finished segment at %X/%X (timeline %u)\n"),
- progname, (uint32) (xlogpos >> 32), (uint32) xlogpos,
- timeline);
+ pg_log_info("finished segment at %X/%X (timeline %u)",
+ (uint32) (xlogpos >> 32), (uint32) xlogpos,
+ timeline);
if (!XLogRecPtrIsInvalid(endpos) && endpos < xlogpos)
{
if (verbose)
- fprintf(stderr, _("%s: stopped log streaming at %X/%X (timeline %u)\n"),
- progname, (uint32) (xlogpos >> 32), (uint32) xlogpos,
- timeline);
+ pg_log_info("stopped log streaming at %X/%X (timeline %u)",
+ (uint32) (xlogpos >> 32), (uint32) xlogpos,
+ timeline);
time_to_stop = true;
return true;
}
@@ -137,9 +138,9 @@ stop_streaming(XLogRecPtr xlogpos, uint32 timeline, bool segment_finished)
* timeline, but it's close enough for reporting purposes.
*/
if (verbose && prevtimeline != 0 && prevtimeline != timeline)
- fprintf(stderr, _("%s: switched to timeline %u at %X/%X\n"),
- progname, timeline,
- (uint32) (prevpos >> 32), (uint32) prevpos);
+ pg_log_info("switched to timeline %u at %X/%X",
+ timeline,
+ (uint32) (prevpos >> 32), (uint32) prevpos);
prevtimeline = timeline;
prevpos = xlogpos;
@@ -147,8 +148,7 @@ stop_streaming(XLogRecPtr xlogpos, uint32 timeline, bool segment_finished)
if (time_to_stop)
{
if (verbose)
- fprintf(stderr, _("%s: received interrupt signal, exiting\n"),
- progname);
+ pg_log_info("received interrupt signal, exiting");
return true;
}
return false;
@@ -167,8 +167,7 @@ get_destination_dir(char *dest_folder)
dir = opendir(dest_folder);
if (dir == NULL)
{
- fprintf(stderr, _("%s: could not open directory \"%s\": %s\n"),
- progname, basedir, strerror(errno));
+ pg_log_error("could not open directory \"%s\": %m", basedir);
exit(1);
}
@@ -185,8 +184,7 @@ close_destination_dir(DIR *dest_dir, char *dest_folder)
Assert(dest_dir != NULL && dest_folder != NULL);
if (closedir(dest_dir))
{
- fprintf(stderr, _("%s: could not close directory \"%s\": %s\n"),
- progname, dest_folder, strerror(errno));
+ pg_log_error("could not close directory \"%s\": %m", dest_folder);
exit(1);
}
}
@@ -266,16 +264,14 @@ FindStreamingStart(uint32 *tli)
snprintf(fullpath, sizeof(fullpath), "%s/%s", basedir, dirent->d_name);
if (stat(fullpath, &statbuf) != 0)
{
- fprintf(stderr, _("%s: could not stat file \"%s\": %s\n"),
- progname, fullpath, strerror(errno));
+ pg_log_error("could not stat file \"%s\": %m", fullpath);
exit(1);
}
if (statbuf.st_size != WalSegSz)
{
- fprintf(stderr,
- _("%s: segment file \"%s\" has incorrect size %d, skipping\n"),
- progname, dirent->d_name, (int) statbuf.st_size);
+ pg_log_warning("segment file \"%s\" has incorrect size %d, skipping",
+ dirent->d_name, (int) statbuf.st_size);
continue;
}
}
@@ -292,25 +288,25 @@ FindStreamingStart(uint32 *tli)
fd = open(fullpath, O_RDONLY | PG_BINARY, 0);
if (fd < 0)
{
- fprintf(stderr, _("%s: could not open compressed file \"%s\": %s\n"),
- progname, fullpath, strerror(errno));
+ pg_log_error("could not open compressed file \"%s\": %m",
+ fullpath);
exit(1);
}
if (lseek(fd, (off_t) (-4), SEEK_END) < 0)
{
- fprintf(stderr, _("%s: could not seek in compressed file \"%s\": %s\n"),
- progname, fullpath, strerror(errno));
+ pg_log_error("could not seek in compressed file \"%s\": %m",
+ fullpath);
exit(1);
}
r = read(fd, (char *) buf, sizeof(buf));
if (r != sizeof(buf))
{
if (r < 0)
- fprintf(stderr, _("%s: could not read compressed file \"%s\": %s\n"),
- progname, fullpath, strerror(errno));
+ pg_log_error("could not read compressed file \"%s\": %m",
+ fullpath);
else
- fprintf(stderr, _("%s: could not read compressed file \"%s\": read %d of %zu\n"),
- progname, fullpath, r, sizeof(buf));
+ pg_log_error("could not read compressed file \"%s\": read %d of %zu",
+ fullpath, r, sizeof(buf));
exit(1);
}
@@ -320,9 +316,8 @@ FindStreamingStart(uint32 *tli)
if (bytes_out != WalSegSz)
{
- fprintf(stderr,
- _("%s: compressed segment file \"%s\" has incorrect uncompressed size %d, skipping\n"),
- progname, dirent->d_name, bytes_out);
+ pg_log_warning("compressed segment file \"%s\" has incorrect uncompressed size %d, skipping",
+ dirent->d_name, bytes_out);
continue;
}
}
@@ -340,8 +335,7 @@ FindStreamingStart(uint32 *tli)
if (errno)
{
- fprintf(stderr, _("%s: could not read directory \"%s\": %s\n"),
- progname, basedir, strerror(errno));
+ pg_log_error("could not read directory \"%s\": %m", basedir);
exit(1);
}
@@ -426,10 +420,9 @@ StreamLog(void)
* Start the replication
*/
if (verbose)
- fprintf(stderr,
- _("%s: starting log streaming at %X/%X (timeline %u)\n"),
- progname, (uint32) (stream.startpos >> 32), (uint32) stream.startpos,
- stream.timeline);
+ pg_log_info("starting log streaming at %X/%X (timeline %u)",
+ (uint32) (stream.startpos >> 32), (uint32) stream.startpos,
+ stream.timeline);
stream.stream_stop = stop_streaming;
stream.stop_socket = PGINVALID_SOCKET;
@@ -446,9 +439,7 @@ StreamLog(void)
if (!stream.walmethod->finish())
{
- fprintf(stderr,
- _("%s: could not finish writing WAL files: %s\n"),
- progname, strerror(errno));
+ pg_log_info("could not finish writing WAL files: %m");
return;
}
@@ -508,6 +499,7 @@ main(int argc, char **argv)
uint32 hi,
lo;
+ pg_logging_init(argv[0]);
progname = get_progname(argv[0]);
set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("pg_basebackup"));
@@ -543,8 +535,7 @@ main(int argc, char **argv)
case 'p':
if (atoi(optarg) <= 0)
{
- fprintf(stderr, _("%s: invalid port number \"%s\"\n"),
- progname, optarg);
+ pg_log_error("invalid port number \"%s\"", optarg);
exit(1);
}
dbport = pg_strdup(optarg);
@@ -562,8 +553,7 @@ main(int argc, char **argv)
standby_message_timeout = atoi(optarg) * 1000;
if (standby_message_timeout < 0)
{
- fprintf(stderr, _("%s: invalid status interval \"%s\"\n"),
- progname, optarg);
+ pg_log_error("invalid status interval \"%s\"", optarg);
exit(1);
}
break;
@@ -573,9 +563,7 @@ main(int argc, char **argv)
case 'E':
if (sscanf(optarg, "%X/%X", &hi, &lo) != 2)
{
- fprintf(stderr,
- _("%s: could not parse end position \"%s\"\n"),
- progname, optarg);
+ pg_log_error("could not parse end position \"%s\"", optarg);
exit(1);
}
endpos = ((uint64) hi) << 32 | lo;
@@ -590,8 +578,7 @@ main(int argc, char **argv)
compresslevel = atoi(optarg);
if (compresslevel < 0 || compresslevel > 9)
{
- fprintf(stderr, _("%s: invalid compression level \"%s\"\n"),
- progname, optarg);
+ pg_log_error("invalid compression level \"%s\"", optarg);
exit(1);
}
break;
@@ -627,9 +614,8 @@ main(int argc, char **argv)
*/
if (optind < argc)
{
- fprintf(stderr,
- _("%s: too many command-line arguments (first is \"%s\")\n"),
- progname, argv[optind]);
+ pg_log_error("too many command-line arguments (first is \"%s\")",
+ argv[optind]);
fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
progname);
exit(1);
@@ -637,7 +623,7 @@ main(int argc, char **argv)
if (do_drop_slot && do_create_slot)
{
- fprintf(stderr, _("%s: cannot use --create-slot together with --drop-slot\n"), progname);
+ pg_log_error("cannot use --create-slot together with --drop-slot");
fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
progname);
exit(1);
@@ -646,7 +632,7 @@ main(int argc, char **argv)
if (replication_slot == NULL && (do_drop_slot || do_create_slot))
{
/* translator: second %s is an option name */
- fprintf(stderr, _("%s: %s needs a slot to be specified using --slot\n"), progname,
+ pg_log_error("%s needs a slot to be specified using --slot",
do_drop_slot ? "--drop-slot" : "--create-slot");
fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
progname);
@@ -655,7 +641,7 @@ main(int argc, char **argv)
if (synchronous && !do_sync)
{
- fprintf(stderr, _("%s: cannot use --synchronous together with --no-sync\n"), progname);
+ pg_log_error("cannot use --synchronous together with --no-sync");
fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
progname);
exit(1);
@@ -666,7 +652,7 @@ main(int argc, char **argv)
*/
if (basedir == NULL && !do_drop_slot && !do_create_slot)
{
- fprintf(stderr, _("%s: no target directory specified\n"), progname);
+ pg_log_error("no target directory specified");
fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
progname);
exit(1);
@@ -675,9 +661,7 @@ main(int argc, char **argv)
#ifndef HAVE_LIBZ
if (compresslevel != 0)
{
- fprintf(stderr,
- _("%s: this build does not support compression\n"),
- progname);
+ pg_log_error("this build does not support compression");
exit(1);
}
#endif
@@ -733,9 +717,8 @@ main(int argc, char **argv)
*/
if (db_name)
{
- fprintf(stderr,
- _("%s: replication connection using slot \"%s\" is unexpectedly database specific\n"),
- progname, replication_slot);
+ pg_log_error("replication connection using slot \"%s\" is unexpectedly database specific",
+ replication_slot);
exit(1);
}
@@ -745,9 +728,7 @@ main(int argc, char **argv)
if (do_drop_slot)
{
if (verbose)
- fprintf(stderr,
- _("%s: dropping replication slot \"%s\"\n"),
- progname, replication_slot);
+ pg_log_info("dropping replication slot \"%s\"", replication_slot);
if (!DropReplicationSlot(conn, replication_slot))
exit(1);
@@ -758,9 +739,7 @@ main(int argc, char **argv)
if (do_create_slot)
{
if (verbose)
- fprintf(stderr,
- _("%s: creating replication slot \"%s\"\n"),
- progname, replication_slot);
+ pg_log_info("creating replication slot \"%s\"", replication_slot);
if (!CreateReplicationSlot(conn, replication_slot, NULL, false, true, false,
slot_exists_ok))
@@ -786,15 +765,14 @@ main(int argc, char **argv)
}
else if (noloop)
{
- fprintf(stderr, _("%s: disconnected\n"), progname);
+ pg_log_error("disconnected");
exit(1);
}
else
{
- fprintf(stderr,
/* translator: check source for value for %d */
- _("%s: disconnected; waiting %d seconds to try again\n"),
- progname, RECONNECT_SLEEP_TIME);
+ pg_log_info("disconnected; waiting %d seconds to try again",
+ RECONNECT_SLEEP_TIME);
pg_usleep(RECONNECT_SLEEP_TIME * 1000000);
}
}