Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit c900c15

Browse files
committed
Warn more strongly about the dangers of exclusive backup mode.
Especially, warn about the hazards of mishandling the backup_label file. Adjust a couple of server messages to be more clear about the hazards associated with removing backup_label files, too. David Steele and Robert Haas, reviewed by Laurenz Albe, Martín Marqués, Peter Eisentraut, and Magnus Hagander. Discussion: http://postgr.es/m/7d85c387-000e-16f0-e00b-50bf83c22127@pgmasters.net
1 parent bb76134 commit c900c15

File tree

2 files changed

+47
-15
lines changed

2 files changed

+47
-15
lines changed

doc/src/sgml/backup.sgml

+39-13
Original file line numberDiff line numberDiff line change
@@ -948,13 +948,26 @@ SELECT * FROM pg_stop_backup(false, true);
948948
</sect3>
949949
<sect3 id="backup-lowlevel-base-backup-exclusive">
950950
<title>Making an exclusive low level backup</title>
951+
952+
<note>
953+
<para>
954+
The exclusive backup method is deprecated and should be avoided.
955+
Prior to <productname>PostgreSQL</productname> 9.6, this was the only
956+
low-level method available, but it is now recommended that all users
957+
upgrade their scripts to use non-exclusive backups.
958+
</para>
959+
</note>
960+
951961
<para>
952962
The process for an exclusive backup is mostly the same as for a
953-
non-exclusive one, but it differs in a few key steps. This type of backup
954-
can only be taken on a primary and does not allow concurrent backups.
955-
Prior to <productname>PostgreSQL</productname> 9.6, this
956-
was the only low-level method available, but it is now recommended that
957-
all users upgrade their scripts to use non-exclusive backups if possible.
963+
non-exclusive one, but it differs in a few key steps. This type of
964+
backup can only be taken on a primary and does not allow concurrent
965+
backups. Moreover, because it writes a backup_label file on the
966+
master, it can cause the master to fail to restart automatically after
967+
a crash. On the other hand, the erroneous removal of a backup_label
968+
file from a backup or standby is a common mistake which can can result
969+
in serious data corruption. If it is necessary to use this method,
970+
the following steps may be used.
958971
</para>
959972
<para>
960973
<orderedlist>
@@ -1011,9 +1024,17 @@ SELECT pg_start_backup('label', true);
10111024
consider during this backup.
10121025
</para>
10131026
<para>
1014-
Note that if the server crashes during the backup it may not be
1015-
possible to restart until the <literal>backup_label</literal> file has been
1016-
manually deleted from the <envar>PGDATA</envar> directory.
1027+
As noted above, if the server crashes during the backup it may not be
1028+
possible to restart until the <literal>backup_label</literal> file has
1029+
been manually deleted from the <envar>PGDATA</envar> directory. Note
1030+
that it is very important to never remove the
1031+
<literal>backup_label</literal> file when restoring a backup, because
1032+
this will result in corruption. Confusion about when it is appropriate
1033+
to remove this file is a common cause of data corruption when using this
1034+
method; be very certain that you remove the file only on an existing
1035+
master and never when building a standby or restoring a backup, even if
1036+
you are building a standby that will subsequently be promoted to a new
1037+
master.
10171038
</para>
10181039
</listitem>
10191040
<listitem>
@@ -1045,11 +1066,16 @@ SELECT pg_stop_backup();
10451066
If the archive process has fallen behind
10461067
because of failures of the archive command, it will keep retrying
10471068
until the archive succeeds and the backup is complete.
1048-
If you wish to place a time limit on the execution of
1049-
<function>pg_stop_backup</function>, set an appropriate
1050-
<varname>statement_timeout</varname> value, but make note that if
1051-
<function>pg_stop_backup</function> terminates because of this your backup
1052-
may not be valid.
1069+
</para>
1070+
1071+
<para>
1072+
When using exclusive backup mode, it is absolutely imperative to ensure
1073+
that <function>pg_stop_backup</function> completes successfully at the
1074+
end of the backup. Even if the backup itself fails, for example due to
1075+
lack of disk space, failure to call <function>pg_stop_backup</function>
1076+
will leave the server in backup mode indefinitely, causing future backups
1077+
to fail and increasing the risk of a restart failure during the time that
1078+
<literal>backup_label</literal> exists.
10531079
</para>
10541080
</listitem>
10551081
</orderedlist>

src/backend/access/transam/xlog.c

+8-2
Original file line numberDiff line numberDiff line change
@@ -6364,14 +6364,20 @@ StartupXLOG(void)
63646364
if (!ReadRecord(xlogreader, checkPoint.redo, LOG, false))
63656365
ereport(FATAL,
63666366
(errmsg("could not find redo location referenced by checkpoint record"),
6367-
errhint("If you are not restoring from a backup, try removing the file \"%s/backup_label\".", DataDir)));
6367+
errhint("If you are restoring from a backup, touch \"%s/recovery.signal\" and add required recovery options.\n"
6368+
"If you are not restoring from a backup, try removing the file \"%s/backup_label\".\n"
6369+
"Be careful: removing \"%s/backup_label\" will result in a corrupt cluster if restoring from a backup.",
6370+
DataDir, DataDir, DataDir)));
63686371
}
63696372
}
63706373
else
63716374
{
63726375
ereport(FATAL,
63736376
(errmsg("could not locate required checkpoint record"),
6374-
errhint("If you are not restoring from a backup, try removing the file \"%s/backup_label\".", DataDir)));
6377+
errhint("If you are restoring from a backup, touch \"%s/recovery.signal\" and add required recovery options.\n"
6378+
"If you are not restoring from a backup, try removing the file \"%s/backup_label\".\n"
6379+
"Be careful: removing \"%s/backup_label\" will result in a corrupt cluster if restoring from a backup.",
6380+
DataDir, DataDir, DataDir)));
63756381
wasShutdown = false; /* keep compiler quiet */
63766382
}
63776383

0 commit comments

Comments
 (0)