Commit 06e8c8e3 authored by Heikki Linnakangas's avatar Heikki Linnakangas

Don't warn about an in-progress online backup, when we're recovering from

an online backup instead of performing one. pg_ctl can detect that by
checking if recovery.conf exists.

Backup label file is renamed away early in recovery, so the window where
backup label exists during recovery is normally very small, but you can run
into it e.g if restore_command is set incorrectly and the startup process
never finds even the first WAL segment containing the checkpoint record to
start recovery from.

Fujii Masao with comments by me.
parent c1ba7db6
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
* *
* Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
* *
* $PostgreSQL: pgsql/src/bin/pg_ctl/pg_ctl.c,v 1.122 2010/04/07 03:48:51 itagaki Exp $ * $PostgreSQL: pgsql/src/bin/pg_ctl/pg_ctl.c,v 1.123 2010/09/14 08:05:33 heikki Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -142,6 +142,7 @@ static char postopts_file[MAXPGPATH]; ...@@ -142,6 +142,7 @@ static char postopts_file[MAXPGPATH];
static char pid_file[MAXPGPATH]; static char pid_file[MAXPGPATH];
static char conf_file[MAXPGPATH]; static char conf_file[MAXPGPATH];
static char backup_file[MAXPGPATH]; static char backup_file[MAXPGPATH];
static char recovery_file[MAXPGPATH];
#if defined(HAVE_GETRLIMIT) && defined(RLIMIT_CORE) #if defined(HAVE_GETRLIMIT) && defined(RLIMIT_CORE)
static void unlimit_core_size(void); static void unlimit_core_size(void);
...@@ -802,7 +803,15 @@ do_stop(void) ...@@ -802,7 +803,15 @@ do_stop(void)
} }
else else
{ {
if ((shutdown_mode == SMART_MODE) && (stat(backup_file, &statbuf) == 0)) /*
* If backup_label exists, an online backup is running. Warn the
* user that smart shutdown will wait for it to finish. However, if
* recovery.conf is also present, we're recovering from an online
* backup instead of performing one.
*/
if (shutdown_mode == SMART_MODE &&
stat(backup_file, &statbuf) == 0 &&
stat(recovery_file, &statbuf) != 0)
{ {
print_msg(_("WARNING: online backup mode is active\n" print_msg(_("WARNING: online backup mode is active\n"
"Shutdown will not complete until pg_stop_backup() is called.\n\n")); "Shutdown will not complete until pg_stop_backup() is called.\n\n"));
...@@ -879,7 +888,15 @@ do_restart(void) ...@@ -879,7 +888,15 @@ do_restart(void)
exit(1); exit(1);
} }
if ((shutdown_mode == SMART_MODE) && (stat(backup_file, &statbuf) == 0)) /*
* If backup_label exists, an online backup is running. Warn the
* user that smart shutdown will wait for it to finish. However, if
* recovery.conf is also present, we're recovering from an online
* backup instead of performing one.
*/
if (shutdown_mode == SMART_MODE &&
stat(backup_file, &statbuf) == 0 &&
stat(recovery_file, &statbuf) != 0)
{ {
print_msg(_("WARNING: online backup mode is active\n" print_msg(_("WARNING: online backup mode is active\n"
"Shutdown will not complete until pg_stop_backup() is called.\n\n")); "Shutdown will not complete until pg_stop_backup() is called.\n\n"));
...@@ -1962,6 +1979,7 @@ main(int argc, char **argv) ...@@ -1962,6 +1979,7 @@ main(int argc, char **argv)
snprintf(pid_file, MAXPGPATH, "%s/postmaster.pid", pg_data); snprintf(pid_file, MAXPGPATH, "%s/postmaster.pid", pg_data);
snprintf(conf_file, MAXPGPATH, "%s/postgresql.conf", pg_data); snprintf(conf_file, MAXPGPATH, "%s/postgresql.conf", pg_data);
snprintf(backup_file, MAXPGPATH, "%s/backup_label", pg_data); snprintf(backup_file, MAXPGPATH, "%s/backup_label", pg_data);
snprintf(recovery_file, MAXPGPATH, "%s/recovery.conf", pg_data);
} }
switch (ctl_command) switch (ctl_command)
......
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