|
37 | 37 | "SELECT pg_tde_set_server_key_using_global_key_provider('server-key', 'keyring');"
|
38 | 38 | );
|
39 | 39 |
|
| 40 | +# This is a quite ugly dance to make sure we have a replica starting in a stats |
| 41 | +# with encrypted WAL and without. We do this by taking a base backup while |
| 42 | +# encryption is disabled and one where it is enabled. |
| 43 | +# |
| 44 | +# We also generate some plaintext WAL and some ecrnypted WAL. |
| 45 | + |
| 46 | +$primary->backup('plain_wal', backup_options => [ '-X', 'none' ]); |
| 47 | + |
40 | 48 | $primary->append_conf('postgresql.conf', "pg_tde.wal_encrypt = on");
|
41 | 49 |
|
42 |
| -$primary->backup('backup', backup_options => [ '-X', 'none' ]); |
| 50 | +$primary->restart; |
| 51 | + |
| 52 | +$primary->backup('enc_wal', backup_options => [ '-X', 'none' ]); |
| 53 | + |
| 54 | +$primary->append_conf('postgresql.conf', "pg_tde.wal_encrypt = off"); |
| 55 | + |
| 56 | +$primary->restart; |
| 57 | + |
| 58 | +$primary->append_conf('postgresql.conf', "pg_tde.wal_encrypt = on"); |
43 | 59 |
|
44 | 60 | $primary->safe_psql('postgres',
|
45 | 61 | "CREATE TABLE t1 AS SELECT 'foobar_plain' AS x");
|
|
71 | 87 | qr/foobar_enc/,
|
72 | 88 | 'should find foobar_enc in archive');
|
73 | 89 |
|
74 |
| -# Test restore_command |
| 90 | +# Test restore_command with encrypted WAL |
75 | 91 |
|
76 |
| -my $replica = PostgreSQL::Test::Cluster->new('replica'); |
77 |
| -$replica->init_from_backup($primary, 'backup'); |
78 |
| -$replica->append_conf('postgresql.conf', |
| 92 | +my $replica_enc = PostgreSQL::Test::Cluster->new('replica_enc'); |
| 93 | +$replica_enc->init_from_backup($primary, 'enc_wal'); |
| 94 | +$replica_enc->append_conf('postgresql.conf', |
79 | 95 | "restore_command = 'pg_tde_restore_encrypt %f %p \"cp $archive_dir/%%f %%p\"'"
|
80 | 96 | );
|
81 |
| -$replica->append_conf('postgresql.conf', "recovery_target_action = promote"); |
82 |
| -$replica->set_recovery_mode; |
83 |
| -$replica->start; |
| 97 | +$replica_enc->set_standby_mode; |
| 98 | +$replica_enc->start; |
84 | 99 |
|
85 |
| -$data_dir = $replica->data_dir; |
| 100 | +$replica_enc->wait_for_log("waiting for WAL to become available"); |
86 | 101 |
|
87 |
| -like( |
| 102 | +$data_dir = $replica_enc->data_dir; |
| 103 | + |
| 104 | +unlike( |
88 | 105 | `strings $data_dir/pg_wal/0000000100000000000000??`,
|
89 | 106 | qr/foobar_plain/,
|
90 |
| - 'should find foobar_plain in WAL since we use the same key file'); |
| 107 | + 'should not find foobar_plain in WAL since it is encrypted'); |
91 | 108 | unlike(
|
92 | 109 | `strings $data_dir/pg_wal/0000000100000000000000??`,
|
93 | 110 | qr/foobar_enc/,
|
94 | 111 | 'should not find foobar_enc in WAL since it is encrypted');
|
95 | 112 |
|
96 |
| -my $result = $replica->safe_psql('postgres', |
| 113 | +$replica_enc->promote; |
| 114 | + |
| 115 | +my $result = $replica_enc->safe_psql('postgres', |
| 116 | + 'SELECT * FROM t1 UNION ALL SELECT * FROM t2'); |
| 117 | + |
| 118 | +is($result, "foobar_plain\nfoobar_enc", 'b'); |
| 119 | + |
| 120 | +$replica_enc->stop; |
| 121 | + |
| 122 | +# Test restore_command with plain WAL |
| 123 | + |
| 124 | +my $replica_plain = PostgreSQL::Test::Cluster->new('replica_plain'); |
| 125 | +$replica_plain->init_from_backup($primary, 'plain_wal'); |
| 126 | +$replica_plain->append_conf('postgresql.conf', |
| 127 | + "restore_command = 'pg_tde_restore_encrypt %f %p \"cp $archive_dir/%%f %%p\"'" |
| 128 | +); |
| 129 | +$replica_plain->set_standby_mode; |
| 130 | +$replica_plain->start; |
| 131 | + |
| 132 | +$replica_plain->wait_for_log("waiting for WAL to become available"); |
| 133 | + |
| 134 | +$data_dir = $replica_plain->data_dir; |
| 135 | + |
| 136 | +like( |
| 137 | + `strings $data_dir/pg_wal/0000000100000000000000??`, |
| 138 | + qr/foobar_plain/, |
| 139 | + 'should find foobar_plain in WAL since it is not encrypted'); |
| 140 | +like( |
| 141 | + `strings $data_dir/pg_wal/0000000100000000000000??`, |
| 142 | + qr/foobar_enc/, |
| 143 | + 'should find foobar_enc in WAL since it is not encrypted'); |
| 144 | + |
| 145 | +$replica_plain->promote; |
| 146 | + |
| 147 | +$result = $replica_plain->safe_psql('postgres', |
97 | 148 | 'SELECT * FROM t1 UNION ALL SELECT * FROM t2');
|
98 | 149 |
|
99 | 150 | is($result, "foobar_plain\nfoobar_enc", 'b');
|
100 | 151 |
|
101 |
| -$replica->stop; |
| 152 | +$replica_plain->stop; |
102 | 153 |
|
103 | 154 | done_testing();
|
0 commit comments