Skip to content

Commit 123828a

Browse files
committed
Test replay of regression tests.
Add a new TAP test under src/test/recovery to run the standard regression tests while a streaming replica replays the WAL. This provides a basic workout for WAL decoding and redo code, and compares the replicated result. Optionally, enable (expensive) wal_consistency_checking if listed in the env variable PG_TEST_EXTRA. Reviewed-by: 綱川 貴之 (Takayuki Tsunakawa) <tsunakawa.takay@fujitsu.com> Reviewed-by: Andres Freund <andres@anarazel.de> Reviewed-by: Andrew Dunstan <andrew@dunslane.net> Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us> Reviewed-by: Anastasia Lubennikova <lubennikovaav@gmail.com> Reviewed-by: Michael Paquier <michael@paquier.xyz> Discussion: https://postgr.es/m/CA%2BhUKGKpRWQ9SxdxxDmTBCJoR0YnFpMBe7kyzY8SUQk%2BHeskxg%40mail.gmail.com
1 parent d1511fe commit 123828a

File tree

4 files changed

+98
-1
lines changed

4 files changed

+98
-1
lines changed

doc/src/sgml/regress.sgml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,17 @@ make check-world PG_TEST_EXTRA='kerberos ldap ssl'
289289
</para>
290290
</listitem>
291291
</varlistentry>
292+
293+
<varlistentry>
294+
<term><literal>wal_consistency_checking</literal></term>
295+
<listitem>
296+
<para>
297+
Uses <literal>wal_consistency_checking=all</literal> while running
298+
certain tests under <filename>src/test/recovery</filename>. Not
299+
enabled by default because it is resource intensive.
300+
</para>
301+
</listitem>
302+
</varlistentry>
292303
</variablelist>
293304

294305
Tests for features that are not supported by the current build

src/test/recovery/Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,14 @@ subdir = src/test/recovery
1515
top_builddir = ../../..
1616
include $(top_builddir)/src/Makefile.global
1717

18-
# required for 017_shm.pl
18+
# required for 017_shm.pl and 027_stream_regress.pl
1919
REGRESS_SHLIB=$(abs_top_builddir)/src/test/regress/regress$(DLSUFFIX)
2020
export REGRESS_SHLIB
2121

22+
# required for 027_stream_regress.pl
23+
REGRESS_OUTPUTDIR=$(abs_top_builddir)/src/test/recovery
24+
export REGRESS_OUTPUTDIR
25+
2226
check:
2327
$(prove_check)
2428

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
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} . " " .
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+
$extra_opts);
56+
57+
# Clobber all sequences with their next value, so that we don't have
58+
# differences between nodes due to caching.
59+
$node_primary->psql('regression',
60+
"select setval(seqrelid, nextval(seqrelid)) from pg_sequence");
61+
62+
# Wait for standby to catch up
63+
$node_primary->wait_for_catchup($node_standby_1, 'replay',
64+
$node_primary->lsn('insert'));
65+
66+
# Perform a logical dump of primary and standby, and check that they match
67+
command_ok(
68+
[ 'pg_dumpall', '-f', $outputdir . '/primary.dump', '--no-sync',
69+
'-p', $node_primary->port ],
70+
'dump primary server');
71+
command_ok(
72+
[ 'pg_dumpall', '-f', $outputdir . '/standby.dump', '--no-sync',
73+
'-p', $node_standby_1->port ],
74+
'dump standby server');
75+
command_ok(
76+
[ 'diff', $outputdir . '/primary.dump', $outputdir . '/standby.dump' ],
77+
'compare primary and standby dumps');
78+
79+
$node_standby_1->stop;
80+
$node_primary->stop;

src/tools/msvc/vcregress.pl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,8 @@ sub recoverycheck
536536
{
537537
InstallTemp();
538538

539+
$ENV{REGRESS_OUTPUTDIR} = "$topdir/src/test/recovery";
540+
539541
my $mstat = 0;
540542
my $dir = "$topdir/src/test/recovery";
541543
my $status = tap_check($dir);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy