|
| 1 | +use strict; |
| 2 | +use warnings; |
| 3 | +use Test::More; |
| 4 | + |
| 5 | +my $pg_15_modules; |
| 6 | + |
| 7 | +BEGIN |
| 8 | +{ |
| 9 | + $pg_15_modules = eval |
| 10 | + { |
| 11 | + require PostgreSQL::Test::Cluster; |
| 12 | + require PostgreSQL::Test::Utils; |
| 13 | + return 1; |
| 14 | + }; |
| 15 | + |
| 16 | + unless (defined $pg_15_modules) |
| 17 | + { |
| 18 | + $pg_15_modules = 0; |
| 19 | + |
| 20 | + require PostgresNode; |
| 21 | + require TestLib; |
| 22 | + } |
| 23 | +} |
| 24 | + |
| 25 | +note('PostgreSQL 15 modules are used: ' . ($pg_15_modules ? 'yes' : 'no')); |
| 26 | + |
| 27 | +my $node; |
| 28 | +my $res_stdout; |
| 29 | +my $res_stderr; |
| 30 | + |
| 31 | +# Create node. |
| 32 | +# Older versions of PostgreSQL modules use get_new_node function. |
| 33 | +# Newer use standard perl object constructor syntax. |
| 34 | +eval |
| 35 | +{ |
| 36 | + if ($pg_15_modules) |
| 37 | + { |
| 38 | + $node = PostgreSQL::Test::Cluster->new("node"); |
| 39 | + } |
| 40 | + else |
| 41 | + { |
| 42 | + $node = PostgresNode::get_new_node("node"); |
| 43 | + } |
| 44 | +}; |
| 45 | + |
| 46 | +note "Test for handling a ptrack map in compressed relations"; |
| 47 | + |
| 48 | +my $psql_stdout; |
| 49 | + |
| 50 | +# Starting the node |
| 51 | +$node->init; |
| 52 | + |
| 53 | +# Could not load ptrack module after postmaster start |
| 54 | + |
| 55 | +my $cfs_tblspc1 = $node->basedir."/cfs_tblspc1"; |
| 56 | +my $cfs_tblspc2 = $node->basedir."/cfs_tblspc2"; |
| 57 | +mkdir $cfs_tblspc1 or die; |
| 58 | +mkdir $cfs_tblspc2 or die; |
| 59 | +my $no_cfs_tblspc1 = $node->basedir."/no_cfs_tblspc1"; |
| 60 | +my $no_cfs_tblspc2 = $node->basedir."/no_cfs_tblspc2"; |
| 61 | +mkdir $no_cfs_tblspc1 or die; |
| 62 | +mkdir $no_cfs_tblspc2 or die; |
| 63 | + |
| 64 | +$node->append_conf('postgresql.conf', qq{ |
| 65 | + shared_preload_libraries = 'ptrack' |
| 66 | + ptrack.map_size = 16 |
| 67 | + wal_level = 'replica' |
| 68 | +}); |
| 69 | + |
| 70 | +$node->start; |
| 71 | + |
| 72 | +# check cfs availability first |
| 73 | +my $cfs_available = $node->safe_psql('postgres', |
| 74 | + "select count(oid) from pg_proc where proname = 'cfs_version'"); |
| 75 | + |
| 76 | +if($cfs_available eq "0") { |
| 77 | + $node->stop; |
| 78 | + plan skip_all => "CFS is not supported by this PostgreSQL build"; |
| 79 | +} else { |
| 80 | + plan tests => 2; |
| 81 | +} |
| 82 | + |
| 83 | +# Creating content |
| 84 | +$node->safe_psql('postgres', qq| |
| 85 | + create tablespace cfs_tblspc1 location '$cfs_tblspc1' with (compression=true); |
| 86 | + create tablespace cfs_tblspc2 location '$cfs_tblspc2' with (compression=true); |
| 87 | + create tablespace no_cfs_tblspc1 location '$no_cfs_tblspc1'; |
| 88 | + create tablespace no_cfs_tblspc2 location '$no_cfs_tblspc2'; |
| 89 | +
|
| 90 | + create database testing_cfs tablespace cfs_tblspc1; |
| 91 | + create database testing_no_cfs tablespace no_cfs_tblspc1; |
| 92 | +|); |
| 93 | + |
| 94 | +$node->safe_psql('testing_cfs', qq{ |
| 95 | + create table testing(i int, text varchar); |
| 96 | + insert into testing select 1, '1111111111111111111111111' from generate_series(1,10000000); |
| 97 | +}); |
| 98 | + |
| 99 | +$node->safe_psql('testing_no_cfs', qq{ |
| 100 | + create table testing_no(i int, text varchar); |
| 101 | + insert into testing_no select 1, '1111111111111111111111111' from generate_series(1,10000000); |
| 102 | +}); |
| 103 | + |
| 104 | +# creating ptrack |
| 105 | +$node->safe_psql('postgres', "create extension ptrack"); |
| 106 | + |
| 107 | +# obtaining init lsn for further usage in ptrack_get_pagemapset |
| 108 | +my $init_lsn = $node->safe_psql('postgres', 'select ptrack_init_lsn()'); |
| 109 | + |
| 110 | +# forcing copydir() hook by altering dbs tablespaces |
| 111 | +$node->safe_psql('postgres', "alter database testing_cfs set tablespace cfs_tblspc2;"); |
| 112 | +$node->safe_psql('postgres', "alter database testing_no_cfs set tablespace no_cfs_tblspc2;"); |
| 113 | + |
| 114 | +# obtaining relpath for cfs table |
| 115 | +my $cfs_relpath = $node->safe_psql('testing_cfs', "select pg_relation_filepath('testing');"); |
| 116 | + |
| 117 | +# obtaining relpath for no-cfs table |
| 118 | +my $no_cfs_relpath = $node->safe_psql('testing_no_cfs', "select pg_relation_filepath('testing_no');"); |
| 119 | + |
| 120 | +# select the pagecount sums and compare them (should be equal) |
| 121 | +my $pagecount_sum_cfs = $node->safe_psql('postgres', |
| 122 | + "select sum(pagecount) from ptrack_get_pagemapset('$init_lsn'::pg_lsn) where path like '%$cfs_relpath%';"); |
| 123 | +my $pagecount_sum_no_cfs = $node->safe_psql('postgres', |
| 124 | + "select sum(pagecount) from ptrack_get_pagemapset('$init_lsn'::pg_lsn) where path like '%$no_cfs_relpath%';"); |
| 125 | + |
| 126 | +is($pagecount_sum_cfs, $pagecount_sum_no_cfs, "pagecount sums don't match"); |
| 127 | + |
| 128 | +# forcing copydir() hook by altering dbs tablespaces back |
| 129 | +$node->safe_psql('postgres', "alter database testing_cfs set tablespace cfs_tblspc1;"); |
| 130 | +$node->safe_psql('postgres', "alter database testing_no_cfs set tablespace no_cfs_tblspc1;"); |
| 131 | + |
| 132 | +# obtaining new relpath for cfs table |
| 133 | +$cfs_relpath = $node->safe_psql('testing_cfs', "select pg_relation_filepath('testing');"); |
| 134 | + |
| 135 | +# obtaining new relpath for no-cfs table |
| 136 | +$no_cfs_relpath = $node->safe_psql('testing_no_cfs', "select pg_relation_filepath('testing_no');"); |
| 137 | + |
| 138 | +# select the pagecount sums and compare them (again, they should be equal) |
| 139 | +$pagecount_sum_cfs = $node->safe_psql('postgres', |
| 140 | + "select sum(pagecount) from ptrack_get_pagemapset('$init_lsn'::pg_lsn) where path like '%$cfs_relpath%';"); |
| 141 | +$pagecount_sum_no_cfs = $node->safe_psql('postgres', |
| 142 | + "select sum(pagecount) from ptrack_get_pagemapset('$init_lsn'::pg_lsn) where path like '%$no_cfs_relpath%';"); |
| 143 | + |
| 144 | +is($pagecount_sum_cfs, $pagecount_sum_no_cfs, "pagecount sums don't match"); |
| 145 | + |
| 146 | + |
| 147 | +$node->stop; |
| 148 | + |
0 commit comments