|
| 1 | +# Run the standard regression tests with streaming replication |
| 2 | +use strict; |
| 3 | +use warnings; |
| 4 | +use PostgreSQL::Test::Cluster; |
| 5 | +use PostgreSQL::Test::Utils; |
| 6 | +use Test::More tests => 4; |
| 7 | +use File::Basename; |
| 8 | + |
| 9 | +# Initialize primary node |
| 10 | +my $node_primary = PostgreSQL::Test::Cluster->new('primary'); |
| 11 | +$node_primary->init(allows_streaming => 1); |
| 12 | +$node_primary->adjust_conf('postgresql.conf', 'max_connections', '25', 1); |
| 13 | +$node_primary->append_conf('postgresql.conf', 'max_prepared_transactions = 10'); |
| 14 | + |
| 15 | +# WAL consistency checking is resource intensive so require opt-in with the |
| 16 | +# PG_TEST_EXTRA environment variable. |
| 17 | +if ($ENV{PG_TEST_EXTRA} && |
| 18 | + $ENV{PG_TEST_EXTRA} =~ m/\bwal_consistency_checking\b/) { |
| 19 | + $node_primary->append_conf('postgresql.conf', |
| 20 | + 'wal_consistency_checking = all'); |
| 21 | +} |
| 22 | + |
| 23 | +$node_primary->start; |
| 24 | +is( $node_primary->psql( |
| 25 | + 'postgres', |
| 26 | + qq[SELECT pg_create_physical_replication_slot('standby_1');]), |
| 27 | + 0, |
| 28 | + 'physical slot created on primary'); |
| 29 | +my $backup_name = 'my_backup'; |
| 30 | + |
| 31 | +# Take backup |
| 32 | +$node_primary->backup($backup_name); |
| 33 | + |
| 34 | +# Create streaming standby linking to primary |
| 35 | +my $node_standby_1 = PostgreSQL::Test::Cluster->new('standby_1'); |
| 36 | +$node_standby_1->init_from_backup($node_primary, $backup_name, |
| 37 | + has_streaming => 1); |
| 38 | +$node_standby_1->append_conf('postgresql.conf', |
| 39 | + "primary_slot_name = standby_1"); |
| 40 | +$node_standby_1->start; |
| 41 | + |
| 42 | +my $dlpath = PostgreSQL::Test::Utils::perl2host(dirname($ENV{REGRESS_SHLIB})); |
| 43 | +my $outputdir = PostgreSQL::Test::Utils::perl2host($ENV{REGRESS_OUTPUTDIR}); |
| 44 | + |
| 45 | +# Run the regression tests against the primary. |
| 46 | +my $extra_opts = $ENV{EXTRA_REGRESS_OPTS} || ""; |
| 47 | +system_or_bail($ENV{PG_REGRESS} . " $extra_opts " . |
| 48 | + "--dlpath=\"$dlpath\" " . |
| 49 | + "--bindir= " . |
| 50 | + "--port=" . $node_primary->port . " " . |
| 51 | + "--schedule=../regress/parallel_schedule " . |
| 52 | + "--max-concurrent-tests=20 " . |
| 53 | + "--inputdir=../regress " . |
| 54 | + "--outputdir=\"$outputdir\""); |
| 55 | + |
| 56 | +# Clobber all sequences with their next value, so that we don't have |
| 57 | +# differences between nodes due to caching. |
| 58 | +$node_primary->psql('regression', |
| 59 | + "select setval(seqrelid, nextval(seqrelid)) from pg_sequence"); |
| 60 | + |
| 61 | +# Wait for standby to catch up |
| 62 | +$node_primary->wait_for_catchup($node_standby_1, 'replay', |
| 63 | + $node_primary->lsn('insert')); |
| 64 | + |
| 65 | +# Perform a logical dump of primary and standby, and check that they match |
| 66 | +command_ok( |
| 67 | + [ 'pg_dumpall', '-f', $outputdir . '/primary.dump', '--no-sync', |
| 68 | + '-p', $node_primary->port ], |
| 69 | + 'dump primary server'); |
| 70 | +command_ok( |
| 71 | + [ 'pg_dumpall', '-f', $outputdir . '/standby.dump', '--no-sync', |
| 72 | + '-p', $node_standby_1->port ], |
| 73 | + 'dump standby server'); |
| 74 | +command_ok( |
| 75 | + [ 'diff', $outputdir . '/primary.dump', $outputdir . '/standby.dump' ], |
| 76 | + 'compare primary and standby dumps'); |
| 77 | + |
| 78 | +$node_standby_1->stop; |
| 79 | +$node_primary->stop; |
0 commit comments