| 1 |
# Copyright (c) 2021-2025, PostgreSQL Global Development Group |
| 2 |
# |
| 3 |
# This test aims to validate that taking an incremental backup fails when |
| 4 |
# wal_level has been changed to minimal between the full backup and the |
| 5 |
# attempted incremental backup. |
| 6 |
|
| 7 |
use strict; |
| 8 |
use warnings FATAL => 'all'; |
| 9 |
use File::Compare; |
| 10 |
use PostgreSQL::Test::Cluster; |
| 11 |
use PostgreSQL::Test::Utils; |
| 12 |
use Test::More; |
| 13 |
|
| 14 |
# Can be changed to test the other modes. |
| 15 |
my $mode = $ENV{PG_TEST_PG_COMBINEBACKUP_MODE} || '--copy'; |
| 16 |
|
| 17 |
note "testing using mode $mode"; |
| 18 |
|
| 19 |
# Set up a new database instance. |
| 20 |
my $node1 = PostgreSQL::Test::Cluster->new('node1'); |
| 21 |
$node1->init(allows_streaming => 1); |
| 22 |
$node1->append_conf('postgresql.conf', <<EOM); |
| 23 |
summarize_wal = on |
| 24 |
wal_keep_size = '1GB' |
| 25 |
EOM |
| 26 |
$node1->start; |
| 27 |
|
| 28 |
# Create a table and insert a test row into it. |
| 29 |
$node1->safe_psql('postgres', <<EOM); |
| 30 |
CREATE TABLE mytable (a int, b text); |
| 31 |
INSERT INTO mytable VALUES (1, 'finch'); |
| 32 |
EOM |
| 33 |
|
| 34 |
# Take a full backup. |
| 35 |
my $backup1path = $node1->backup_dir . '/backup1'; |
| 36 |
$node1->command_ok( |
| 37 |
[ |
| 38 |
'pg_basebackup', |
| 39 |
'--pgdata' => $backup1path, |
| 40 |
'--no-sync', |
| 41 |
'--checkpoint' => 'fast' |
| 42 |
], |
| 43 |
"full backup"); |
| 44 |
|
| 45 |
# Switch to wal_level=minimal, which also requires max_wal_senders=0 and |
| 46 |
# summarize_wal=off |
| 47 |
$node1->safe_psql('postgres', <<EOM); |
| 48 |
ALTER SYSTEM SET wal_level = minimal; |
| 49 |
ALTER SYSTEM SET max_wal_senders = 0; |
| 50 |
ALTER SYSTEM SET summarize_wal = off; |
| 51 |
EOM |
| 52 |
$node1->restart; |
| 53 |
|
| 54 |
# Insert a second row on the original node. |
| 55 |
$node1->safe_psql('postgres', <<EOM); |
| 56 |
INSERT INTO mytable VALUES (2, 'gerbil'); |
| 57 |
EOM |
| 58 |
|
| 59 |
# Revert configuration changes |
| 60 |
$node1->safe_psql('postgres', <<EOM); |
| 61 |
ALTER SYSTEM RESET wal_level; |
| 62 |
ALTER SYSTEM RESET max_wal_senders; |
| 63 |
ALTER SYSTEM RESET summarize_wal; |
| 64 |
EOM |
| 65 |
$node1->restart; |
| 66 |
|
| 67 |
# Now take an incremental backup. |
| 68 |
my $backup2path = $node1->backup_dir . '/backup2'; |
| 69 |
$node1->command_fails_like( |
| 70 |
[ |
| 71 |
'pg_basebackup', |
| 72 |
'--pgdata' => $backup2path, |
| 73 |
'--no-sync', |
| 74 |
'--checkpoint' => 'fast', |
| 75 |
'--incremental' => $backup1path . '/backup_manifest' |
| 76 |
], |
| 77 |
qr/WAL summaries are required on timeline 1 from.*are incomplete/, |
| 78 |
"incremental backup fails"); |
| 79 |
|
| 80 |
# OK, that's all. |
| 81 |
done_testing(); |