Skip to content

Commit ad34146

Browse files
committed
Add more TAP tests with BASE_BACKUP and pg_backup_start/stop
This commit adds some test coverage for ee79647 (prevent BASE_BACKUP from running in the middle of another base backup) and b24b2be (BASE_BACKUP cancellation followed by pg_backup_start), caused by the interactions of replication and SQL commands in a logical replication connection in a WAL sender. The second test uses a design close to what has been introduced in 0475a97, where BASE_BACKUP is throttled to give enough room for a cancellation, though this time we rely on psql with multiple -c switches to keep a connection around for the second query. Reviewed-by: Fujii Masao Discussion: https://postgr.es/m/Ys/NCI4Eo9300GnQ@paquier.xyz
1 parent 3451a57 commit ad34146

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

src/test/recovery/t/001_stream_rep.pl

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,4 +531,59 @@ sub replay_check
531531
ok(!-f "$primary_data/pg_wal/$segment_removed",
532532
"WAL segment $segment_removed recycled after physical slot advancing");
533533

534+
note "testing pg_backup_start() followed by BASE_BACKUP";
535+
my $connstr = $node_primary->connstr('postgres') . " replication=database";
536+
537+
# This test requires a replication connection with a database, as it mixes
538+
# a replication command and a SQL command.
539+
$node_primary->command_fails_like(
540+
[
541+
'psql', '-c', "SELECT pg_backup_start('backup', true)",
542+
'-c', 'BASE_BACKUP', '-d', $connstr
543+
],
544+
qr/a backup is already in progress in this session/,
545+
'BASE_BACKUP cannot run in session already running backup');
546+
547+
note "testing BASE_BACKUP cancellation";
548+
549+
my $sigchld_bb_timeout =
550+
IPC::Run::timer($PostgreSQL::Test::Utils::timeout_default);
551+
552+
# This test requires a replication connection with a database, as it mixes
553+
# a replication command and a SQL command. The first BASE_BACKUP is throttled
554+
# to give enough room for the cancellation running below. The second command
555+
# for pg_backup_stop() should fail.
556+
my ($sigchld_bb_stdin, $sigchld_bb_stdout, $sigchld_bb_stderr) = ('', '', '');
557+
my $sigchld_bb = IPC::Run::start(
558+
[
559+
'psql', '-X', '-c', "BASE_BACKUP (CHECKPOINT 'fast', MAX_RATE 32);",
560+
'-c', 'SELECT pg_backup_stop()',
561+
'-d', $connstr
562+
],
563+
'<',
564+
\$sigchld_bb_stdin,
565+
'>',
566+
\$sigchld_bb_stdout,
567+
'2>',
568+
\$sigchld_bb_stderr,
569+
$sigchld_bb_timeout);
570+
571+
# The cancellation is issued once the database files are streamed and
572+
# the checkpoint issued at backup start completes.
573+
is( $node_primary->poll_query_until(
574+
'postgres',
575+
"SELECT pg_cancel_backend(a.pid) FROM "
576+
. "pg_stat_activity a, pg_stat_progress_basebackup b WHERE "
577+
. "a.pid = b.pid AND a.query ~ 'BASE_BACKUP' AND "
578+
. "b.phase = 'streaming database files';"),
579+
"1",
580+
"WAL sender sending base backup killed");
581+
582+
# The psql command should fail on pg_backup_stop().
583+
ok( pump_until(
584+
$sigchld_bb, $sigchld_bb_timeout,
585+
\$sigchld_bb_stderr, qr/backup is not in progress/),
586+
'base backup cleanly cancelled');
587+
$sigchld_bb->finish();
588+
534589
done_testing();

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