Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rpDEz-005cXg-8o for pgsql-hackers@arkaria.postgresql.org; Tue, 26 Mar 2024 20:17:50 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1rpDEx-0051Ol-GA for pgsql-hackers@arkaria.postgresql.org; Tue, 26 Mar 2024 20:17:47 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rpDEv-0051Oc-Qc for pgsql-hackers@lists.postgresql.org; Tue, 26 Mar 2024 20:17:47 +0000 Received: from fout7-smtp.messagingengine.com ([103.168.172.150]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rpDEm-006aK3-O7 for pgsql-hackers@lists.postgresql.org; Tue, 26 Mar 2024 20:17:44 +0000 Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailfout.nyi.internal (Postfix) with ESMTP id 4EC7F1380108; Tue, 26 Mar 2024 16:17:36 -0400 (EDT) Received: from imap49 ([10.202.2.99]) by compute2.internal (MEProxy); Tue, 26 Mar 2024 16:17:36 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=eulerto.com; h= cc:cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1711484256; x=1711570656; bh=0lKoe1Vlaw JDKfA7UWgZbjwm8xoHQpFPZMJWk3f4BPU=; b=Q2wVe2nN6z3NWL3r76XtZP6hcj D+K0xtlDsgE6qIc7XE/I9CCMLpNS0lrKAUHGmFR1u0x8LVyUnUUMGHJhghURi2ZD p9n6Vx99PHzt3BkN+eqWwt9h+M16opipwlhxdx/kOH/47nVrI+pwJjsmOfrSBKQA XeE/ExFjR4Am6/ojdOchaN6rl7/a4R3T8g1mak5PvpW9brv0UMydJvEkektgGNrD 87tESsEFSBLDD5EEA92CAOzBgB8BMqod58m/MNWM51XpC+5ZNnyn8QY8a09RXUu9 dUobUUWG+ZeVcz12GbhNnAGt9zJ4CPfd73ABgx47fQwitKc9VndRVKR3cSiQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm2; t=1711484256; x=1711570656; bh=0lKoe1VlawJDKfA7UWgZbjwm8xoH QpFPZMJWk3f4BPU=; b=iC1S7WBZeCroDCY6dYrCJda/lk5E/m3LRvPqtQ2BUfO6 V7N/sANs6hx8cF6oEqT7yRtIz4MAMgvfqZNxfhClpXVFAccijbuuQ3ebggJAbDo2 J7TememT2QvVbmD84sdTpEdsQsP8TZfL3eRGzqYwKyyySetOzWqLnzertRiMz9WK M8q7n2nTbTPdap5sB2QNVe16AvZaYqFg3SPyacwgJOZVc9znADM8OkiKbAQJ+Ay5 WjtT47xLnWAH8thEwFml9c2SpBHl9Ut1YQF3qx2J7IEH44SbCAewAoBfKH4o4Zj3 psC4piZBKuC0OpD97yGfr67Ptdrhx5gsz+2RvxnYOA== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledruddufedgudefhecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefofgggkfgjfhffhffvvefutgesrgdtreerreertdenucfhrhhomhepfdfg uhhlvghrucfvrghvvghirhgrfdcuoegvuhhlvghrsegvuhhlvghrthhordgtohhmqeenuc ggtffrrghtthgvrhhnpeehvdevueeljeekfeeliefhfeefgfffgeeufefhvdeugedttdeg vdehuedvgfdugfenucffohhmrghinhepphhoshhtghhrvghsqhhlrdhorhhgpdgvnhhtvg hrphhrihhsvggusgdrtghomhenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhep mhgrihhlfhhrohhmpegvuhhlvghrsegvuhhlvghrthhordgtohhm X-ME-Proxy: Feedback-ID: i0c21471d:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id 7BD5315A0092; Tue, 26 Mar 2024 16:17:35 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.11.0-alpha0-328-gc998c829b7-fm-20240325.002-gc998c829 MIME-Version: 1.0 Message-Id: In-Reply-To: <47524383-6fd1-4b13-8c4e-fb918b1d35ba@enterprisedb.com> References: <9a9c7e65-c47b-4400-a63e-ac6169c0860e@app.fastmail.com> <2f0b73f3-e7c0-4e95-9712-1993442a6b64@app.fastmail.com> <34637e7f-0330-420d-8f45-1d022962d2fe@app.fastmail.com> <7a970912-0b77-4942-84f7-2c9ca0bc05a5@eisentraut.org> <44de4e04-db22-40ed-8ba9-46387dc8bf83@app.fastmail.com> <3fa9ef0f-b277-4c13-850a-8ccc04de1406@eisentraut.org> <65b841a8-0c2f-4953-b9cd-240fce84b90b@eisentraut.org> <47524383-6fd1-4b13-8c4e-fb918b1d35ba@enterprisedb.com> Date: Tue, 26 Mar 2024 17:17:15 -0300 From: "Euler Taveira" To: "Tomas Vondra" , "kuroda.hayato@fujitsu.com" , "Peter Eisentraut" , "Bharath Rupireddy" Cc: "Amit Kapila" , "Shlok Kyal" , "pgsql-hackers@lists.postgresql.org" , "Michael Paquier" , "Andres Freund" , "Ashutosh Bapat" , =?UTF-8?Q?Fabr=C3=ADzio_de_Royes_Mello?= , "vignesh C" Subject: Re: speed up a logical replica setup Content-Type: multipart/alternative; boundary=9f09d666ed9847f2ba258435270b2c8f List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --9f09d666ed9847f2ba258435270b2c8f Content-Type: text/plain On Tue, Mar 26, 2024, at 4:12 PM, Tomas Vondra wrote: > Perhaps I'm missing something, but why is NUM_CONN_ATTEMPTS even needed? > Why isn't recovery_timeout enough to decide if wait_for_end_recovery() > waited long enough? It was an attempt to decoupled a connection failure (that keeps streaming the WAL) from recovery timeout. The NUM_CONN_ATTEMPTS guarantees that if the primary is gone during the standby recovery process, there is a way to bail out. The recovery-timeout is 0 (infinite) by default so you have an infinite wait without this check. The idea behind this implementation is to avoid exiting in this critical code path. If it times out here you might have to rebuild the standby and start again. Amit suggested [1] that we use a value as recovery-timeout but how high is a good value? I've already saw some long recovery process using pglogical equivalent that timeout out after hundreds of minutes. Maybe I'm too worried about a small percentage of cases and we should use 1h as default, for example. It would reduce the complexity since the recovery process lacks some progress indicators (LSN is not sufficient in this case and there isn't a function to provide the current state -- stop applying WAL, reach target, new timeline, etc). If we remove the pg_stat_wal_receiver check, we should avoid infinite recovery by default otherwise we will have some reports saying the tool is hanging when in reality the primary has gone and WAL should be streamed. > IMHO the test should simply pass PG_TEST_DEFAULT_TIMEOUT when calling > pg_createsubscriber, and that should do the trick. That's a good idea. Tests are not exercising the recovery-timeout option. > Increasing PG_TEST_DEFAULT_TIMEOUT is what buildfarm animals doing > things like ubsan/valgrind already use to deal with exactly this kind of > timeout problem. > > Or is there a deeper problem with deciding if the system is in recovery? As I said with some recovery progress indicators it would be easier to make some decisions like wait a few seconds because the WAL has already been applied and it is creating a new timeline. The recovery timeout decision is a shot in the dark because we might be aborting pg_createsubscriber when the target server is about to set RECOVERY_STATE_DONE. [1] https://www.postgresql.org/message-id/CAA4eK1JRgnhv_ySzuFjN7UaX9qxz5Hqcwew7Fk%3D%2BAbJbu0Kd9w%40mail.gmail.com -- Euler Taveira EDB https://www.enterprisedb.com/ --9f09d666ed9847f2ba258435270b2c8f Content-Type: text/html Content-Transfer-Encoding: quoted-printable
On Tue, Mar 26,= 2024, at 4:12 PM, Tomas Vondra wrote:
Perhaps I'm missing something, but why is NU= M_CONN_ATTEMPTS even needed?
Why isn't recovery_timeout en= ough to decide if wait_for_end_recovery()
waited long enou= gh?

It was an attempt to decou= pled a connection failure (that keeps streaming the
WAL) f= rom recovery timeout. The NUM_CONN_ATTEMPTS guarantees that if the prima= ry
is gone during the standby recovery process, there is a= way to bail out. The
recovery-timeout is 0 (infinite) by = default so you have an infinite wait without
this check. T= he idea behind this implementation is to avoid exiting in this
=
critical code path. If it times out here you might have to rebuild = the standby
and start again. Amit suggested [1] that we us= e a value as recovery-timeout but
how high is a good value= ? I've already saw some long recovery process using
pglogi= cal equivalent that timeout out after hundreds of minutes. Maybe I'm too=
worried about a small percentage of cases and we should u= se 1h as default, for
example. It would reduce the complex= ity since the recovery process lacks some
progress indicat= ors (LSN is not sufficient in this case and there isn't a
= function to provide the current state -- stop applying WAL, reach target= , new
timeline, etc).

If we r= emove the pg_stat_wal_receiver check, we should avoid infinite recovery<= br>
by default otherwise we will have some reports saying the = tool is hanging when
in reality the primary has gone and W= AL should be streamed.

IMHO the test should simply pass PG_TEST_DEFA= ULT_TIMEOUT when calling
pg_createsubscriber, and that sho= uld do the trick.

That's a goo= d idea. Tests are not exercising the recovery-timeout option.
=
Increasing= PG_TEST_DEFAULT_TIMEOUT is what buildfarm animals doing
t= hings like ubsan/valgrind already use to deal with exactly this kind of<= br>
timeout problem.

Or is there = a deeper problem with deciding if the system is in recovery?

As I said with some recovery progress ind= icators it would be easier to make some
decisions like wai= t a few seconds because the WAL has already been applied and
it is creating a new timeline. The recovery timeout decision is a sho= t in the
dark because we might be aborting pg_createsubscr= iber when the target server is
about to set RECOVERY_STATE= _DONE.


--
Eu= ler Taveira

--9f09d666ed9847f2ba258435270b2c8f--