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 1oIRVz-0004ng-I3 for pgsql-general@arkaria.postgresql.org; Mon, 01 Aug 2022 09:15:08 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oIRVy-0007tB-FK for pgsql-general@arkaria.postgresql.org; Mon, 01 Aug 2022 09:15:06 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oHRUy-0007Sr-BY for pgsql-general@lists.postgresql.org; Fri, 29 Jul 2022 15:01:56 +0000 Received: from mta1.nexign.com ([91.210.7.4]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oHRUq-0007mZ-O2 for pgsql-general@lists.postgresql.org; Fri, 29 Jul 2022 15:01:54 +0000 Received: from mta1.nexign.com (localhost [127.0.0.1]) by mta1.nexign.com (Postfix) with ESMTP id 913EB100014 for ; Fri, 29 Jul 2022 18:01:45 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nexign.com; s=mta; t=1659106905; bh=M8XAm2wh45SeDpD/htZCMUk+5NjfoUZsDj7uhf5Nxms=; h=From:To:Subject:Date:Message-ID:Content-Type:MIME-Version; b=P6ekMzi/sWiyf21RRmVkig+ak9ENVB/BqG5n9/hjRP6WZA8zdDoMgO2ScVr2BNsbw OOsaGJ5YXI5/Wa9vrrrK37bWVQ+eXGEnkU7d0NLijmeK3B/5TzfVRWHgCa5omb0jb9 L3YKPxBUHF/g1FWur2eAqvokuBfYc0dvBPH4ot5mHCQN5Jpwo0t3nSj943gyJS3F9W kiF+v7DzPvBkHueLt1B6ly9eNC0DTo0R749Eg+bOhT6OM1Koe0QIIZazPIwUC7+3Ng xhbY118AUiCNYBjkZo74WemXOp5J9ct22eTKiNj7VP3NvygeGIFBXZDMOS7GJuuwUe TWNM0DiTy7yfQ== Received: from srv-exch2.billing.ru (srv-exch2.billing.ru [172.25.0.123]) by mta1.nexign.com (Postfix) with ESMTP for ; Fri, 29 Jul 2022 18:01:45 +0300 (MSK) Received: from srv-exch2.billing.ru (172.25.0.123) by srv-exch2.billing.ru (172.25.0.123) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.9; Fri, 29 Jul 2022 18:01:45 +0300 Received: from srv-exch2.billing.ru ([fe80::8926:6bc4:6ad3:1f33]) by srv-exch2.billing.ru ([fe80::8926:6bc4:6ad3:1f33%8]) with mapi id 15.02.1118.009; Fri, 29 Jul 2022 18:01:45 +0300 From: "Lahnov, Igor" To: "pgsql-general@lists.postgresql.org" CC: "Timonin, Alexey" , "Dmitriyev, Andrey" , "Vassiliev, Andrey" Subject: Unable to start replica after failover Thread-Topic: Unable to start replica after failover Thread-Index: AdijWnx+0o7hJYgWQoeVD4B/HJsOZw== Date: Fri, 29 Jul 2022 15:01:44 +0000 Message-ID: Accept-Language: ru-RU, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [192.168.93.54] Content-Type: multipart/alternative; boundary="_000_c0085e0f801d4bda9e50b46c496311b3nexigncom_" MIME-Version: 1.0 X-KSMG-Rule-ID: 14 X-KSMG-Message-Action: clean X-KSMG-AntiSpam-Status: not scanned, disabled by settings X-KSMG-AntiSpam-Interceptor-Info: not scanned X-KSMG-AntiPhishing: not scanned, disabled by settings X-KSMG-AntiVirus: Kaspersky Secure Mail Gateway, version 1.1.2.30, bases: 2022/07/29 12:44:00 #19999695 X-KSMG-AntiVirus-Status: Clean, skipped List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --_000_c0085e0f801d4bda9e50b46c496311b3nexigncom_ Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Hi, We're using asynchronous streaming replication together with WAL archiving = and recovery (we've set these parameters: archive_command, restore_command,= recovery_target_timeline=3Dlatest). To manage backup and recovery, we're using pg_probackup. We have a 3-node cluster managed by Patroni on Raft. While running our cluster, we encounter a recurring problem: after a failov= er, the former leader cannot recover neither via the tools provided by Post= greSQL nor with the Patroni tools (pg_rewind). We've seen a number of different WAL reading errors. For example: * "could not find previous WAL record at E6F/C2436F50: invalid reso= urce manager ID 139 at E6F/C2436F50"; or * "could not find previous WAL record at 54E/FB348118: unexpected p= ageaddr 54E/7B34A000 in log segment 000000050000054E000000FB, offset 344883= 2". There have been some other variations but all such errors have the same cau= se: 1. At startup, the former leader does not immediately get access to t= he backup. As a result, the recovery process uses the local WAL, which inev= itably leads to a split brain since in most cases there is a lag in replica= tion after a failover. 2. Next, the former leader finally manages to read the latest log fro= m the backup, and that log has a higher priority than the local log, even t= hough the recovery with the local log has already occurred. As a result, we see the following: "new timeline 3 forked off current database system timeline 2 before curren= t recovery point 54E/FB348150". When pg_rewind is run, it also uses the log from the backup (the lagging lo= g from the new leader) instead of the partial log with which the former lea= der has already been started. Next, pg_rewind returns errors while reading the log from the backup back, = looking for the last checkpoint, which is quite reasonable because, once a = new leader starts, the point of divergence normally ends up in the next tim= eline and the previous timeline's backup log does not have a block with the= LSN of the divergence. Also, in this case, it is impossible to build a map of the pages that have = been changed to roll back the changes using pg_rewind. To avoid the problem, we decided to stop using restore_command. Could you p= lease let us know if there is a better solution to the problem we've descri= bed? --_000_c0085e0f801d4bda9e50b46c496311b3nexigncom_ Content-Type: text/html; charset="us-ascii" Content-Transfer-Encoding: quoted-printable

Hi,

We're using asynchronous streaming replic= ation together with WAL archiving and recovery (we've set these parameters: ar= chive_command, restore_command, recovery_target_tim= eline=3Dlatest).

To manage backup and recovery, we're using pg_= probackup.

We have a 3-node cluster managed by Patroni on= Raft.

While running our cluster, we encounter a recu= rring problem: after a failover, the former leader cannot recover neither via the tools provided by PostgreSQL nor wit= h the Patroni tools (pg_rewind).

We've seen a number of different WAL reading e= rrors. For example:

·&nbs= p;        "c= ould not find previous WAL record at E6F/C2436F50: invalid resource manager= ID 139 at E6F/C2436F50"; or

·&nbs= p;        "c= ould not find previous WAL record at 54E/FB348118: unexpected pageaddr 54E/= 7B34A000 in log segment 000000050000054E000000FB, offset 3448832".

There have been some other variations but all = such errors have the same cause:

1.&nb= sp;      At star= tup, the former leader does not immediately get access to the backup. As a = result, the recovery process uses the local WAL, which inevitably leads to a split brain since in most cases the= re is a lag in replication after a failover.

2.&nb= sp;      Next, t= he former leader finally manages to read the latest log from the backup, an= d that log has a higher priority than the local log, even though the recovery with the local log has already occ= urred.

As a result, we see the following:<= /span>

"new timeline 3 forked off current databa= se system timeline 2 before current recovery point 54E/FB348150".

When pg_rewind is run, it also uses the log fr= om the backup (the lagging log from the new leader) instead of the partial log with which the former leader has al= ready been started.

Next, pg_rewind returns errors while reading t= he log from the backup back, looking for the last checkpoint, which is quite reasonable because, once a new leader = starts, the point of divergence normally ends up in the next timeline and t= he previous timeline's backup log does not have a block with the LSN of the= divergence.

Also, in this case, it is impossible to build = a map of the pages that have been changed to roll back the changes using pg_rewind.

 

To avoid the problem, we decided to stop using=  restore_command. Could you please let us know if there is a better solution to the problem = we've described?

 

--_000_c0085e0f801d4bda9e50b46c496311b3nexigncom_--