|
15 | 15 |
|
16 | 16 | my $datadir = PostgreSQL::Test::Utils::tempdir;
|
17 | 17 |
|
| 18 | +# Generate a database with a name made of a range of ASCII characters. |
| 19 | +# Extracted from 002_pg_upgrade.pl. |
| 20 | +sub generate_db |
| 21 | +{ |
| 22 | + my ($node, $prefix, $from_char, $to_char, $suffix) = @_; |
| 23 | + |
| 24 | + my $dbname = $prefix; |
| 25 | + for my $i ($from_char .. $to_char) |
| 26 | + { |
| 27 | + next if $i == 7 || $i == 10 || $i == 13; # skip BEL, LF, and CR |
| 28 | + $dbname = $dbname . sprintf('%c', $i); |
| 29 | + } |
| 30 | + |
| 31 | + $dbname .= $suffix; |
| 32 | + $node->command_ok( |
| 33 | + [ 'createdb', $dbname ], |
| 34 | + "created database with ASCII characters from $from_char to $to_char"); |
| 35 | + |
| 36 | + return $dbname; |
| 37 | +} |
| 38 | + |
18 | 39 | #
|
19 | 40 | # Test mandatory options
|
20 | 41 | command_fails(['pg_createsubscriber'],
|
|
104 | 125 | # - create test tables
|
105 | 126 | # - insert a row
|
106 | 127 | # - create a physical replication slot
|
107 |
| -$node_p->safe_psql( |
108 |
| - 'postgres', q( |
109 |
| - CREATE DATABASE pg1; |
110 |
| - CREATE DATABASE pg2; |
111 |
| -)); |
112 |
| -$node_p->safe_psql('pg1', 'CREATE TABLE tbl1 (a text)'); |
113 |
| -$node_p->safe_psql('pg1', "INSERT INTO tbl1 VALUES('first row')"); |
114 |
| -$node_p->safe_psql('pg2', 'CREATE TABLE tbl2 (a text)'); |
| 128 | +my $db1 = generate_db($node_p, 'regression\\"\\', 1, 45, '\\\\"\\\\\\'); |
| 129 | +my $db2 = generate_db($node_p, 'regression', 46, 90, ''); |
| 130 | + |
| 131 | +$node_p->safe_psql($db1, 'CREATE TABLE tbl1 (a text)'); |
| 132 | +$node_p->safe_psql($db1, "INSERT INTO tbl1 VALUES('first row')"); |
| 133 | +$node_p->safe_psql($db2, 'CREATE TABLE tbl2 (a text)'); |
115 | 134 | my $slotname = 'physical_slot';
|
116 |
| -$node_p->safe_psql('pg2', |
| 135 | +$node_p->safe_psql($db2, |
117 | 136 | "SELECT pg_create_physical_replication_slot('$slotname')");
|
118 | 137 |
|
119 | 138 | # Set up node S as standby linking to node P
|
|
143 | 162 | 'pg_createsubscriber', '--verbose',
|
144 | 163 | '--dry-run', '--pgdata',
|
145 | 164 | $node_t->data_dir, '--publisher-server',
|
146 |
| - $node_p->connstr('pg1'), '--socket-directory', |
| 165 | + $node_p->connstr($db1), '--socket-directory', |
147 | 166 | $node_t->host, '--subscriber-port',
|
148 | 167 | $node_t->port, '--database',
|
149 |
| - 'pg1', '--database', |
150 |
| - 'pg2' |
| 168 | + $db1, '--database', |
| 169 | + $db2 |
151 | 170 | ],
|
152 | 171 | 'target server is not in recovery');
|
153 | 172 |
|
|
157 | 176 | 'pg_createsubscriber', '--verbose',
|
158 | 177 | '--dry-run', '--pgdata',
|
159 | 178 | $node_s->data_dir, '--publisher-server',
|
160 |
| - $node_p->connstr('pg1'), '--socket-directory', |
| 179 | + $node_p->connstr($db1), '--socket-directory', |
161 | 180 | $node_s->host, '--subscriber-port',
|
162 | 181 | $node_s->port, '--database',
|
163 |
| - 'pg1', '--database', |
164 |
| - 'pg2' |
| 182 | + $db1, '--database', |
| 183 | + $db2 |
165 | 184 | ],
|
166 | 185 | 'standby is up and running');
|
167 | 186 |
|
|
170 | 189 | [
|
171 | 190 | 'pg_createsubscriber', '--verbose',
|
172 | 191 | '--pgdata', $node_f->data_dir,
|
173 |
| - '--publisher-server', $node_p->connstr('pg1'), |
| 192 | + '--publisher-server', $node_p->connstr($db1), |
174 | 193 | '--socket-directory', $node_f->host,
|
175 | 194 | '--subscriber-port', $node_f->port,
|
176 |
| - '--database', 'pg1', |
177 |
| - '--database', 'pg2' |
| 195 | + '--database', $db1, |
| 196 | + '--database', $db2 |
178 | 197 | ],
|
179 | 198 | 'subscriber data directory is not a copy of the source database cluster');
|
180 | 199 |
|
|
191 | 210 | 'pg_createsubscriber', '--verbose',
|
192 | 211 | '--dry-run', '--pgdata',
|
193 | 212 | $node_c->data_dir, '--publisher-server',
|
194 |
| - $node_s->connstr('pg1'), '--socket-directory', |
| 213 | + $node_s->connstr($db1), '--socket-directory', |
195 | 214 | $node_c->host, '--subscriber-port',
|
196 | 215 | $node_c->port, '--database',
|
197 |
| - 'pg1', '--database', |
198 |
| - 'pg2' |
| 216 | + $db1, '--database', |
| 217 | + $db2 |
199 | 218 | ],
|
200 | 219 | 'primary server is in recovery');
|
201 | 220 |
|
202 | 221 | # Insert another row on node P and wait node S to catch up
|
203 |
| -$node_p->safe_psql('pg1', "INSERT INTO tbl1 VALUES('second row')"); |
| 222 | +$node_p->safe_psql($db1, "INSERT INTO tbl1 VALUES('second row')"); |
204 | 223 | $node_p->wait_for_replay_catchup($node_s);
|
205 | 224 |
|
206 | 225 | # Check some unmet conditions on node P
|
|
218 | 237 | 'pg_createsubscriber', '--verbose',
|
219 | 238 | '--dry-run', '--pgdata',
|
220 | 239 | $node_s->data_dir, '--publisher-server',
|
221 |
| - $node_p->connstr('pg1'), '--socket-directory', |
| 240 | + $node_p->connstr($db1), '--socket-directory', |
222 | 241 | $node_s->host, '--subscriber-port',
|
223 | 242 | $node_s->port, '--database',
|
224 |
| - 'pg1', '--database', |
225 |
| - 'pg2' |
| 243 | + $db1, '--database', |
| 244 | + $db2 |
226 | 245 | ],
|
227 | 246 | 'primary contains unmet conditions on node P');
|
228 | 247 | # Restore default settings here but only apply it after testing standby. Some
|
|
247 | 266 | 'pg_createsubscriber', '--verbose',
|
248 | 267 | '--dry-run', '--pgdata',
|
249 | 268 | $node_s->data_dir, '--publisher-server',
|
250 |
| - $node_p->connstr('pg1'), '--socket-directory', |
| 269 | + $node_p->connstr($db1), '--socket-directory', |
251 | 270 | $node_s->host, '--subscriber-port',
|
252 | 271 | $node_s->port, '--database',
|
253 |
| - 'pg1', '--database', |
254 |
| - 'pg2' |
| 272 | + $db1, '--database', |
| 273 | + $db2 |
255 | 274 | ],
|
256 | 275 | 'standby contains unmet conditions on node S');
|
257 | 276 | $node_s->append_conf(
|
|
265 | 284 |
|
266 | 285 | # Create failover slot to test its removal
|
267 | 286 | my $fslotname = 'failover_slot';
|
268 |
| -$node_p->safe_psql('pg1', |
| 287 | +$node_p->safe_psql($db1, |
269 | 288 | "SELECT pg_create_logical_replication_slot('$fslotname', 'pgoutput', false, false, true)");
|
270 | 289 | $node_s->start;
|
271 | 290 | $node_s->safe_psql('postgres', "SELECT pg_sync_replication_slots()");
|
|
280 | 299 | '--recovery-timeout', "$PostgreSQL::Test::Utils::timeout_default",
|
281 | 300 | '--dry-run', '--pgdata',
|
282 | 301 | $node_s->data_dir, '--publisher-server',
|
283 |
| - $node_p->connstr('pg1'), '--socket-directory', |
| 302 | + $node_p->connstr($db1), '--socket-directory', |
284 | 303 | $node_s->host, '--subscriber-port',
|
285 | 304 | $node_s->port, '--publication',
|
286 | 305 | 'pub1', '--publication',
|
287 | 306 | 'pub2', '--subscription',
|
288 | 307 | 'sub1', '--subscription',
|
289 | 308 | 'sub2', '--database',
|
290 |
| - 'pg1', '--database', |
291 |
| - 'pg2' |
| 309 | + $db1, '--database', |
| 310 | + $db2 |
292 | 311 | ],
|
293 | 312 | 'run pg_createsubscriber --dry-run on node S');
|
294 | 313 |
|
|
304 | 323 | 'pg_createsubscriber', '--verbose',
|
305 | 324 | '--dry-run', '--pgdata',
|
306 | 325 | $node_s->data_dir, '--publisher-server',
|
307 |
| - $node_p->connstr('pg1'), '--socket-directory', |
| 326 | + $node_p->connstr($db1), '--socket-directory', |
308 | 327 | $node_s->host, '--subscriber-port',
|
309 | 328 | $node_s->port, '--replication-slot',
|
310 | 329 | 'replslot1'
|
|
318 | 337 | '--recovery-timeout', "$PostgreSQL::Test::Utils::timeout_default",
|
319 | 338 | '--verbose', '--pgdata',
|
320 | 339 | $node_s->data_dir, '--publisher-server',
|
321 |
| - $node_p->connstr('pg1'), '--socket-directory', |
| 340 | + $node_p->connstr($db1), '--socket-directory', |
322 | 341 | $node_s->host, '--subscriber-port',
|
323 | 342 | $node_s->port, '--publication',
|
324 | 343 | 'pub1', '--publication',
|
325 | 344 | 'Pub2', '--replication-slot',
|
326 | 345 | 'replslot1', '--replication-slot',
|
327 | 346 | 'replslot2', '--database',
|
328 |
| - 'pg1', '--database', |
329 |
| - 'pg2' |
| 347 | + $db1, '--database', |
| 348 | + $db2 |
330 | 349 | ],
|
331 | 350 | 'run pg_createsubscriber on node S');
|
332 | 351 |
|
333 | 352 | # Confirm the physical replication slot has been removed
|
334 |
| -$result = $node_p->safe_psql('pg1', |
| 353 | +$result = $node_p->safe_psql($db1, |
335 | 354 | "SELECT count(*) FROM pg_replication_slots WHERE slot_name = '$slotname'"
|
336 | 355 | );
|
337 | 356 | is($result, qq(0),
|
338 | 357 | 'the physical replication slot used as primary_slot_name has been removed'
|
339 | 358 | );
|
340 | 359 |
|
341 | 360 | # Insert rows on P
|
342 |
| -$node_p->safe_psql('pg1', "INSERT INTO tbl1 VALUES('third row')"); |
343 |
| -$node_p->safe_psql('pg2', "INSERT INTO tbl2 VALUES('row 1')"); |
| 361 | +$node_p->safe_psql($db1, "INSERT INTO tbl1 VALUES('third row')"); |
| 362 | +$node_p->safe_psql($db2, "INSERT INTO tbl2 VALUES('row 1')"); |
344 | 363 |
|
345 | 364 | # Start subscriber
|
346 | 365 | $node_s->start;
|
|
357 | 376 | $node_s->wait_for_subscription_sync($node_p, $subnames[1]);
|
358 | 377 |
|
359 | 378 | # Confirm the failover slot has been removed
|
360 |
| -$result = $node_s->safe_psql('pg1', |
| 379 | +$result = $node_s->safe_psql($db1, |
361 | 380 | "SELECT count(*) FROM pg_replication_slots WHERE slot_name = '$fslotname'");
|
362 | 381 | is($result, qq(0), 'failover slot was removed');
|
363 | 382 |
|
364 |
| -# Check result on database pg1 |
365 |
| -$result = $node_s->safe_psql('pg1', 'SELECT * FROM tbl1'); |
| 383 | +# Check result on database $db1 |
| 384 | +$result = $node_s->safe_psql($db1, 'SELECT * FROM tbl1'); |
366 | 385 | is( $result, qq(first row
|
367 | 386 | second row
|
368 | 387 | third row),
|
369 |
| - 'logical replication works on database pg1'); |
| 388 | + "logical replication works on database $db1"); |
370 | 389 |
|
371 |
| -# Check result on database pg2 |
372 |
| -$result = $node_s->safe_psql('pg2', 'SELECT * FROM tbl2'); |
373 |
| -is($result, qq(row 1), 'logical replication works on database pg2'); |
| 390 | +# Check result on database $db2 |
| 391 | +$result = $node_s->safe_psql($db2, 'SELECT * FROM tbl2'); |
| 392 | +is($result, qq(row 1), "logical replication works on database $db2"); |
374 | 393 |
|
375 | 394 | # Different system identifier?
|
376 | 395 | my $sysid_p = $node_p->safe_psql('postgres',
|
|
0 commit comments