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 1sbxBU-002kYK-Dy for pgsql-bugs@arkaria.postgresql.org; Thu, 08 Aug 2024 07:03:40 +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 1sbxBS-00CHP0-FR for pgsql-bugs@arkaria.postgresql.org; Thu, 08 Aug 2024 07:03:38 +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 1sbxBS-00CHOr-3o for pgsql-bugs@lists.postgresql.org; Thu, 08 Aug 2024 07:03:38 +0000 Received: from lahtoruutu.iki.fi ([185.185.170.37]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sbxBO-003fVa-P6 for pgsql-bugs@lists.postgresql.org; Thu, 08 Aug 2024 07:03:36 +0000 Received: from [192.168.1.110] (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 lahtoruutu.iki.fi (Postfix) with ESMTPSA id 4WfdL94L0Mz49PxX; Thu, 8 Aug 2024 10:03:29 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=lahtoruutu; t=1723100610; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=c9e8DnB5SlSZC8Yud44fJ6J5sGjZFAa1baTgp+uy7jE=; b=KV88ioFeYaFzVwHhOWr5yXHaVQqxYzcnJ1/Kb3DhpFmmPE3OAzcDXTnT2AbqB4tBSfUwA5 PE/MNxtD9jDu+uPJv0zkqOKhMrU8yAAu5asQIUXmx+4B1gINHQyKNhBmPt81L4ZqaOYBOk A4YsRurmymw0da4WjaWeMOvJsaaYQN/91BhsUTeCRbV5aY2uGopxC1CR8r+ZAHfpfSFqG9 BqVLfegcJiBZRb90sjQsgEvrVpwLa7hmU1CKDUAhFoW02n4itVIUFzJcuRE24J8p+fim/k VJMEff/bGXS2cCr/5etOUPtGKqetFdwUv8xjRioR6Na/tcBWP1w0LSyfec1vgg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=lahtoruutu; t=1723100610; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=c9e8DnB5SlSZC8Yud44fJ6J5sGjZFAa1baTgp+uy7jE=; b=AcBWFLQap3C2gMdPMIcjCA8DHo2rDQ7a2+MottNGnqyj5X7pNQb4mpRIqHS0VmxjFcorau kxfaSHMe0nj2SoGTWOaCXT1Qhhpg31rB26ZeWlFLNldRAmoDq8EX39mp+g9Jm3Ap4MCstI HT9/H6pLvVGfp3arw9o1EyOZp/DH+glWOUDkOy7CXb5c8XJrqPfI02xM9clY5V/Zzwb2wf 72uA2+IZtAX8YK0VfLw0iZ5X9bAW5ucOSI5Iyfr0aNXHVCnUZPzHsgPVHH75W/uTjmUpSM oDtCu+fvKWih89Jy3pElBJMQTs/DZrZCZWUSxcJks9VVu2YaYSrqcK79vdOG1Q== ARC-Authentication-Results: i=1; ORIGINATING; auth=pass smtp.auth=hlinnaka smtp.mailfrom=hlinnaka@iki.fi ARC-Seal: i=1; s=lahtoruutu; d=iki.fi; t=1723100610; a=rsa-sha256; cv=none; b=FPgUfLfWcChzcYIoNSx2SGVpQYPIKAKg88T0US7Vi9MfBYhgYT+tTKhkWcOOiFlFffRmVp tcpOgkBA7YgGjnz6KzVfoGxVMo0RPpv3oalb9cJR3ykE7T3jbgM7MX4ouoeS2BjIFoUjNL XbcLdLD5fwLY0mFIDVxryg3fzRhSKLoD8h/iquE3va1nID5JapthXQm3puHfsV0AnfZVQE YC2LZLqk/7jjbB/xLR+CzeBL3QI6joNB6H/MmYeuNX3GdlX50ufiGFqpcRKEnq+HCebG5e grYa4DiBHlcC+7cktrMU2CGE/pUH3pG4i86HrjPAjHY010RCTcD3q+xMDRKvDg== Content-Type: multipart/mixed; boundary="------------KIkJ90WJZAbeAWAKSQ6EsR8V" Message-ID: <092dd515-b7b4-4fd0-8407-ceca2f02f6ec@iki.fi> Date: Thu, 8 Aug 2024 10:03:29 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird From: Heikki Linnakangas Subject: Re: BUG #18575: Sometimes pg_rewind mistakenly assumes that nothing needs to be done. To: g.shelkovy@arenadata.io, pgsql-bugs@lists.postgresql.org References: <18575-1b9b3b60e2a480de@postgresql.org> Content-Language: en-US In-Reply-To: <18575-1b9b3b60e2a480de@postgresql.org> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk This is a multi-part message in MIME format. --------------KIkJ90WJZAbeAWAKSQ6EsR8V Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 07/08/2024 15:19, PG Bug reporting form wrote: > Sometimes pg_rewind mistakenly assumes that nothing needs to be done, which > results in the replica having data that is not on the master. > > ... > + pg_rewind --progress --debug '--source-pgdata=standby1' > '--target-pgdata=standby2' > pg_rewind: Source timeline history: > pg_rewind: Target timeline history: > pg_rewind: 1: 0/0 - 0/0 > pg_rewind: servers diverged at WAL location 0/10392E8 on timeline 1 > pg_rewind: no rewind required > > ... > Same query > + psql -d postgres -a --no-psqlrc -p 5001 > select count(*) from a; > count > -------- > 100000 > (1 row) > > + echo 'Different results' > Different results > + psql -d postgres -a --no-psqlrc -p 5002 > select count(*) from a; > count > -------- > 100340 > (1 row) > > + echo 'Stop standby1' > Stop standby1 > + pg_ctl -w -D standby1 stop -m fast > waiting for server to shut down....2024-08-07 17:15:03.077 +05 [19703] > DEBUG: logger shutting down > done > server stopped > + echo 'Stop standby2' > Stop standby2 > + pg_ctl -w -D standby2 stop -m fast > waiting for server to shut down....2024-08-07 17:15:03.117 +05 [19713] > DEBUG: logger shutting down > done > server stopped > ``` I cannot reproduce this. On my laptop, the reported "servers diverged at WAL location" is always higher, and it performs rewind as expected: g_rewind: Source timeline history: pg_rewind: Target timeline history: pg_rewind: 1: 0/0 - 0/0 pg_rewind: servers diverged at WAL location 0/1138F00 on timeline 1 pg_rewind: rewinding from last common checkpoint at 0/1138E88 on timeline 1 However while looking at the code, I noticed that the debug-output of the Source timeline history is broken. See attached patch to fix it. With that fix, I get: pg_rewind: Source timeline history: pg_rewind: 1: 0/0 - 0/1138F00 pg_rewind: 2: 0/1138F00 - 0/0 pg_rewind: Target timeline history: pg_rewind: 1: 0/0 - 0/0 pg_rewind: 0 a: 1 0/0-0/1138F00 - b: 1 0/0-0/0 pg_rewind: servers diverged at WAL location 0/1138F00 on timeline 1 pg_rewind: rewinding from last common checkpoint at 0/1138E88 on timeline 1 That just fixes the debugging output, though, it doesn't change what it actually does. Can you try the attached fix show the output you get with that please? Or alternatively, show the contents of the standby1/pg_wal/00000002.history file. -- Heikki Linnakangas Neon (https://neon.tech) --------------KIkJ90WJZAbeAWAKSQ6EsR8V Content-Type: text/x-patch; charset=UTF-8; name="fix-print-debug-source-history.patch" Content-Disposition: attachment; filename="fix-print-debug-source-history.patch" Content-Transfer-Encoding: base64 ZGlmZiAtLWdpdCBhL3NyYy9iaW4vcGdfcmV3aW5kL3BnX3Jld2luZC5jIGIvc3JjL2Jpbi9w Z19yZXdpbmQvcGdfcmV3aW5kLmMKaW5kZXggMDg0MWFiNDEzNS4uMGY5ZDM4YWJkNSAxMDA2 NDQKLS0tIGEvc3JjL2Jpbi9wZ19yZXdpbmQvcGdfcmV3aW5kLmMKKysrIGIvc3JjL2Jpbi9w Z19yZXdpbmQvcGdfcmV3aW5kLmMKQEAgLTg5Miw5ICs4OTIsOSBAQCBnZXRUaW1lbGluZUhp c3RvcnkoVGltZUxpbmVJRCB0bGksIGJvb2wgaXNfc291cmNlLCBpbnQgKm5lbnRyaWVzKQog CQkJcGdfbG9nX2RlYnVnKCJUYXJnZXQgdGltZWxpbmUgaGlzdG9yeToiKTsKIAogCQkvKgot CQkgKiBQcmludCB0aGUgdGFyZ2V0IHRpbWVsaW5lIGhpc3RvcnkuCisJCSAqIFByaW50IHRo ZSB0aW1lbGluZSBoaXN0b3J5CiAJCSAqLwotCQlmb3IgKGkgPSAwOyBpIDwgdGFyZ2V0TmVu dHJpZXM7IGkrKykKKwkJZm9yIChpID0gMDsgaSA8ICpuZW50cmllczsgaSsrKQogCQl7CiAJ CQlUaW1lTGluZUhpc3RvcnlFbnRyeSAqZW50cnk7CiAK --------------KIkJ90WJZAbeAWAKSQ6EsR8V--