|
| 1 | + |
| 2 | +# Copyright (c) 2023, PostgreSQL Global Development Group |
| 3 | + |
| 4 | +# Test WAL replay for CREATE DATABASE .. STRATEGY WAL_LOG. |
| 5 | + |
| 6 | +use strict; |
| 7 | +use warnings; |
| 8 | +use PostgreSQL::Test::Cluster; |
| 9 | +use PostgreSQL::Test::Utils; |
| 10 | +use Test::More; |
| 11 | + |
| 12 | +my $node = PostgreSQL::Test::Cluster->new('node'); |
| 13 | +$node->init; |
| 14 | +$node->start; |
| 15 | + |
| 16 | +# This checks that any DDLs run on the template database that modify pg_class |
| 17 | +# are persisted after creating a database from it using the WAL_LOG strategy, |
| 18 | +# as a direct copy of the template database's pg_class is used in this case. |
| 19 | +my $db_template = "template1"; |
| 20 | +my $db_new = "test_db_1"; |
| 21 | + |
| 22 | +# Create table. It should persist on the template database. |
| 23 | +$node->safe_psql("postgres", |
| 24 | + "CREATE DATABASE $db_new STRATEGY WAL_LOG TEMPLATE $db_template;"); |
| 25 | + |
| 26 | +$node->safe_psql($db_template, "CREATE TABLE tab_db_after_create_1 (a INT);"); |
| 27 | + |
| 28 | +# Flush the changes affecting the template database, then replay them. |
| 29 | +$node->safe_psql("postgres", "CHECKPOINT;"); |
| 30 | + |
| 31 | +$node->stop('immediate'); |
| 32 | +$node->start; |
| 33 | +my $result = $node->safe_psql($db_template, |
| 34 | + "SELECT count(*) FROM pg_class WHERE relname LIKE 'tab_db_%';"); |
| 35 | +is($result, "1", |
| 36 | + "check that table exists on template after crash, with checkpoint"); |
| 37 | + |
| 38 | +# The new database should have no tables. |
| 39 | +$result = $node->safe_psql($db_new, |
| 40 | + "SELECT count(*) FROM pg_class WHERE relname LIKE 'tab_db_%';"); |
| 41 | +is($result, "0", |
| 42 | + "check that there are no tables from template on new database after crash" |
| 43 | +); |
| 44 | + |
| 45 | +done_testing(); |
0 commit comments