|
15 | 15 | my $mode = $ENV{PG_TEST_PG_UPGRADE_MODE} || '--copy';
|
16 | 16 |
|
17 | 17 | # Initialize old cluster
|
18 |
| -my $old_publisher = PostgreSQL::Test::Cluster->new('old_publisher'); |
19 |
| -$old_publisher->init(allows_streaming => 'logical'); |
| 18 | +my $oldpub = PostgreSQL::Test::Cluster->new('oldpub'); |
| 19 | +$oldpub->init(allows_streaming => 'logical'); |
20 | 20 |
|
21 | 21 | # Initialize new cluster
|
22 |
| -my $new_publisher = PostgreSQL::Test::Cluster->new('new_publisher'); |
23 |
| -$new_publisher->init(allows_streaming => 'logical'); |
| 22 | +my $newpub = PostgreSQL::Test::Cluster->new('newpub'); |
| 23 | +$newpub->init(allows_streaming => 'logical'); |
24 | 24 |
|
25 |
| -# Setup a pg_upgrade command. This will be used anywhere. |
| 25 | +# Setup a common pg_upgrade command to be used by all the test cases |
26 | 26 | my @pg_upgrade_cmd = (
|
27 | 27 | 'pg_upgrade', '--no-sync',
|
28 |
| - '-d', $old_publisher->data_dir, |
29 |
| - '-D', $new_publisher->data_dir, |
30 |
| - '-b', $old_publisher->config_data('--bindir'), |
31 |
| - '-B', $new_publisher->config_data('--bindir'), |
32 |
| - '-s', $new_publisher->host, |
33 |
| - '-p', $old_publisher->port, |
34 |
| - '-P', $new_publisher->port, |
| 28 | + '-d', $oldpub->data_dir, |
| 29 | + '-D', $newpub->data_dir, |
| 30 | + '-b', $oldpub->config_data('--bindir'), |
| 31 | + '-B', $newpub->config_data('--bindir'), |
| 32 | + '-s', $newpub->host, |
| 33 | + '-p', $oldpub->port, |
| 34 | + '-P', $newpub->port, |
35 | 35 | $mode);
|
36 | 36 |
|
37 | 37 | # ------------------------------
|
38 | 38 | # TEST: Confirm pg_upgrade fails when the new cluster has wrong GUC values
|
39 | 39 |
|
40 | 40 | # Preparations for the subsequent test:
|
41 | 41 | # 1. Create two slots on the old cluster
|
42 |
| -$old_publisher->start; |
43 |
| -$old_publisher->safe_psql( |
| 42 | +$oldpub->start; |
| 43 | +$oldpub->safe_psql( |
44 | 44 | 'postgres', qq[
|
45 | 45 | SELECT pg_create_logical_replication_slot('test_slot1', 'test_decoding');
|
46 | 46 | SELECT pg_create_logical_replication_slot('test_slot2', 'test_decoding');
|
47 | 47 | ]);
|
48 |
| -$old_publisher->stop(); |
| 48 | +$oldpub->stop(); |
49 | 49 |
|
50 | 50 | # 2. Set 'max_replication_slots' to be less than the number of slots (2)
|
51 | 51 | # present on the old cluster.
|
52 |
| -$new_publisher->append_conf('postgresql.conf', "max_replication_slots = 1"); |
| 52 | +$newpub->append_conf('postgresql.conf', "max_replication_slots = 1"); |
53 | 53 |
|
54 | 54 | # pg_upgrade will fail because the new cluster has insufficient
|
55 | 55 | # max_replication_slots
|
|
62 | 62 | [qr//],
|
63 | 63 | 'run of pg_upgrade where the new cluster has insufficient max_replication_slots'
|
64 | 64 | );
|
65 |
| -ok( -d $new_publisher->data_dir . "/pg_upgrade_output.d", |
| 65 | +ok( -d $newpub->data_dir . "/pg_upgrade_output.d", |
66 | 66 | "pg_upgrade_output.d/ not removed after pg_upgrade failure");
|
67 | 67 |
|
68 | 68 | # Set 'max_replication_slots' to match the number of slots (2) present on the
|
69 | 69 | # old cluster. Both slots will be used for subsequent tests.
|
70 |
| -$new_publisher->append_conf('postgresql.conf', "max_replication_slots = 2"); |
| 70 | +$newpub->append_conf('postgresql.conf', "max_replication_slots = 2"); |
71 | 71 |
|
72 | 72 |
|
73 | 73 | # ------------------------------
|
|
82 | 82 | #
|
83 | 83 | # 3. Emit a non-transactional message. This will cause test_slot2 to detect the
|
84 | 84 | # unconsumed WAL record.
|
85 |
| -$old_publisher->start; |
86 |
| -$old_publisher->safe_psql( |
| 85 | +$oldpub->start; |
| 86 | +$oldpub->safe_psql( |
87 | 87 | 'postgres', qq[
|
88 | 88 | CREATE TABLE tbl AS SELECT generate_series(1, 10) AS a;
|
89 | 89 | SELECT pg_replication_slot_advance('test_slot2', pg_current_wal_lsn());
|
90 | 90 | SELECT count(*) FROM pg_logical_emit_message('false', 'prefix', 'This is a non-transactional message');
|
91 | 91 | ]);
|
92 |
| -$old_publisher->stop; |
| 92 | +$oldpub->stop; |
93 | 93 |
|
94 | 94 | # pg_upgrade will fail because there are slots still having unconsumed WAL
|
95 | 95 | # records
|
|
111 | 111 | # contains a milliseconds timestamp. File::Find::find must be used.
|
112 | 112 | find(
|
113 | 113 | sub {
|
114 |
| - if ($File::Find::name =~ m/invalid_logical_replication_slots\.txt/) |
| 114 | + if ($File::Find::name =~ m/invalid_logical_slots\.txt/) |
115 | 115 | {
|
116 | 116 | $slots_filename = $File::Find::name;
|
117 | 117 | }
|
118 | 118 | },
|
119 |
| - $new_publisher->data_dir . "/pg_upgrade_output.d"); |
| 119 | + $newpub->data_dir . "/pg_upgrade_output.d"); |
120 | 120 |
|
121 | 121 | # Check the file content. Both slots should be reporting that they have
|
122 | 122 | # unconsumed WAL records.
|
|
135 | 135 |
|
136 | 136 | # Preparations for the subsequent test:
|
137 | 137 | # 1. Setup logical replication (first, cleanup slots from the previous tests)
|
138 |
| -my $old_connstr = $old_publisher->connstr . ' dbname=postgres'; |
| 138 | +my $old_connstr = $oldpub->connstr . ' dbname=postgres'; |
139 | 139 |
|
140 |
| -$old_publisher->start; |
141 |
| -$old_publisher->safe_psql( |
| 140 | +$oldpub->start; |
| 141 | +$oldpub->safe_psql( |
142 | 142 | 'postgres', qq[
|
143 | 143 | SELECT * FROM pg_drop_replication_slot('test_slot1');
|
144 | 144 | SELECT * FROM pg_drop_replication_slot('test_slot2');
|
145 | 145 | CREATE PUBLICATION regress_pub FOR ALL TABLES;
|
146 | 146 | ]);
|
147 | 147 |
|
148 | 148 | # Initialize subscriber cluster
|
149 |
| -my $subscriber = PostgreSQL::Test::Cluster->new('subscriber'); |
150 |
| -$subscriber->init(); |
| 149 | +my $sub = PostgreSQL::Test::Cluster->new('sub'); |
| 150 | +$sub->init(); |
151 | 151 |
|
152 |
| -$subscriber->start; |
153 |
| -$subscriber->safe_psql( |
| 152 | +$sub->start; |
| 153 | +$sub->safe_psql( |
154 | 154 | 'postgres', qq[
|
155 | 155 | CREATE TABLE tbl (a int);
|
156 | 156 | CREATE SUBSCRIPTION regress_sub CONNECTION '$old_connstr' PUBLICATION regress_pub WITH (two_phase = 'true')
|
157 | 157 | ]);
|
158 |
| -$subscriber->wait_for_subscription_sync($old_publisher, 'regress_sub'); |
| 158 | +$sub->wait_for_subscription_sync($oldpub, 'regress_sub'); |
159 | 159 |
|
160 | 160 | # 2. Temporarily disable the subscription
|
161 |
| -$subscriber->safe_psql('postgres', "ALTER SUBSCRIPTION regress_sub DISABLE"); |
162 |
| -$old_publisher->stop; |
| 161 | +$sub->safe_psql('postgres', "ALTER SUBSCRIPTION regress_sub DISABLE"); |
| 162 | +$oldpub->stop; |
163 | 163 |
|
164 | 164 | # pg_upgrade should be successful
|
165 | 165 | command_ok([@pg_upgrade_cmd], 'run of pg_upgrade of old cluster');
|
166 | 166 |
|
167 | 167 | # Check that the slot 'regress_sub' has migrated to the new cluster
|
168 |
| -$new_publisher->start; |
169 |
| -my $result = $new_publisher->safe_psql('postgres', |
| 168 | +$newpub->start; |
| 169 | +my $result = $newpub->safe_psql('postgres', |
170 | 170 | "SELECT slot_name, two_phase FROM pg_replication_slots");
|
171 | 171 | is($result, qq(regress_sub|t), 'check the slot exists on new cluster');
|
172 | 172 |
|
173 | 173 | # Update the connection
|
174 |
| -my $new_connstr = $new_publisher->connstr . ' dbname=postgres'; |
175 |
| -$subscriber->safe_psql( |
| 174 | +my $new_connstr = $newpub->connstr . ' dbname=postgres'; |
| 175 | +$sub->safe_psql( |
176 | 176 | 'postgres', qq[
|
177 | 177 | ALTER SUBSCRIPTION regress_sub CONNECTION '$new_connstr';
|
178 | 178 | ALTER SUBSCRIPTION regress_sub ENABLE;
|
179 | 179 | ]);
|
180 | 180 |
|
181 | 181 | # Check whether changes on the new publisher get replicated to the subscriber
|
182 |
| -$new_publisher->safe_psql('postgres', |
| 182 | +$newpub->safe_psql('postgres', |
183 | 183 | "INSERT INTO tbl VALUES (generate_series(11, 20))");
|
184 |
| -$new_publisher->wait_for_catchup('regress_sub'); |
185 |
| -$result = $subscriber->safe_psql('postgres', "SELECT count(*) FROM tbl"); |
186 |
| -is($result, qq(20), 'check changes are replicated to the subscriber'); |
| 184 | +$newpub->wait_for_catchup('regress_sub'); |
| 185 | +$result = $sub->safe_psql('postgres', "SELECT count(*) FROM tbl"); |
| 186 | +is($result, qq(20), 'check changes are replicated to the sub'); |
187 | 187 |
|
188 | 188 | # Clean up
|
189 |
| -$subscriber->stop(); |
190 |
| -$new_publisher->stop(); |
| 189 | +$sub->stop(); |
| 190 | +$newpub->stop(); |
191 | 191 |
|
192 | 192 | done_testing();
|
0 commit comments