|
438 | 438 | $node_publisher->stop('fast');
|
439 | 439 | $node_subscriber->stop('fast');
|
440 | 440 |
|
| 441 | +# The bug was that pgoutput was incorrectly replacing missing attributes in |
| 442 | +# tuples with NULL. This could result in incorrect replication with |
| 443 | +# `REPLICA IDENTITY FULL`. |
| 444 | + |
| 445 | +$node_publisher->rotate_logfile(); |
| 446 | +$node_publisher->start(); |
| 447 | + |
| 448 | +$node_subscriber->rotate_logfile(); |
| 449 | +$node_subscriber->start(); |
| 450 | + |
| 451 | +# Set up a table with schema `(a int, b bool)` where the `b` attribute is |
| 452 | +# missing for one row due to the `ALTER TABLE ... ADD COLUMN ... DEFAULT` |
| 453 | +# fast path. |
| 454 | +$node_publisher->safe_psql( |
| 455 | + 'postgres', qq( |
| 456 | + CREATE TABLE tab_default (a int); |
| 457 | + ALTER TABLE tab_default REPLICA IDENTITY FULL; |
| 458 | + INSERT INTO tab_default VALUES (1); |
| 459 | + ALTER TABLE tab_default ADD COLUMN b bool DEFAULT false NOT NULL; |
| 460 | + INSERT INTO tab_default VALUES (2, true); |
| 461 | + CREATE PUBLICATION pub1 FOR TABLE tab_default; |
| 462 | +)); |
| 463 | + |
| 464 | +# Replicate to the subscriber. |
| 465 | +$node_subscriber->safe_psql( |
| 466 | + 'postgres', qq( |
| 467 | + CREATE TABLE tab_default (a int, b bool); |
| 468 | + CREATE SUBSCRIPTION sub1 CONNECTION '$publisher_connstr' PUBLICATION pub1; |
| 469 | +)); |
| 470 | + |
| 471 | +$node_subscriber->wait_for_subscription_sync($node_publisher, 'sub1'); |
| 472 | +$result = $node_subscriber->safe_psql('postgres', |
| 473 | + "SELECT a, b FROM tab_default"); |
| 474 | +is($result, qq(1|f |
| 475 | +2|t), 'check snapshot on subscriber'); |
| 476 | + |
| 477 | +# Update all rows in the table and ensure the rows with the missing `b` |
| 478 | +# attribute replicate correctly. |
| 479 | +$node_publisher->safe_psql('postgres', |
| 480 | + "UPDATE tab_default SET a = a + 1"); |
| 481 | +$node_publisher->wait_for_catchup('sub1'); |
| 482 | + |
| 483 | +# When the bug is present, the `1|f` row will not be updated to `2|f` because |
| 484 | +# the publisher incorrectly fills in `NULL` for `b` and publishes an update |
| 485 | +# for `1|NULL`, which doesn't exist in the subscriber. |
| 486 | +$result = $node_subscriber->safe_psql('postgres', |
| 487 | + "SELECT a, b FROM tab_default"); |
| 488 | +is($result, qq(2|f |
| 489 | +3|t), 'check replicated update on subscriber'); |
| 490 | + |
| 491 | +$node_publisher->stop('fast'); |
| 492 | +$node_subscriber->stop('fast'); |
| 493 | + |
441 | 494 | done_testing();
|
0 commit comments