|
| 1 | +# Copyright (c) 2021-2022, PostgreSQL Global Development Group |
| 2 | + |
| 3 | +# Verify WAL consistency |
| 4 | + |
| 5 | +use strict; |
| 6 | +use warnings; |
| 7 | + |
| 8 | +use PostgreSQL::Test::Utils; |
| 9 | +use Test::More; |
| 10 | +use PostgreSQL::Test::Cluster; |
| 11 | + |
| 12 | +# Set up primary |
| 13 | +my $whiskey = PostgreSQL::Test::Cluster->new('whiskey'); |
| 14 | +$whiskey->init(allows_streaming => 1); |
| 15 | +$whiskey->append_conf('postgresql.conf', 'wal_consistency_checking = brin'); |
| 16 | +$whiskey->start; |
| 17 | +$whiskey->safe_psql('postgres', 'create extension pageinspect'); |
| 18 | +is( $whiskey->psql( |
| 19 | + 'postgres', |
| 20 | + qq[SELECT pg_create_physical_replication_slot('standby_1');]), |
| 21 | + 0, |
| 22 | + 'physical slot created on primary'); |
| 23 | + |
| 24 | +# Take backup |
| 25 | +my $backup_name = 'brinbkp'; |
| 26 | +$whiskey->backup($backup_name); |
| 27 | + |
| 28 | +# Create streaming standby linking to primary |
| 29 | +my $charlie = PostgreSQL::Test::Cluster->new('charlie'); |
| 30 | +$charlie->init_from_backup($whiskey, $backup_name, has_streaming => 1); |
| 31 | +$charlie->append_conf('postgresql.conf', 'primary_slot_name = standby_1'); |
| 32 | +$charlie->start; |
| 33 | + |
| 34 | +# Now write some WAL in the primary |
| 35 | + |
| 36 | +$whiskey->safe_psql( |
| 37 | + 'postgres', qq{ |
| 38 | +create table tbl_timestamp0 (d1 timestamp(0) without time zone) with (fillfactor=10); |
| 39 | +create index on tbl_timestamp0 using brin (d1) with (pages_per_range = 1, autosummarize=false); |
| 40 | +}); |
| 41 | +# Run a loop that will end when the second revmap page is created |
| 42 | +$whiskey->safe_psql( |
| 43 | + 'postgres', q{ |
| 44 | +do |
| 45 | +$$ |
| 46 | +declare |
| 47 | + current timestamp with time zone := '2019-03-27 08:14:01.123456789 America/Punta_Arenas'; |
| 48 | +begin |
| 49 | + loop |
| 50 | + insert into tbl_timestamp0 select i from |
| 51 | + generate_series(current, current + interval '1 day', '28 seconds') i; |
| 52 | + perform brin_summarize_new_values('tbl_timestamp0_d1_idx'); |
| 53 | + if (brin_metapage_info(get_raw_page('tbl_timestamp0_d1_idx', 0))).lastrevmappage > 1 then |
| 54 | + exit; |
| 55 | + end if; |
| 56 | + current := current + interval '1 day'; |
| 57 | + end loop; |
| 58 | +end |
| 59 | +$$; |
| 60 | +}); |
| 61 | + |
| 62 | +$whiskey->wait_for_catchup($charlie, 'replay', $whiskey->lsn('insert')); |
| 63 | + |
| 64 | +done_testing(); |
0 commit comments