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.96) (envelope-from ) id 1wvZRg-001N2o-2t for pgsql-hackers@arkaria.postgresql.org; Sun, 16 Aug 2026 11:54:33 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wvZRe-005xAe-1J for pgsql-hackers@arkaria.postgresql.org; Sun, 16 Aug 2026 11:54:31 +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.96) (envelope-from ) id 1wvZRd-005xAW-3B for pgsql-hackers@lists.postgresql.org; Sun, 16 Aug 2026 11:54:31 +0000 Received: from mail-ej1-x62a.google.com ([2a00:1450:4864:20::62a]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wvZRd-00000000tUP-0P1Q for pgsql-hackers@lists.postgresql.org; Sun, 16 Aug 2026 11:54:30 +0000 Received: by mail-ej1-x62a.google.com with SMTP id a640c23a62f3a-c15d111ca99so264991866b.0 for ; Sun, 16 Aug 2026 04:54:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1786881267; x=1787486067; darn=lists.postgresql.org; h=content-transfer-encoding:content-type:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:from:to:cc:subject:date:message-id:reply-to :content-type; bh=G5V/23mgdUZWS5/xI+o9XsHdupT4JstpdD/VwYhWHHQ=; b=jZZtb+o39ZT06d9tAqHQzVUbg8L+WMcGA0bKNoUSnDcQK4cMNJkX/EhoDF1oBK0lR9 08sEja06ddPlRXyrxBQcDLkUh+mneZ4fLppSUsi+DzFwrBVEmDEIupH5xUebjWtp68lB 8OoDIdsQy77hCPo6R0i+yFALQ2WQPVe43RPDPz8WQHC1SzMrt1AT4y+rsl71l2glXup/ NEAzEIKH8+bqgOe9nGm5I0EBHCLDBqppUPQPQ5BavuphszupssxPW6YrXKq5+trIO6r1 7FnG21L90q6SSsg6vTlkHeyOtB2WL+T3iDA6Ks7grHMkPWazDrINqa5TWTbI2h+DYlZF z8aw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786881267; x=1787486067; h=content-transfer-encoding:content-type:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=G5V/23mgdUZWS5/xI+o9XsHdupT4JstpdD/VwYhWHHQ=; b=kg4BbX1qOD776eIlgkgvgoFVP52qFIt4cleOCM0OLcU96UkQE0IYG/218ZmjUe7MrL RGNTfz90SXjD6teXB24bsjcPSTGeRc2osr31aksjahS1VXisSXSXpDXgaMG/keHCO45j XW2o04M2ZADqc8oBNhy0E55nRgSdmMJTM+D5h4SfFg9e00zGNCLQ+Q3bcB5Mp/zZsnBa 1mG8sSF3SD1WjZs0XznqGkF2CyZP9Jl4D6aa/OMU8nwsd75/+Gnm429aB+9/5HUdkrGY sxiONIqWHGXnPeRqxxF9ZkWLbKGy2Oi935Hd2EZGicrJUbcO0kwnF2VT0SCzGT1kIK41 9l5A== X-Forwarded-Encrypted: i=1; AHgh+Rq2ZS8FJ29BHkUM5686XzmQq2sV3Fts3Os6QoT4wuhToap/Vh1S8siTUSdfcaIoatdYJZe/DUR93QbzY7/L@lists.postgresql.org X-Gm-Message-State: AOJu0Yy9EW5r058OlA87MTBL3pr4Xp5nV0qcL7nHAdhAG8vTFL6isjQ7 9nSBqPHv9KEdB4ahMUmquYGtQHfe2YeCkq+ZKGHh64/fnUUPxTpQT/gD X-Gm-Gg: AR+sD10CXoZISu2IuCMO3wh90I3XEAtkDyhfINui0HxqsLSbNE4z5FL/ewS+q98aJUW wapmme67+kwLqx0UtakSzjLnxqY6yw1E7Gu7NwUjeQb9HzKguS/gAuWj6g08qEcNql/wgcnr/d+ RPWvcOJMMyGk/W91v9NyDiV0PcV+Op/kb0f56TUY4ShVlHrVrq6ypR93bTpHyLYJCpJd+xHVDy3 OUgs5WdoGz/RCnRNhroEG0H2+vqYneqLCEuDUj84dwpQUCxHszbpcJEL8i232eOGLC8D+CFWcSc sPJYNkpdPPIh3cUqpUsU1cp4AQbmQPap5B9q3AZPsJWYnLpKntg2hlLqnTyXOq7hx/jByF8G1wR uQZNGS5PtmRNUExyEA5HmiKdd26vwJ7b4mSiImnM8GsykiE3jzUMm4HbSpoBDNg2JIvksOn+Ebl jAxv2bF21m1gqA0+XKYxrSimxvQQCMMqfjjqKNrZzfQiPWkA9AS471/4+8i9b4fc7RufuTfjIjK 7Xo3HAI8C0hV6oqOcj79gks04cHtvI= X-Received: by 2002:a17:907:3e06:b0:c1f:1520:4de5 with SMTP id a640c23a62f3a-c2129c1bd87mr809659466b.1.1786881267135; Sun, 16 Aug 2026 04:54:27 -0700 (PDT) Received: from [192.168.0.161] (c151-177-23-39.bredband.tele2.se. [151.177.23.39]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-c2139f220e1sm273742966b.61.2026.08.16.04.54.26 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 16 Aug 2026 04:54:26 -0700 (PDT) Message-ID: Date: Sun, 16 Aug 2026 13:54:26 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: pg_rewind does not rewind diverging timelines To: Japin Li Cc: Andrey Borodin , pgsql-hackers mailing list References: <80D76C66-A953-466C-8295-A1CF8365A4D2@yandex-team.ru> <10351a09-3a93-49fc-a366-d616b67c6ede@gmail.com> Content-Language: en-US From: Mats Kindahl 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 Thank you Japin, I double checked with the latest as well, just in case, but your patch looks fine. Best wishes, Mats Kindahl On 7/17/26 17:59, Japin Li wrote: > Hi, all > > On Sun, 21 Jun 2026 at 11:09, Mats Kindahl wrote: >> On 6/8/26 12:48, Andrey Borodin wrote: >> >> On 30 Apr 2026, at 13:19, Mats Kindahl wrote: >> >> There is one scenario that I assume is known that TLC found, but does not seem to be fixed. It is a relatively rare case, but since the fix is quite easy, I thought I'd share it with you and get feedback. >> >> Hi Mats, >> >> Hi Andrey, >> >> Thanks for looking at this. >> >> Thanks for working on this. I think the problem is real, but I wonder if >> adding a separate UUID to timeline history files is solving it one step >> too late. >> >> If two independent promotions manage to choose the same numeric TLI, then >> we already have two different histories with the same timeline identifier. >> Their history files will also have the same name. A UUID in the file lets >> tools detect the mismatch afterwards, but it does not prevent the archive >> namespace from containing two different meanings for the same TLI. >> >> Yes, that is correct. >> >> In normal deployments with a shared archive this should only be possible >> when the history file is not visible to the other promoting server: >> either there is no usable restore_command/shared archive, or there is a >> race around publishing and observing the history file. In other words, TLI >> allocation is not atomic, but it is intended to be coordinated through the >> archive. >> >> Yes, that is the ideal way it should work when you have a shared archive. This works because you have a central authority >> that synchronizes the timelines (in theory, not counting bugs). >> >> Maybe we should keep TimelineID as the actual branch identifier and make >> that allocation harder to collide instead of adding a second identifier. >> For example, when choosing a new TLI, add some randomness rather than just >> using the next sequential value. >> >> That would make the race window much less >> dangerous: two independent promotions would be extremely unlikely to >> choose the same TLI, the history file names would remain distinct, and TLI >> would keep its current role as the timeline identifier. >> This also keeps the operational model simpler. TimelineID is already the >> identifier exposed in WAL file names, history file names, logs, and >> recovery configuration. If we add UUIDs, we effectively introduce another >> identity for the same object, and tools then need to reason about both. >> If instead we make TLI allocation less deterministic under races, the >> existing model remains intact. >> >> Does that framing make sense, or am I missing a case where duplicate TLIs >> are unavoidable even with a shared archive and a less collision-prone >> allocation scheme? >> >> I considered using some random increment of the TLI in the manner you describe but there are some issues that makes this >> solution more complicated from an operational perspective: >> >> * If you skip some TLIs (in the sense pick a TLI that is "random but larger"), then it is not clear what the relation >> between them are. >> >> * The history files contain the complete linkage of the timelines, so that is covered, but the naming would be strange. >> >> * For example, if you have history files 1, 5, 7, and 8, then these can all belong to different timelines, (except 1), or >> be a single timeline and it is hard to understand which one without looking through the files. >> >> * With more promotions, the relation becomes even more strange, and the risk of collisions increases. (For example, >> imagine one timeline with 1, 5, 7, 8, 11, and one timeline that forks off 1. Then any increment of 4, 6, 7, or 10 will >> result in a collision.) >> >> * To actually reduce the risk significantly, you need to have a very wide range of the added randomness. Taking a smaller >> number is easier to work with, but then you need to handle that some timelines can collide in some manner. >> * Normally, the history file with the highest number will be the only relevant one. With this approach, you have to check >> the contents of the files to understand which ones are relevant, which increases the operational burden. >> >> In contrast, if you use an UUID in this manner. >> >> * Adding an UUID does not require a central coordinator and is not likely to collide (on the level "impossible to >> collide") and is very straightforward to add. It also comes with a low risk since the places in the code that requires >> changes are very few and not likely to have unexpected consequences elsewhere. This works both with and without a >> shared archive. >> * Normally, a shared archive should only contain a single timeline. Anything else is an anomaly and should be corrected. >> * I think it is still necessary to handle the case where you do not have a shared archive; it would be an odd limitation >> to say that promote only works if you have a shared archive >> * The UUID still serves a purpose in capturing a situation where things have gone wrong. Think of the UUID as similar to >> a "checksum" safety and an extra precaution to prevent things from going wrong. >> >> In short, I think the operational issues with random increment of the history file number is worse, not better, and we >> should deal with the name collisions correctly for shared archives instead. There is an issue in that it need to work >> even in the case where you have a promotion that generates a new UUID but the correct history file exists (reported in >> the other message) that I will look into. >> > I would like to know the current status of this patch. I have encountered the > same issue in practice, and I think the proposed solution is reasonable. > > I found that the v6 patch does not apply cleanly to the current master (1f414035135) > because commit 7f77b2a89bd4 changed the parameter type of writeTimeLineHistory(). > > I've rebased the patch and attached v7. > >> Best wishes, >> Mats Kindahl >> >> Best regards, Andrey Borodin.