|
7 | 7 | use PostgreSQL::Test::Utils; |
8 | 8 | use Test::More; |
9 | 9 |
|
| 10 | +my $tempdir = PostgreSQL::Test::Utils::tempdir; |
| 11 | + |
10 | 12 | # Set up a new database instance. |
11 | 13 | my $primary = PostgreSQL::Test::Cluster->new('primary'); |
12 | 14 | $primary->init(has_archiving => 1, allows_streaming => 1); |
13 | 15 | $primary->append_conf('postgresql.conf', 'summarize_wal = on'); |
14 | 16 | $primary->start; |
| 17 | +my $tsprimary = $tempdir . '/ts'; |
| 18 | +mkdir($tsprimary) || die "mkdir $tsprimary: $!"; |
15 | 19 |
|
16 | 20 | # Create some test tables, each containing one row of data, plus a whole |
17 | 21 | # extra database. |
|
29 | 33 | CREATE TABLE will_get_rewritten (a int, b text); |
30 | 34 | INSERT INTO will_get_rewritten VALUES (1, 'initial test row'); |
31 | 35 | CREATE DATABASE db_will_get_dropped; |
| 36 | +CREATE TABLESPACE ts1 LOCATION '$tsprimary'; |
| 37 | +CREATE TABLE will_not_change_in_ts (a int, b text) TABLESPACE ts1; |
| 38 | +INSERT INTO will_not_change_in_ts VALUES (1, 'initial test row'); |
| 39 | +CREATE TABLE will_change_in_ts (a int, b text) TABLESPACE ts1; |
| 40 | +INSERT INTO will_change_in_ts VALUES (1, 'initial test row'); |
| 41 | +CREATE TABLE will_get_dropped_in_ts (a int, b text); |
| 42 | +INSERT INTO will_get_dropped_in_ts VALUES (1, 'initial test row'); |
32 | 43 | EOM |
33 | 44 |
|
34 | 45 | # Take a full backup. |
35 | 46 | my $backup1path = $primary->backup_dir . '/backup1'; |
| 47 | +my $tsbackup1path = $tempdir . '/ts1backup'; |
| 48 | +mkdir($tsbackup1path) || die "mkdir $tsbackup1path: $!"; |
36 | 49 | $primary->command_ok( |
37 | | - [ 'pg_basebackup', '-D', $backup1path, '--no-sync', '-cfast' ], |
38 | | - "full backup"); |
| 50 | + [ 'pg_basebackup', '-D', $backup1path, '--no-sync', '-cfast', |
| 51 | + "-T${tsprimary}=${tsbackup1path}" ], "full backup"); |
39 | 52 |
|
40 | 53 | # Now make some database changes. |
41 | 54 | $primary->safe_psql('postgres', <<EOM); |
42 | 55 | UPDATE will_change SET b = 'modified value' WHERE a = 1; |
| 56 | +UPDATE will_change_in_ts SET b = 'modified value' WHERE a = 1; |
43 | 57 | INSERT INTO will_grow |
44 | 58 | SELECT g, 'additional row' FROM generate_series(2, 5000) g; |
45 | 59 | TRUNCATE will_shrink; |
46 | 60 | VACUUM will_get_vacuumed; |
47 | 61 | DROP TABLE will_get_dropped; |
| 62 | +DROP TABLE will_get_dropped_in_ts; |
48 | 63 | CREATE TABLE newly_created (a int, b text); |
49 | 64 | INSERT INTO newly_created VALUES (1, 'row for new table'); |
| 65 | +CREATE TABLE newly_created_in_ts (a int, b text) TABLESPACE ts1; |
| 66 | +INSERT INTO newly_created_in_ts VALUES (1, 'row for new table'); |
50 | 67 | VACUUM FULL will_get_rewritten; |
51 | 68 | DROP DATABASE db_will_get_dropped; |
52 | 69 | CREATE DATABASE db_newly_created; |
53 | 70 | EOM |
54 | 71 |
|
55 | 72 | # Take an incremental backup. |
56 | 73 | my $backup2path = $primary->backup_dir . '/backup2'; |
| 74 | +my $tsbackup2path = $tempdir . '/tsbackup2'; |
| 75 | +mkdir($tsbackup2path) || die "mkdir $tsbackup2path: $!"; |
57 | 76 | $primary->command_ok( |
58 | 77 | [ 'pg_basebackup', '-D', $backup2path, '--no-sync', '-cfast', |
| 78 | + "-T${tsprimary}=${tsbackup2path}", |
59 | 79 | '--incremental', $backup1path . '/backup_manifest' ], |
60 | 80 | "incremental backup"); |
61 | 81 |
|
|
78 | 98 | # Perform PITR from the full backup. Disable archive_mode so that the archive |
79 | 99 | # doesn't find out about the new timeline; that way, the later PITR below will |
80 | 100 | # choose the same timeline. |
| 101 | +my $tspitr1path = $tempdir . '/tspitr1'; |
81 | 102 | my $pitr1 = PostgreSQL::Test::Cluster->new('pitr1'); |
82 | 103 | $pitr1->init_from_backup($primary, 'backup1', |
83 | | - standby => 1, has_restoring => 1); |
| 104 | + standby => 1, has_restoring => 1, |
| 105 | + tablespace_map => { $tsbackup1path => $tspitr1path }); |
84 | 106 | $pitr1->append_conf('postgresql.conf', qq{ |
85 | 107 | recovery_target_lsn = '$lsn' |
86 | 108 | recovery_target_action = 'promote' |
|
90 | 112 |
|
91 | 113 | # Perform PITR to the same LSN from the incremental backup. Use the same |
92 | 114 | # basic configuration as before. |
| 115 | +my $tspitr2path = $tempdir . '/tspitr2'; |
93 | 116 | my $pitr2 = PostgreSQL::Test::Cluster->new('pitr2'); |
94 | 117 | $pitr2->init_from_backup($primary, 'backup2', |
95 | 118 | standby => 1, has_restoring => 1, |
96 | | - combine_with_prior => [ 'backup1' ]); |
| 119 | + combine_with_prior => [ 'backup1' ], |
| 120 | + tablespace_map => { $tsbackup2path => $tspitr2path }); |
97 | 121 | $pitr2->append_conf('postgresql.conf', qq{ |
98 | 122 | recovery_target_lsn = '$lsn' |
99 | 123 | recovery_target_action = 'promote' |
|
0 commit comments