Pre-beta mechanical code beautification.
[pgsql.git] / src / bin / pg_combinebackup / t / 006_db_file_copy.pl
blobd57b550af2134d15ee91060fde934707b2b94049
1 # Copyright (c) 2021-2024, PostgreSQL Global Development Group
3 use strict;
4 use warnings FATAL => 'all';
5 use File::Compare;
6 use PostgreSQL::Test::Cluster;
7 use PostgreSQL::Test::Utils;
8 use Test::More;
10 # Set up a new database instance.
11 my $primary = PostgreSQL::Test::Cluster->new('primary');
12 $primary->init(has_archiving => 1, allows_streaming => 1);
13 $primary->append_conf('postgresql.conf', 'summarize_wal = on');
14 $primary->start;
16 # Initial setup.
17 $primary->safe_psql('postgres', <<EOM);
18 CREATE DATABASE lakh OID = 100000 STRATEGY = FILE_COPY
19 EOM
20 $primary->safe_psql('lakh', <<EOM);
21 CREATE TABLE t1 (a int)
22 EOM
24 # Take a full backup.
25 my $backup1path = $primary->backup_dir . '/backup1';
26 $primary->command_ok(
27 [ 'pg_basebackup', '-D', $backup1path, '--no-sync', '-cfast' ],
28 "full backup");
30 # Now make some database changes.
31 $primary->safe_psql('postgres', <<EOM);
32 DROP DATABASE lakh;
33 CREATE DATABASE lakh OID = 100000 STRATEGY = FILE_COPY
34 EOM
36 # Take an incremental backup.
37 my $backup2path = $primary->backup_dir . '/backup2';
38 $primary->command_ok(
40 'pg_basebackup', '-D', $backup2path, '--no-sync', '-cfast',
41 '--incremental', $backup1path . '/backup_manifest'
43 "incremental backup");
45 # Recover the incremental backup.
46 my $restore = PostgreSQL::Test::Cluster->new('restore');
47 $restore->init_from_backup($primary, 'backup2',
48 combine_with_prior => ['backup1']);
49 $restore->start();
51 # Query the DB.
52 my $stdout;
53 my $stderr;
54 $restore->psql(
55 'lakh', 'SELECT * FROM t1',
56 stdout => \$stdout,
57 stderr => \$stderr);
58 is($stdout, '', 'SELECT * FROM t1: no stdout');
59 like(
60 $stderr,
61 qr/relation "t1" does not exist/,
62 'SELECT * FROM t1: stderr missing table');
64 done_testing();