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 1rQpPi-003n5M-EO for pgsql-hackers@arkaria.postgresql.org; Fri, 19 Jan 2024 14:00:06 +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 1rQpPh-009Vy3-Ji for pgsql-hackers@arkaria.postgresql.org; Fri, 19 Jan 2024 14:00:05 +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 1rQpPh-009Vxv-AO for pgsql-hackers@lists.postgresql.org; Fri, 19 Jan 2024 14:00:05 +0000 Received: from mail-lj1-x22d.google.com ([2a00:1450:4864:20::22d]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1rQpPf-002dwN-58 for pgsql-hackers@postgresql.org; Fri, 19 Jan 2024 14:00:04 +0000 Received: by mail-lj1-x22d.google.com with SMTP id 38308e7fff4ca-2cd853c159eso9960061fa.2 for ; Fri, 19 Jan 2024 06:00:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1705672802; x=1706277602; darn=postgresql.org; h=content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=jm87EPiS2iuK6rCvVfy4a3TFdb89PkvCuupkK4Q8yYo=; b=hcJJZJWqWh07vZSIapqpGn6Q/9IM+G5FNAhxiOFyNKH1HyNrpavIzgMcSZPSujJTHS jPP/okUV6kXJvdP7WQMrfhLV2f3/JX1jqCBjjwLuKbc7AiQT7jd7ED8Aqf6lxoSNXvxk Wvi7iQbddnk14sLHiDzKyg1oQtep2n6ccc1RulFYiWKRxrgRxMh3I7nRSSPm/GLsdwEn +NgH5o1/Ja9N3UHMoYbglYBfV5GQsTNCD0XpY0J4Ftw08aaHutn5tY9a2DB9lOnSDTlj rFJ+NGjwZXsMxpeye0FlMHKkZtqvhClxoWFu4OnBI8uElCIK4ytdvWleloiTw7DJ96Jd Otwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705672802; x=1706277602; h=content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=jm87EPiS2iuK6rCvVfy4a3TFdb89PkvCuupkK4Q8yYo=; b=rK1nYY01SswtU/egE4ufgmM7ZLAl2pVt1e7AvE251M0v7I2T94AU+UhjY3+fN44Mg3 AcpDkNaii9Dm4tmcJn+kMVIxMUfHRKkkY/lNp4h/NK/ClnBq3NH0LCqiGM3t9R1uksLg aH2aBBF0p07SLqbaeJtb6uor680kvYR4rSu7bl5yUlV4Ic48VzX0hpaW8KA4XNZTuBn9 q2KX5i+15HJV4ItG/y0lJeOF6fpIhz2nZaYTRW7MYXZgxsDdAvaDHD5E4y6E1OK6qc+D nQvpWbw8+riJ6me7szsg7aeXNNh1W29JAAJUxVsx87A2xrkLm7N4gC5AizoJ1vabQS/J MTiw== X-Gm-Message-State: AOJu0YxKa1OZ0UI9y8msKKt8/xpzBgOEO7vanKAtnH83//SeYpECellL v5yas+W5M1QAJt/Xv207fpf+uCAlZ4oj0V2n+dOfdjD1fVsCg75N X-Google-Smtp-Source: AGHT+IE5VYv3btkZhNt4RZMBRPe581tAKiCGDzjbuPkSVidZTgVml1SNz7Z3tS3f2vNxhCJldbcEkQ== X-Received: by 2002:a2e:8509:0:b0:2cd:246a:6df2 with SMTP id j9-20020a2e8509000000b002cd246a6df2mr1370805lji.60.1705672802110; Fri, 19 Jan 2024 06:00:02 -0800 (PST) Received: from [1.0.0.7] ([91.185.77.50]) by smtp.gmail.com with ESMTPSA id q4-20020a2eb4a4000000b002cdb2addf0csm1834004ljm.134.2024.01.19.06.00.01 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 19 Jan 2024 06:00:01 -0800 (PST) Message-ID: <74ea5e7e-9aa0-4d7a-85df-71a9d200a8d8@gmail.com> Date: Fri, 19 Jan 2024 17:00:00 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.2 Subject: Re: BUG: Former primary node might stuck when started as a standby Content-Language: en-US To: Aleksander Alekseev , pgsql-hackers References: From: Alexander Lakhin In-Reply-To: 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 Hi Aleksander, 19.01.2024 14:45, Aleksander Alekseev wrote: > >> it might not go online, due to the error: >> new timeline N forked off current database system timeline M before current recovery point X/X >> [...] >> In this case, node1 wrote to it's WAL record 0/304DC68, but sent to node2 >> only record 0/304DBF0, then node2, being promoted to primary, forked a next >> timeline from it, but when node1 was started as a standby, it first >> replayed 0/304DC68 from WAL, and then could not switch to the new timeline >> starting from the previous position. > Unless I'm missing something, this is just the right behavior of the system. Thank you for the answer! > node1 has no way of knowing the history of node1/node2/nodeN > promotion. It sees that it has more data and/or inconsistent timeline > with another node and refuses to process further until DBA will > intervene. But node1 knows that it's a standby now and it's expected to get all the WAL records from the primary, doesn't it? Maybe it could REDO from it's own WAL as little records as possible, before requesting records from the authoritative source... Is it supposed that it's more performance-efficient (not on the first restart, but on later ones)? > What else can node1 do, drop the data? That's not how > things are done in Postgres :) In case no other options exist (this behavior is really correct and the only possible), maybe the server should just stop? Can DBA intervene somehow to make the server proceed without stopping it? > It's been a while since I seriously played with replication, but if > memory serves, a proper way to switch node1 to a replica mode would be > to use pg_rewind on it first. Perhaps that's true generally, but as we can see, without the extra records replayed, this scenario works just fine. Moreover, existing tests rely on it, e.g., 009_twophase.pl or 012_subtransactions.pl (in fact, my research of the issue was initiated per a test failure). Best regards, Alexander