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 1oQUwL-0004H7-28 for pgsql-general@arkaria.postgresql.org; Tue, 23 Aug 2022 14:31:37 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oQUwJ-0008Uz-V3 for pgsql-general@arkaria.postgresql.org; Tue, 23 Aug 2022 14:31:35 +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 1oQT4g-0003Ua-HG for pgsql-general@lists.postgresql.org; Tue, 23 Aug 2022 12:32:06 +0000 Received: from mta1.nexign.com ([91.210.7.4]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oQT4b-00088W-KU for pgsql-general@lists.postgresql.org; Tue, 23 Aug 2022 12:32:05 +0000 Received: from mta1.nexign.com (localhost [127.0.0.1]) by mta1.nexign.com (Postfix) with ESMTP id 7A3FA100014; Tue, 23 Aug 2022 15:32:00 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nexign.com; s=mta; t=1661257920; bh=DBqlNxuI76v/b3w+BWcPSm/Wo2sbaOJb8DkXAdYnFus=; h=From:To:Subject:Date:Message-ID:Content-Type:MIME-Version; b=MDAXnFq9s6CZ595MBW69CgNX7hvh4hkt9ZrbGLkG/LmkJzfA9ALM9HEjOjTYtn2OE teb3qLRV9ZDdkR0kEXRXZv2y6iaq1hwqPWnaQ8oeG1BxTbta5ZeoxqG2OtLzE++jt3 /+qGdB8Da/NwijTmNym+xz6nubujf2Oe+xSgyV2v9o9IJVXOGx5hpqUbGOdCVqpD7O z6SJIzUFuUvQIR3iG2FeIyl0FMxdWfaF4C9APy2zu8r7vch8+rEshkRAS4/HE1xbEl RT3RXsHRTTJ4uqE6117r55qFLpDRfBtNZxrwzD8/Z+/WD+P4cYgZjlNsg//Idp3vTB GX0q0qBSrbq8g== Received: from srv-exch2.billing.ru (srv-exch2.billing.ru [172.25.0.123]) by mta1.nexign.com (Postfix) with ESMTP; Tue, 23 Aug 2022 15:32:00 +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; Tue, 23 Aug 2022 15:31:59 +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; Tue, 23 Aug 2022 15:31:59 +0300 From: "Lahnov, Igor" To: Kyotaro Horiguchi CC: "pgsql-general@lists.postgresql.org" , "Timonin, Alexey" , "Dmitriyev, Andrey" , "Vassiliev, Andrey" Subject: RE: Unable to start replica after failover Thread-Topic: Unable to start replica after failover Thread-Index: AdijWnx+0o7hJYgWQoeVD4B/HJsOZwEaMqQAAjbN1tABf8KegAAMVm5Q Date: Tue, 23 Aug 2022 12:31:59 +0000 Message-ID: References: <20220804.173016.1842863543105077523.horikyota.ntt@gmail.com> <20220823.150753.1388779380039481878.horikyota.ntt@gmail.com> In-Reply-To: <20220823.150753.1388779380039481878.horikyota.ntt@gmail.com> Accept-Language: ru-RU, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [192.168.93.38] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable 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/08/23 08:27:00 #20145130 X-KSMG-AntiVirus-Status: Clean, skipped List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk We know what the problem is, but don't know how to solve it correctly. After failover, *new leader* promoted and read local partial log to LSN 54E= /FB348118 -> 2022-05-23 01:47:52.124 [12088] LOG: record with incorrect prev-link 0/100 = at 54E/FB348118 2022-05-23 01:47:52.124 [12088] LOG: redo done at 54E/FB3480F0 system usage= : CPU: user: 321.21 s, system: 144.77 s, elapsed: 354977.44 s rmgr: XLOG len (rec/tot): 42/ 42, tx: 0, lsn: 54E/FB348118, prev 54E/FB3480= F0, desc: END_OF_RECOVERY tli 3; prev tli 2; time 2022-05-23 01:47:53.34210= 0=20 2022-05-23 01:47:52.900 [12088] LOG: selected new timeline ID: 3 2022-05-23 01:47:53.658 [12084] LOG: database system is ready to accept con= nections <- The *previous leader* started after a failure and read the local partial lo= g to LSN 54E/FB348150 -> 2022-05-23 01:50:12.945 [122891] LOG: redo starts at 54E/F97F4878 2022-05-23 01:50:13.010 [122891] LOG: invalid record length at 54E/FB348150= : wanted 24, got 0 2022-05-23 01:50:13.011 [122891] LOG: consistent recovery state reached at = 54E/FB348150 2022-05-23 01:50:13.012 [122883] LOG: database system is ready to accept re= ad-only connections <- Our 'restore_command' on *previous leader* restores a partial file from arc= hive (from *new leader*) -> 2022-05-23 01:50:14 [123730]: [1-1]: INFO: pg_probackup archive-get WAL fil= e: 000000020000054E000000FB, remote: ssh, threads: 1/1, batch: 1 <- And this file has a higher priority than the original local partial file on= the * previous leader*. And this leads to the problem: --- 2022-05-23 01:50:14.448 [122891] LOG: new timeline 3 forked off current dat= abase system timeline 2 before current recovery point 54E/FB348150 --- And pg_rewind tries to use this file (from *new leader*) to build a map of = pages that have changed since the last checkpoint --- 2022-05-23 01:51:32,202 INFO: Lock owner: pg51; I am pg01 2022-05-23 01:51:32,209 INFO: Local timeline=3D2 lsn=3D54E/FB348150 2022-05-23 01:51:32,252 INFO: master_timeline=3D3 2022-05-23 01:51:32,254 INFO: master: history=3D1 53E/FD65D298 no recovery = target specified 2 54E/FB348118 no recovery target specified 2022-05-23 01:51:32,499 INFO: running pg_rewind from pg51 2022-05-23 01:51:32,574 INFO: running pg_rewind from dbname=3Dpostgres user= =3Dpostgres host=3D IP port=3D5432 target_session_attrs=3Dread-write 2022-05-23 01:51:32,640 INFO: pg_rewind exit code=3D1 2022-05-23 01:51:32,640 INFO: stdout=3D 2022-05-23 01:51:32,640 INFO: stderr=3Dpg_rewind: servers diverged at WAL l= ocation 54E/FB348118 on timeline 2 pg_rewind: fatal: could not find previous WAL record at 54E/FB348118: unexp= ected pageaddr 54E/7B34A000 in log segment 000000020000054E000000FB, offset= 3448832 --- We checked this log (from *new leader*), and when direct reading, the outpu= t like this: --- record with incorrect prev-link 0/100 at 54E/FB348118 ---- when backward reading: --- 54E/FB348118: unexpected pageaddr 54E/7B34A000 in log segment 0000000200000= 54E000000FB, offset 3448832 --- Now we have disabled restore_command, but I think it's not best solution. W= hat the correct solution in this case?