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 1wvZCL-001MuM-1q for pgsql-hackers@arkaria.postgresql.org; Sun, 16 Aug 2026 11:38:41 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wvZBK-005uha-0B for pgsql-hackers@arkaria.postgresql.org; Sun, 16 Aug 2026 11:37:39 +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 1wvZBJ-005uhR-1s for pgsql-hackers@lists.postgresql.org; Sun, 16 Aug 2026 11:37:38 +0000 Received: from mail-ed1-x532.google.com ([2a00:1450:4864:20::532]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wvZBI-00000000tND-2o4y for pgsql-hackers@lists.postgresql.org; Sun, 16 Aug 2026 11:37:37 +0000 Received: by mail-ed1-x532.google.com with SMTP id 4fb4d7f45d1cf-6a18840e2abso3946963a12.0 for ; Sun, 16 Aug 2026 04:37:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1786880254; x=1787485054; 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=H3OOd43MmgYgXy6IffT8RPGraMuX2z+xHBN3ueCHR+U=; b=SMo+UokIMv2kCW8uwsEWx/oM7N3RUehnP6bZSggnWDSuwICGsVorAHpZTjVlx8EDmH evsuKwHCGFNM0DqQdJATVWiOr+OyXQqIG4KR7s1xPrqe/UuzzRv11ewi3FJiw4QDi1+3 +oM7/4mJdicM26Uq8tdBCOwCNQdfM1HV/E1FyVNUP3Y4J/CU4Wlm9Hru7YUCrCdVLvXr 0bXBzO1hkkjmG80HHd8Y3WAdBiBoWqNeK8XQFkXkxfnghLeKk/WBxAMimd6jUWLKIX1/ SFkQo08+XamFVr81FQGtwsNbQ1VzZ5voC6YF/aXaSexe96O+Y/Rk2Xe+HkD+LT1e2MF2 Rwng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786880254; x=1787485054; 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=H3OOd43MmgYgXy6IffT8RPGraMuX2z+xHBN3ueCHR+U=; b=ZbZXdP+iyIERGrECic3dR8jP7pA4BQN9EKSyh1yRGUnSQcpTMJPRKygKforLqvKYNQ wy/H9wQrJoR9Sa+dAeZjI2ZHaG9Yc6dYuHT+s2xU+POqSesDDGLuG97g2/ms9AGzjCNP e//iqZPMgkojlizwqIEQvyCMs65mC8oXLQOO7RDBN1L8TlViwxJ0UxazO2CQlRllskgU kaKgb+jC/QGgsk2biKYvYL0ahxQVuE8f8+4bnDHV83+5sQT73zH+Kih2O1tbo+4RMNSz kdglUFOs1dcvsvbKw9cRvb1i2pgyRPWKYdqQnTXkBzwS4hzV3hbetr2SwRN6iEHsEMYc YxFg== X-Forwarded-Encrypted: i=1; AHgh+Rovtu7wdf5m62Po/vTw5UacBKX9K8TYyVJuRHM1cWh8C+mw3BM3T340C4mR+JO7zsrRJQ/6xNX/R4JU2pIJ@lists.postgresql.org X-Gm-Message-State: AOJu0YzNUFhhOsKS8nAlpfuQ6AH5fgeSwh2mc8QATv1y6m/pAhrjEtuP NmMll5Yea5ostMWvJ1QMyc57l2d6gD3riZL4JMPhc3PXzuVf5RdWKe5k X-Gm-Gg: AR+sD13NyADCSHHvQzNddh2xxZHygYvj0m2Pe9W9P8ZR7nuEEK8j3e1tPOj1EnhbGD3 /8GUllvnZJ3sYqJMIap1CLz97U5r8jCf8Ebfj5HBcfOLE+2y9UjT/Wd+GCRU1vopPJT5ku7eFri +3f4WtAm/4HlIipyDYl66/UuancsN9DQEJGlsyCNM48fe+8tNJxDhMTBV6T8+TSfzro+Ose9euT kpDfasZ6EucYCPPSbKwwq0EYpshebA5J9hgZ2mZ6AI9Pho7Pqk4DT2aKEoYw7LCGQul4IwLkkrC Lk62RFWvJAj69ZciKe2bHBDVSXExrzbjXJ1xrOX9wv9S6YJIy9KuXJIyIAnlN3h+/ewl5nIFjoj WEEzL63pU9PPC6m7ike/Ty5rHCoPM3dTe8H9nmv0lq7B+0W7DINbuWUu+bco4ZyFEo6IQVgSPjb 1lPtkuNHPDvqmyJumA920LRs30Oi/JdS6/ihtWU/XhbvWzK7fYXJRqzrU8Ne6CJRE6wT+P5fca5 b0sj/Q6lh2V/rBvsIeHhIfh0omYvo0= X-Received: by 2002:a17:907:3c92:b0:c20:1265:99b2 with SMTP id a640c23a62f3a-c212a2426fdmr902254366b.31.1786880253903; Sun, 16 Aug 2026 04:37:33 -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-c21237e7fe2sm330798766b.49.2026.08.16.04.37.33 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 16 Aug 2026 04:37:33 -0700 (PDT) Message-ID: <0ed702a2-5cb2-4d5b-a9e2-c9ae66fe7c83@gmail.com> Date: Sun, 16 Aug 2026 13:37:32 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: pg_rewind does not rewind diverging timelines To: Tatsuya Kawata Cc: Zsolt Parragi , pgsql-hackers@lists.postgresql.org References: <9ce0d2b9-7a41-4a8a-b299-da295bb4514f@gmail.com> <8683af69-28af-4a2d-a1db-aa1447b02446@gmail.com> Content-Language: en-US From: Mats Kindahl In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 7/26/26 11:57, Tatsuya Kawata wrote: > Hi Mats-san, Zsolt-san, > > Thanks -- I went through both v7 and the new version. > > >   +                       PG_CATCH(); > >   +                       { > >   +                               ErrorData  *edata = CopyErrorData(); > >   + > >   +                               FlushErrorState(); > >   +                               ereport(FATAL, > >   +  errmsg("invalid UUID in history file \"%s\"", path), > >   +  errdetail("%s", edata->message)); > >   +                       } > > > >   This is missing a MemoryContextSwitchTo before CopyErrorData, and > >   results in an assertion with debug builds. > > > Thank you for reviewing this and sorry for the delay. I have attached a > > new version with the issues you pointed to handled. See comments inline > > below. > > The context-switch > fix in readTimeLineHistory() (restoring the caller's context before > CopyErrorData()) looks correct to me. > > One note: the original problem was not only a debug-build assertion. On > non-assert builds CopyErrorData() allocates the ErrorData in ErrorContext, > FlushErrorState() then frees it, and the following > errdetail("%s", edata->message) reads freed memory -- a use-after-free > that > can crash a production server, not just trip an Assert(). Your fix already > covers this; I'm just sharing it since it bears on the severity. Got that. Assertions are just a way to trigger a potential problem early. I did not assume this change was needed just to avoid the assertion. > One minor point: on an invalid UUID the backend FATALs while the frontend > (pg_rewind) silently treats it as "unknown" (all-zero) -- probably > intentional, just flagging it.And should you ever want to drop the > PG_TRY/PG_CATCH here, uuid_in supports soft errors, so a > DirectInputFunctionCallSafe() call with an ErrorSaveContext would avoid > CopyErrorData()/FlushErrorState() and the context switch entirely -- i.e. > it removes the very handling that had to be fixed here, so this class of > mistake can't recur. The current fix is correct and minimal, so this is > purely optional. Yes, I wanted to keep the UUID just as a final discriminator, after the TLI, and keep the changes minimal. Best wishes, Mats Kindahl > > Regards, > Tatsuya Kawata >