Debian Codegraph @

src/test/subscription/t/009_matviews.pl

raw
1
2 # Copyright (c) 2021-2025, PostgreSQL Global Development Group
3
4 # Test materialized views behavior
5 use strict;
6 use warnings FATAL => 'all';
7 use PostgreSQL::Test::Cluster;
8 use PostgreSQL::Test::Utils;
9 use Test::More;
10
11 my $node_publisher = PostgreSQL::Test::Cluster->new('publisher');
12 $node_publisher->init(allows_streaming => 'logical');
13 $node_publisher->start;
14
15 my $node_subscriber = PostgreSQL::Test::Cluster->new('subscriber');
16 $node_subscriber->init;
17 $node_subscriber->start;
18
19 my $publisher_connstr = $node_publisher->connstr . ' dbname=postgres';
20
21 $node_publisher->safe_psql('postgres',
22 "CREATE PUBLICATION mypub FOR ALL TABLES;");
23 $node_subscriber->safe_psql('postgres',
24 "CREATE SUBSCRIPTION mysub CONNECTION '$publisher_connstr' PUBLICATION mypub;"
25 );
26
27 $node_publisher->safe_psql('postgres',
28 q{CREATE TABLE test1 (a int PRIMARY KEY, b text)});
29 $node_publisher->safe_psql('postgres',
30 q{INSERT INTO test1 (a, b) VALUES (1, 'one'), (2, 'two');});
31
32 $node_subscriber->safe_psql('postgres',
33 q{CREATE TABLE test1 (a int PRIMARY KEY, b text);});
34
35 $node_publisher->wait_for_catchup('mysub');
36
37 # Materialized views are not supported by logical replication, but
38 # logical decoding does produce change information for them, so we
39 # need to make sure they are properly ignored. (bug #15044)
40
41 # create a MV with some data
42 $node_publisher->safe_psql('postgres',
43 q{CREATE MATERIALIZED VIEW testmv1 AS SELECT * FROM test1;});
44 $node_publisher->wait_for_catchup('mysub');
45
46 # There is no equivalent relation on the subscriber, but MV data is
47 # not replicated, so this does not hang.
48
49 pass "materialized view data not replicated";
50
51 $node_subscriber->stop;
52 $node_publisher->stop;
53
54 done_testing();