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

Commit 205db01

Browse files
committed
pg_combinebackup: Detect checksum mismatches and document limitation.
If not all backups have the same checksum status, but the final backup has checksums enabled, then the output directory may include pages with invalid checksums. Document this limitation and explain how to work around it. In a future release, we may want to teach pg_combinebackup to recompute page checksums when required, but as feature freeze has come and gone, it seems a bit too late to do that for this release. Patch by me, reviewed by Daniel Gustafsson Discussion: http://postgr.es/m/CA+TgmoZugzOSmgkx97u3pc0M7U8LycWvugqoyWBv6j15a4hE5g@mail.gmail.com
1 parent 6d4bc96 commit 205db01

File tree

3 files changed

+47
-1
lines changed

3 files changed

+47
-1
lines changed

doc/src/sgml/backup.sgml

+5-1
Original file line numberDiff line numberDiff line change
@@ -892,7 +892,11 @@ test ! -f /mnt/server/archivedir/00000001000000A900000065 && cp pg_wal/0
892892
only the incremental backup itself but also all earlier backups that
893893
are required to supply the blocks omitted from the incremental backup.
894894
See <xref linkend="app-pgcombinebackup"/> for further information about
895-
this requirement.
895+
this requirement. Note that there are restrictions on the use of
896+
<literal>pg_combinebackup</literal> when the checksum status of the
897+
cluster has been changed; see
898+
<link linkend="app-pgcombinebackup-limitations">pg_combinebackup
899+
limitations</link>.
896900
</para>
897901

898902
<para>

doc/src/sgml/ref/pg_combinebackup.sgml

+20
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,26 @@ PostgreSQL documentation
261261

262262
</refsect1>
263263

264+
<refsect1 id="app-pgcombinebackup-limitations">
265+
<title>Limitations</title>
266+
267+
<para>
268+
<literal>pg_combinebackup</literal> does not recompute page checksums when
269+
writing the output directory. Therefore, if any of the backups used for
270+
reconstruction were taken with checksums disabled, but the final backup was
271+
taken with checksums enabled, the resulting directory may contain pages
272+
with invalid checksums.
273+
</para>
274+
275+
<para>
276+
To avoid this problem, taking a new full backup after changing the checksum
277+
state of the cluster using <xref linkend="app-pgchecksums "/> is
278+
recommended. Otherwise, you can disable and then optionally reenable
279+
checksums on the directory produced by <literal>pg_combinebackup</literal>
280+
in order to correct the problem.
281+
</para>
282+
</refsect1>
283+
264284
<refsect1>
265285
<title>Environment</title>
266286

src/bin/pg_combinebackup/pg_combinebackup.c

+22
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,8 @@ check_control_files(int n_backups, char **backup_dirs)
583583
{
584584
int i;
585585
uint64 system_identifier = 0; /* placate compiler */
586+
uint32 data_checksum_version = 0; /* placate compiler */
587+
bool data_checksum_mismatch = false;
586588

587589
/* Try to read each control file in turn, last to first. */
588590
for (i = n_backups - 1; i >= 0; --i)
@@ -612,6 +614,16 @@ check_control_files(int n_backups, char **backup_dirs)
612614
controlpath, (unsigned long long) system_identifier,
613615
(unsigned long long) control_file->system_identifier);
614616

617+
/*
618+
* Detect checksum mismatches, but only if the last backup in the
619+
* chain has checksums enabled.
620+
*/
621+
if (i == n_backups - 1)
622+
data_checksum_version = control_file->data_checksum_version;
623+
else if (data_checksum_version != 0 &&
624+
data_checksum_version != control_file->data_checksum_version)
625+
data_checksum_mismatch = true;
626+
615627
/* Release memory. */
616628
pfree(control_file);
617629
pfree(controlpath);
@@ -624,6 +636,16 @@ check_control_files(int n_backups, char **backup_dirs)
624636
pg_log_debug("system identifier is %llu",
625637
(unsigned long long) system_identifier);
626638

639+
/*
640+
* Warn the user if not all backups are in the same state with regards to
641+
* checksums.
642+
*/
643+
if (data_checksum_mismatch)
644+
{
645+
pg_log_warning("only some backups have checksums enabled");
646+
pg_log_warning_hint("disable, and optionally reenable, checksums on the output directory to avoid failures");
647+
}
648+
627649
return system_identifier;
628650
}
629651

0 commit comments

Comments
 (0)