diff --git a/contrib/pg_standby/pg_standby.c b/contrib/pg_standby/pg_standby.c index 97b6482..d9cb118 100644 --- a/contrib/pg_standby/pg_standby.c +++ b/contrib/pg_standby/pg_standby.c @@ -53,6 +53,7 @@ int maxwaittime = 0; /* how long are we prepared to wait for? */ int keepfiles = 0; /* number of WAL files to keep, 0 keep all */ int maxretries = 3; /* number of retries on restore command */ bool debug = false; /* are we debugging? */ +bool progress = true; /* are we reporting progress? */ bool need_cleanup = false; /* do we need to remove files from * archive? */ @@ -480,21 +481,18 @@ RestoreWALFileForRecovery(void) int rc = 0; int numretries = 0; - if (debug) - { - fprintf(stderr, "running restore :"); - fflush(stderr); - } + if (progress) + fprintf(stdout, "Running restore :"); while (numretries <= maxretries) { rc = system(restoreCommand); if (rc == 0) { - if (debug) + if (progress) { - fprintf(stderr, " OK\n"); - fflush(stderr); + fprintf(stdout, " OK\n"); + fflush(stdout); } return true; } @@ -504,8 +502,8 @@ RestoreWALFileForRecovery(void) /* * Allow caller to add additional info */ - if (debug) - fprintf(stderr, "not restored\n"); + if (progress) + fprintf(stdout, " not restored\n"); return false; } @@ -522,10 +520,11 @@ usage(void) " restore_command = 'pg_standby -l /mnt/server/archiverdir %%f %%p %%r'\n"); printf("\nOptions:\n"); printf(" -c copies file from archive (default)\n"); - printf(" -d generate lots of debugging output (testing only)\n"); + printf(" -d generate lots of debugging output (testing only, to STDERR)\n"); printf(" -k NUMFILESTOKEEP if RESTARTWALFILE not used, removes files prior to limit\n" " (0 keeps all)\n"); printf(" -l does nothing; use of link is now deprecated\n"); + printf(" -p report progress of replay activity (to STDOUT)\n"); printf(" -r MAXRETRIES max number of times to retry, with progressive wait\n" " (default=3)\n"); printf(" -s SLEEPTIME seconds to wait between file checks (min=1, max=60,\n" @@ -623,6 +622,9 @@ main(int argc, char **argv) restoreCommandType = RESTORE_COMMAND_LINK; #endif break; + case 'p': /* Report Progress mode */ + progress = true; + break; case 'r': /* Retries */ maxretries = atoi(optarg); if (maxretries < 0) @@ -718,23 +720,23 @@ main(int argc, char **argv) need_cleanup = SetWALFileNameForCleanup(); - if (debug) + if (progress) { - fprintf(stderr, "Trigger file : %s\n", triggerPath ? triggerPath : ""); - fprintf(stderr, "Waiting for WAL file : %s\n", nextWALFileName); - fprintf(stderr, "WAL file path : %s\n", WALFilePath); - fprintf(stderr, "Restoring to : %s\n", xlogFilePath); - fprintf(stderr, "Sleep interval : %d second%s\n", + fprintf(stdout, "Trigger file : %s\n", triggerPath ? triggerPath : ""); + fprintf(stdout, "Waiting for WAL file : %s\n", nextWALFileName); + fprintf(stdout, "WAL file path : %s\n", WALFilePath); + fprintf(stdout, "Restoring to : %s\n", xlogFilePath); + fprintf(stdout, "Sleep interval : %d second%s\n", sleeptime, (sleeptime > 1 ? "s" : " ")); - fprintf(stderr, "Max wait interval : %d %s\n", + fprintf(stdout, "Max wait interval : %d %s\n", maxwaittime, (maxwaittime > 0 ? "seconds" : "forever")); - fprintf(stderr, "Command for restore : %s\n", restoreCommand); - fprintf(stderr, "Keep archive history : "); + fprintf(stdout, "Command for restore : %s\n", restoreCommand); + fprintf(stdout, "Keep archive history : "); if (need_cleanup) - fprintf(stderr, "%s and later\n", exclusiveCleanupFileName); + fprintf(stdout, "%s and later\n", exclusiveCleanupFileName); else - fprintf(stderr, "No cleanup required\n"); - fflush(stderr); + fprintf(stdout, "No cleanup required\n"); + fflush(stdout); } /* @@ -747,6 +749,16 @@ main(int argc, char **argv) ".history") == 0) { nextWALFileType = XLOG_HISTORY; + /* error is ENOENT */ + if (stat(nextWALFileName, &stat_buf) != 0) { + if (debug) + { + fprintf(stderr, "stat for history file failed (probably ok)\n"); + fflush(stderr); + } + exit(1); + } + if (RestoreWALFileForRecovery()) exit(0); else