mirror of https://github.com/postgres/postgres
To do this, we must include the wal_level in the first WAL record covered by each summary file; so add wal_level to struct Checkpoint and the payload of XLOG_CHECKPOINT_REDO and XLOG_END_OF_RECOVERY. This, in turn, requires bumping XLOG_PAGE_MAGIC and, since the Checkpoint is also stored in the control file, also PG_CONTROL_VERSION. It's not great to do that so late in the release cycle, but the alternative seems to ship v17 without robust protections against this scenario, which could result in corrupted incremental backups. A side effect of this patch is that, when a server with wal_level=replica is started with summarize_wal=on for the first time, summarization will no longer begin with the oldest WAL that still exists in pg_wal, but rather from the first checkpoint after that. This change should be harmless, because a WAL summary for a partial checkpoint cycle can never make an incremental backup possible when it would otherwise not have been. Report by Fujii Masao. Patch by me. Review and/or testing by Jakub Wartak and Fujii Masao. Discussion: http://postgr.es/m/6e30082e-041b-4e31-9633-95a66de76f5d@oss.nttdata.compull/183/head
parent
4cbd8c6022
commit
2b5819e2b4
@ -0,0 +1,73 @@ |
|||||||
|
# Copyright (c) 2021-2024, PostgreSQL Global Development Group |
||||||
|
# |
||||||
|
# This test aims to validate that taking an incremental backup fails when |
||||||
|
# wal_level has been changed to minimal between the full backup and the |
||||||
|
# attempted incremental backup. |
||||||
|
|
||||||
|
use strict; |
||||||
|
use warnings FATAL => 'all'; |
||||||
|
use File::Compare; |
||||||
|
use PostgreSQL::Test::Cluster; |
||||||
|
use PostgreSQL::Test::Utils; |
||||||
|
use Test::More; |
||||||
|
|
||||||
|
# Can be changed to test the other modes. |
||||||
|
my $mode = $ENV{PG_TEST_PG_COMBINEBACKUP_MODE} || '--copy'; |
||||||
|
|
||||||
|
note "testing using mode $mode"; |
||||||
|
|
||||||
|
# Set up a new database instance. |
||||||
|
my $node1 = PostgreSQL::Test::Cluster->new('node1'); |
||||||
|
$node1->init(allows_streaming => 1); |
||||||
|
$node1->append_conf('postgresql.conf', <<EOM); |
||||||
|
summarize_wal = on |
||||||
|
wal_keep_size = '1GB' |
||||||
|
EOM |
||||||
|
$node1->start; |
||||||
|
|
||||||
|
# Create a table and insert a test row into it. |
||||||
|
$node1->safe_psql('postgres', <<EOM); |
||||||
|
CREATE TABLE mytable (a int, b text); |
||||||
|
INSERT INTO mytable VALUES (1, 'finch'); |
||||||
|
EOM |
||||||
|
|
||||||
|
# Take a full backup. |
||||||
|
my $backup1path = $node1->backup_dir . '/backup1'; |
||||||
|
$node1->command_ok( |
||||||
|
[ 'pg_basebackup', '-D', $backup1path, '--no-sync', '-cfast' ], |
||||||
|
"full backup"); |
||||||
|
|
||||||
|
# Switch to wal_level=minimal, which also requires max_wal_senders=0 and |
||||||
|
# summarize_wal=off |
||||||
|
$node1->safe_psql('postgres', <<EOM); |
||||||
|
ALTER SYSTEM SET wal_level = minimal; |
||||||
|
ALTER SYSTEM SET max_wal_senders = 0; |
||||||
|
ALTER SYSTEM SET summarize_wal = off; |
||||||
|
EOM |
||||||
|
$node1->restart; |
||||||
|
|
||||||
|
# Insert a second row on the original node. |
||||||
|
$node1->safe_psql('postgres', <<EOM); |
||||||
|
INSERT INTO mytable VALUES (2, 'gerbil'); |
||||||
|
EOM |
||||||
|
|
||||||
|
# Revert configuration changes |
||||||
|
$node1->safe_psql('postgres', <<EOM); |
||||||
|
ALTER SYSTEM RESET wal_level; |
||||||
|
ALTER SYSTEM RESET max_wal_senders; |
||||||
|
ALTER SYSTEM RESET summarize_wal; |
||||||
|
EOM |
||||||
|
$node1->restart; |
||||||
|
|
||||||
|
# Now take an incremental backup. |
||||||
|
my $backup2path = $node1->backup_dir . '/backup2'; |
||||||
|
$node1->command_fails_like( |
||||||
|
[ |
||||||
|
'pg_basebackup', '-D', $backup2path, '--no-sync', '-cfast', |
||||||
|
'--incremental', $backup1path . '/backup_manifest' |
||||||
|
], |
||||||
|
qr/WAL summaries are required on timeline 1 from.*are incomplete/, |
||||||
|
"incremental backup fails"); |
||||||
|
|
||||||
|
# OK, that's all. |
||||||
|
done_testing(); |
Loading…
Reference in new issue