Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jTZQh-0006sR-Bl for pgsql-hackers@arkaria.postgresql.org; Tue, 28 Apr 2020 23:14:19 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jTZQg-0000BV-9S for pgsql-hackers@arkaria.postgresql.org; Tue, 28 Apr 2020 23:14:18 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jTZQg-0000BO-0b for pgsql-hackers@lists.postgresql.org; Tue, 28 Apr 2020 23:14:18 +0000 Received: from mail-qv1-xf41.google.com ([2607:f8b0:4864:20::f41]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1jTZQd-0007Q3-Bk for pgsql-hackers@lists.postgresql.org; Tue, 28 Apr 2020 23:14:17 +0000 Received: by mail-qv1-xf41.google.com with SMTP id di6so237396qvb.10 for ; Tue, 28 Apr 2020 16:14:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :content-transfer-encoding:in-reply-to:user-agent; bh=U+l+t5+06+tXgbWohXBkgobwMMaxa7+LfM4HrZ4aB+U=; b=nzvbNoXSOdBpjBJQ3gBe21Gd9+7KQyHHa4J0/0dIeHmWh6EEY0g+PKm3pVtP8Swfy9 xh2ftdLjBnlYXVpU40iXUjRqgOFL+vLEkmFMncZ1LIvzrDxeW5YJ4voTyr6faScJZedn u33uLgzyTt4IwnRmggTaygw8d+ZbIxFkB++OnGPJbOCwfmwBpyf198h5IA2X74xr/qkp 2gRXtXnmilosk7EpxlqJxFT9neYqKMFFRqbfY5dhfFizv26o1y56/F+9o70LsZyBmUyG /HeLky3eyfWB0azySkcjswhOirvkM9icoJMXqhc/e6l0WZxM/lY/yikegc3mkVUPPKQJ MRvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=U+l+t5+06+tXgbWohXBkgobwMMaxa7+LfM4HrZ4aB+U=; b=r1pBGjSiS7iWTKNbV6FBOq4A08qDrXNl0+tCEVeUgnerrDS19iMsYzX7xH61pbcimU IExCJgNPjmOobACmimMCgjmu8o4mNxdbUr2JoqIxaExfOK/OTM+aNy+z7kReizlBLZdd lE0tU1cvQMMZdnzWPv/s7rGkqjoB4UN2EWfr9lqkNIZFBPAmVzsRYJE+waSHVkgvtG6H TQ5XvpjxOxPNvsGKG2BQtLab97UUTLD5AorxNIjTImiBxj5PR8wLP5fdY0Xj9LLb4T8Z QPN2l45V8BaQQMF+CWRVUcqz++9VoNi7DaAdEaK37pTZ7xAYhF2yxW7tKapuA3cPdvN2 4eJA== X-Gm-Message-State: AGi0PubJ53X+hzkqASC64B9KqMCJnL4t1M6UFWHi6k+4cwul6ECG58gF x7ALnT6nd/0DkJZr7G2EZrDP5g== X-Google-Smtp-Source: APiQypI2ZlkdnO8UMHmnFBhTx8m8RFCsYQo4jAvk8bWx6xm+xzs3CdZwB44qYjEzkh1posPVkdzAgA== X-Received: by 2002:a0c:f991:: with SMTP id t17mr30323056qvn.233.1588115653974; Tue, 28 Apr 2020 16:14:13 -0700 (PDT) Received: from nimloth.alvh.no-ip.org ([190.95.18.252]) by smtp.gmail.com with ESMTPSA id d4sm14187181qtw.25.2020.04.28.16.14.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Apr 2020 16:14:12 -0700 (PDT) Received: by nimloth.alvh.no-ip.org (Postfix, from userid 1000) id C84B43007E7; Tue, 28 Apr 2020 19:14:10 -0400 (-04) Date: Tue, 28 Apr 2020 19:14:10 -0400 From: Alvaro Herrera To: Kyotaro Horiguchi Cc: jgdr@dalibo.com, andres@anarazel.de, michael@paquier.xyz, sawada.mshk@gmail.com, peter.eisentraut@2ndquadrant.com, pgsql-hackers@lists.postgresql.org, thomas.munro@enterprisedb.com, sk@zsrv.org, michael.paquier@gmail.com Subject: Re: [HACKERS] Restricting maximum keep segments by repslots Message-ID: <20200428231410.GA9805@alvherre.pgsql> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="CE+1k2dSO48ffgeK" Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20200428.171815.1687900483771598932.horikyota.ntt@gmail.com> User-Agent: Mutt/1.10.1 (2018-07-13) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --CE+1k2dSO48ffgeK Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit On 2020-Apr-28, Kyotaro Horiguchi wrote: > > Anyway I think this patch should fix it also -- instead of adding a new > > flag, we just rely on the existing flags (since do_checkpoint must have > > been set correctly from the flags earlier in that block.) > > Since the added (!do_checkpoint) check is reached with > do_checkpoint=false at server start and at archive_timeout intervals, > the patch makes checkpointer run a busy-loop at that timings, and that > loop lasts until a checkpoint is actually executed. > > What we need to do here is not forgetting the fact that the latch has > been set even if the latch itself gets reset before reaching to > WaitLatch. After a few more false starts :-) I think one easy thing we can do without the additional boolean flag is to call SetLatch there in the main loop if we see that ckpt_flags is nonzero. (I had two issues with the boolean flag. One is that the comment in ReqCheckpointHandler needed an update to, essentially, say exactly the opposite of what it was saying; such a change was making me very uncomfortable. The other is that the place where the flag was reset in CheckpointerMain() was ... not really appropriate; or it could have been appropriate if the flag was called, say, "CheckpointerMainNoSleepOnce". Because "RequestPending" was the wrong name to use, because if the flag was for really request pending, then we should reset it inside the "if do_checkpoint" block .. but as I understand this would cause the busy-loop behavior you described.) > The attached patch on 019_replslot_limit.pl does the commands above > automatically. It sometimes succeed but fails in most cases, at least > for me. With the additional SetLatch, the test passes reproducibly for me. Before the patch, it failed ten out of ten times I ran it. -- Álvaro Herrera https://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services --CE+1k2dSO48ffgeK Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="0001-Fix-checkpoint-signalling.patch" From 74751b6a3a049ff83c6bef99e2e39562278a7ba6 Mon Sep 17 00:00:00 2001 From: Alvaro Herrera Date: Mon, 27 Apr 2020 19:35:15 -0400 Subject: [PATCH] Fix checkpoint signalling Because the checkpointer process now uses its MyLatch to wait for walsenders to go away (per commit c6550776394e), we must ensure to nudge it when going to sleep. --- src/backend/postmaster/checkpointer.c | 8 +++++ src/test/recovery/t/019_replslot_limit.pl | 44 +++++++++++++++++++++-- 2 files changed, 50 insertions(+), 2 deletions(-) diff --git a/src/backend/postmaster/checkpointer.c b/src/backend/postmaster/checkpointer.c index e354a78725..94e0161162 100644 --- a/src/backend/postmaster/checkpointer.c +++ b/src/backend/postmaster/checkpointer.c @@ -494,6 +494,14 @@ CheckpointerMain(void) */ pgstat_send_bgwriter(); + /* + * If any checkpoint flags have been set, nudge our latch so that the + * wait below will return immediately, even if a latch signal was + * consumed elsewhere. + */ + if (((volatile CheckpointerShmemStruct *) CheckpointerShmem)->ckpt_flags) + SetLatch(MyLatch); + /* * Sleep until we are signaled or it's time for another checkpoint or * xlog file switch. diff --git a/src/test/recovery/t/019_replslot_limit.pl b/src/test/recovery/t/019_replslot_limit.pl index 32dce54522..634f2bec8b 100644 --- a/src/test/recovery/t/019_replslot_limit.pl +++ b/src/test/recovery/t/019_replslot_limit.pl @@ -8,7 +8,7 @@ use TestLib; use PostgresNode; use File::Path qw(rmtree); -use Test::More tests => 13; +use Test::More tests => 14; use Time::HiRes qw(usleep); $ENV{PGDATABASE} = 'postgres'; @@ -179,7 +179,47 @@ for (my $i = 0; $i < 10000; $i++) } ok($failed, 'check that replication has been broken'); -$node_standby->stop; +$node_master->stop('immediate'); +$node_standby->stop('immediate'); + +my $node_master2 = get_new_node('master2'); +$node_master2->init(allows_streaming => 1); +$node_master2->append_conf( + 'postgresql.conf', qq( +min_wal_size = 32MB +max_wal_size = 32MB +log_checkpoints = yes +)); +$node_master2->start; +$node_master2->safe_psql('postgres', + "SELECT pg_create_physical_replication_slot('rep1')"); +$backup_name = 'my_backup2'; +$node_master2->backup($backup_name); + +$node_master2->stop; +$node_master2->append_conf( + 'postgresql.conf', qq( +max_slot_wal_keep_size = 0 +)); +$node_master2->start; + +$node_standby = get_new_node('standby_2'); +$node_standby->init_from_backup($node_master2, $backup_name, + has_streaming => 1); +$node_standby->append_conf('postgresql.conf', "primary_slot_name = 'rep1'"); +$node_standby->start; +my @result = + split( + '\n', + $node_master2->safe_psql( + 'postgres', + "CREATE TABLE tt(); + DROP TABLE tt; + SELECT pg_switch_wal(); + CHECKPOINT; + SELECT 'finished';", + timeout => '60')); +is($result[1], 'finished', 'check if checkpoint command is not blocked'); ##################################### # Advance WAL of $node by $n segments -- 2.20.1 --CE+1k2dSO48ffgeK--