|
19 | 19 | $node_primary->backup($backup_name); |
20 | 20 |
|
21 | 21 | # Create a streaming standby with a 1 second delay from the backup |
22 | | -my $node_standby1 = PostgreSQL::Test::Cluster->new('standby'); |
| 22 | +my $node_standby = PostgreSQL::Test::Cluster->new('standby'); |
23 | 23 | my $delay = 1; |
24 | | -$node_standby1->init_from_backup($node_primary, $backup_name, |
| 24 | +$node_standby->init_from_backup($node_primary, $backup_name, |
25 | 25 | has_streaming => 1); |
26 | | -$node_standby1->append_conf( |
| 26 | +$node_standby->append_conf( |
27 | 27 | 'postgresql.conf', qq[ |
28 | 28 | recovery_min_apply_delay = '${delay}s' |
29 | 29 | ]); |
30 | | -$node_standby1->start; |
| 30 | +$node_standby->start; |
31 | 31 |
|
32 | 32 | # 1. Make sure that pg_wal_replay_wait() works: add new content to |
33 | 33 | # primary and memorize primary's insert LSN, then wait for that LSN to be |
|
36 | 36 | "INSERT INTO wait_test VALUES (generate_series(11, 20))"); |
37 | 37 | my $lsn1 = |
38 | 38 | $node_primary->safe_psql('postgres', "SELECT pg_current_wal_insert_lsn()"); |
39 | | -my $output = $node_standby1->safe_psql( |
| 39 | +my $output = $node_standby->safe_psql( |
40 | 40 | 'postgres', qq[ |
41 | 41 | CALL pg_wal_replay_wait('${lsn1}', 1000000); |
42 | 42 | SELECT pg_lsn_cmp(pg_last_wal_replay_lsn(), '${lsn1}'::pg_lsn); |
|
52 | 52 | "INSERT INTO wait_test VALUES (generate_series(21, 30))"); |
53 | 53 | my $lsn2 = |
54 | 54 | $node_primary->safe_psql('postgres', "SELECT pg_current_wal_insert_lsn()"); |
55 | | -$output = $node_standby1->safe_psql( |
| 55 | +$output = $node_standby->safe_psql( |
56 | 56 | 'postgres', qq[ |
57 | 57 | CALL pg_wal_replay_wait('${lsn2}'); |
58 | 58 | SELECT count(*) FROM wait_test; |
|
68 | 68 | $node_primary->safe_psql('postgres', |
69 | 69 | "SELECT pg_current_wal_insert_lsn() + 10000000000"); |
70 | 70 | my $stderr; |
71 | | -$node_standby1->safe_psql('postgres', |
| 71 | +$node_standby->safe_psql('postgres', |
72 | 72 | "CALL pg_wal_replay_wait('${lsn2}', 10);"); |
73 | | -$node_standby1->psql( |
| 73 | +$node_standby->psql( |
74 | 74 | 'postgres', |
75 | 75 | "CALL pg_wal_replay_wait('${lsn3}', 1000);", |
76 | 76 | stderr => \$stderr); |
|
88 | 88 | ok( $stderr =~ /recovery is not in progress/, |
89 | 89 | "get an error when running on the primary"); |
90 | 90 |
|
91 | | -$node_standby1->psql( |
| 91 | +$node_standby->psql( |
92 | 92 | 'postgres', |
93 | 93 | "BEGIN ISOLATION LEVEL REPEATABLE READ; CALL pg_wal_replay_wait('${lsn3}');", |
94 | 94 | stderr => \$stderr); |
|
107 | 107 | LANGUAGE plpgsql; |
108 | 108 | ]); |
109 | 109 |
|
110 | | -$node_primary->wait_for_catchup($node_standby1); |
111 | | -$node_standby1->psql( |
| 110 | +$node_primary->wait_for_catchup($node_standby); |
| 111 | +$node_standby->psql( |
112 | 112 | 'postgres', |
113 | 113 | "SELECT pg_wal_replay_wait_wrap('${lsn3}');", |
114 | 114 | stderr => \$stderr); |
|
134 | 134 | \$\$ |
135 | 135 | LANGUAGE plpgsql; |
136 | 136 | ]); |
137 | | -$node_standby1->safe_psql('postgres', "SELECT pg_wal_replay_pause();"); |
| 137 | +$node_standby->safe_psql('postgres', "SELECT pg_wal_replay_pause();"); |
138 | 138 | my @psql_sessions; |
139 | 139 | for (my $i = 0; $i < 5; $i++) |
140 | 140 | { |
141 | | - print($i); |
142 | 141 | $node_primary->safe_psql('postgres', |
143 | 142 | "INSERT INTO wait_test VALUES (${i});"); |
144 | 143 | my $lsn = |
145 | 144 | $node_primary->safe_psql('postgres', |
146 | 145 | "SELECT pg_current_wal_insert_lsn()"); |
147 | | - $psql_sessions[$i] = $node_standby1->background_psql('postgres'); |
| 146 | + $psql_sessions[$i] = $node_standby->background_psql('postgres'); |
148 | 147 | $psql_sessions[$i]->query_until( |
149 | 148 | qr/start/, qq[ |
150 | 149 | \\echo start |
151 | 150 | CALL pg_wal_replay_wait('${lsn}'); |
152 | 151 | SELECT log_count(${i}); |
153 | 152 | ]); |
154 | 153 | } |
155 | | -my $log_offset = -s $node_standby1->logfile; |
156 | | -$node_standby1->safe_psql('postgres', "SELECT pg_wal_replay_resume();"); |
| 154 | +my $log_offset = -s $node_standby->logfile; |
| 155 | +$node_standby->safe_psql('postgres', "SELECT pg_wal_replay_resume();"); |
157 | 156 | for (my $i = 0; $i < 5; $i++) |
158 | 157 | { |
159 | | - $node_standby1->wait_for_log("count ${i}", $log_offset); |
| 158 | + $node_standby->wait_for_log("count ${i}", $log_offset); |
160 | 159 | $psql_sessions[$i]->quit; |
161 | 160 | } |
162 | 161 |
|
|
171 | 170 | "SELECT pg_current_wal_insert_lsn() + 10000000000"); |
172 | 171 | my $lsn5 = |
173 | 172 | $node_primary->safe_psql('postgres', "SELECT pg_current_wal_insert_lsn()"); |
174 | | -my $psql_session = $node_standby1->background_psql('postgres'); |
| 173 | +my $psql_session = $node_standby->background_psql('postgres'); |
175 | 174 | $psql_session->query_until( |
176 | 175 | qr/start/, qq[ |
177 | 176 | \\echo start |
178 | 177 | CALL pg_wal_replay_wait('${lsn4}'); |
179 | 178 | ]); |
180 | 179 |
|
181 | | -$log_offset = -s $node_standby1->logfile; |
182 | | -$node_standby1->promote; |
183 | | -$node_standby1->wait_for_log('recovery is not in progress', $log_offset); |
| 180 | +$log_offset = -s $node_standby->logfile; |
| 181 | +$node_standby->promote; |
| 182 | +$node_standby->wait_for_log('recovery is not in progress', $log_offset); |
184 | 183 |
|
185 | 184 | ok(1, 'got error after standby promote'); |
186 | 185 |
|
187 | | -$node_standby1->safe_psql('postgres', "CALL pg_wal_replay_wait('${lsn5}');"); |
| 186 | +$node_standby->safe_psql('postgres', "CALL pg_wal_replay_wait('${lsn5}');"); |
188 | 187 |
|
189 | | -ok(1, |
190 | | - 'wait for already replayed LSN exists immediately even after promotion'); |
| 188 | +ok(1, 'wait for already replayed LSN exits immediately even after promotion'); |
191 | 189 |
|
192 | | -$node_standby1->stop; |
| 190 | +$node_standby->stop; |
193 | 191 | $node_primary->stop; |
194 | 192 |
|
195 | 193 | # If we send \q with $psql_session->quit the command can be sent to the session |
|
0 commit comments