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 1sbzT7-0031ZI-CA for pgsql-bugs@arkaria.postgresql.org; Thu, 08 Aug 2024 09:30:01 +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 1sbzT5-00D0Ml-SM for pgsql-bugs@arkaria.postgresql.org; Thu, 08 Aug 2024 09:29:59 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sbzT5-00D0Mc-GB for pgsql-bugs@lists.postgresql.org; Thu, 08 Aug 2024 09:29:59 +0000 Received: from meesny.iki.fi ([195.140.195.201]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sbzT2-003mCm-RO for pgsql-bugs@lists.postgresql.org; Thu, 08 Aug 2024 09:29:58 +0000 Received: from [192.168.1.119] (dsl-hkibng22-54f8db-125.dhcp.inet.fi [84.248.219.125]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: hlinnaka) by meesny.iki.fi (Postfix) with ESMTPSA id 4Wfhb70R87zyQm; Thu, 8 Aug 2024 12:29:53 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=meesny; t=1723109395; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=zW7j/rjcjdueTJo0RowhMELozciNOKaTOOlMhc6THvM=; b=BlLXsbz3yOe4Xn2Qu0jQhj7xAOLJwyr8DfRUPAGCRskz6GmWXyEWhOvCKVc78h07TdtdKk pw8GOIo+2gp/N/MOxxEfA1J30P5Yiy4mHbe2S3NIJQaX7ohTAddvkb7TiJumoXiC9Oy0kc PobNKIkI6TMyex4RRc9AeFW+KKxiAks= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=meesny; t=1723109395; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=zW7j/rjcjdueTJo0RowhMELozciNOKaTOOlMhc6THvM=; b=zOrD5xdSmpn4ryR0pFGRLdcHxv3pYYsGzaZbColrGLvt3pksDPhdf7je2ja0gT+Acvc6C3 yYl4sBzxc1PLOiW2yIgeierc99mzMq2BQD7hJjjIGbYLneHpwcXqrlXKjLrTzXR3ZwOeGE 1Dk7+JYkxb0IXfk22HTm+kz7OCzimdA= ARC-Seal: i=1; s=meesny; d=iki.fi; t=1723109395; a=rsa-sha256; cv=none; b=anDjonZhAupf50loqcvJyNmjiKBm5Ry3BlmzJhDiX4N/cWM2g/J1PLdnNTW6QfvKZ/2jDV pvOxtXhG7ReV6MZDfPIpiCU/6qu2tq/xMk6yffzacw51L/MATYVG/R602aNlbyGndMZQ4x JV6PU1Pfk3wB2DwzIQ+zbp/b7RXhdsk= ARC-Authentication-Results: i=1; ORIGINATING; auth=pass smtp.auth=hlinnaka smtp.mailfrom=hlinnaka@iki.fi Message-ID: Date: Thu, 8 Aug 2024 12:29:53 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: BUG #18575: Sometimes pg_rewind mistakenly assumes that nothing needs to be done. To: Georgy Shelkovy , "pgsql-bugs@lists.postgresql.org" References: <18575-1b9b3b60e2a480de@postgresql.org> <092dd515-b7b4-4fd0-8407-ceca2f02f6ec@iki.fi> <3382141723103572@mail.yandex.ru> Content-Language: en-US From: Heikki Linnakangas In-Reply-To: <3382141723103572@mail.yandex.ru> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 08/08/2024 10:57, Georgy Shelkovy wrote: > Unfortunately, the playback is not very stable, but sometimes it shoots. > I added some commands to show last WAL rows Thanks. I still haven't been able to reproduce it, but here's a theory: When determining whether the target needs rewinding, pg_rewind looks at the target's last checkpoint record, or if it's a standby, its minRecoveryPoint. It's possible that standby2's minRecoveryPoint is indeed before the point of divergence. That means it has replayed the 340 insert records, but all the changes are still only sitting in the shared buffer cache. When you shut it down, those 340 inserts are gone on standby2. When you restart it, they will be applied again from the WAL. In that case, pg_rewind's conclusion that no rewind is needed is correct. standby2 is strictly behind standby1, and could catch up directly to it. However, when you restart standby2, it will first replay the WAL it had streamed from master. Can you show the full output of pg_controldata on all the servers, please? In your latest snippet, you showed just the checkpoint locations, but if just remove the "grep checkpoint | grep location" filters, it would print the whole thing. I'm particularly interested in the minRecoveryPoint on standby2, in the cases when it works and when it doesn't. I'm not sure what the right behavior would be if that's the issue. Perhaps pg_rewind should truncate the WAL in standby2/pg_wal/ in that case, so that when you start it up again, it would not replay the local WAL but would connect to standby2 directly. Also, perhaps a fast shutdown of a standby server should update minRecoveryPoint before exiting. -- Heikki Linnakangas Neon (https://neon.tech)