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 1x4YwE-007FRE-2J for pgsql-hackers@arkaria.postgresql.org; Thu, 10 Sep 2026 07:11:14 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1x4YwD-002qhw-1f for pgsql-hackers@arkaria.postgresql.org; Thu, 10 Sep 2026 07:11:13 +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 1x4YwD-002qhj-0j for pgsql-hackers@lists.postgresql.org; Thu, 10 Sep 2026 07:11:13 +0000 Received: from mail-pl1-x635.google.com ([2607:f8b0:4864:20::635]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1x4YwB-00000004ubj-03cH for pgsql-hackers@lists.postgresql.org; Thu, 10 Sep 2026 07:11:12 +0000 Received: by mail-pl1-x635.google.com with SMTP id d9443c01a7336-2d6d28aa26cso43974145ad.2 for ; Thu, 10 Sep 2026 00:11:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1789024270; x=1789629070; darn=lists.postgresql.org; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:content-type:from:to:cc :subject:date:message-id:reply-to:content-type; bh=coFBv7Mv5wbNaej+mRa8Ws7SbZz/Hg1IXnh9K+sEL7I=; b=ETIuxTnfu9vArt8PvFL+43Nj8NBMoSgpIEb8fP0/kW7vxmA+dZrf1I1n+o+aWw8N1E RljxQmF6LmI4tlZDZtWPgVuRzDdVNZ3/W7jhtcaxivKzmAexFWyiayQhmv3K5Sgi1icv 655uouVe598cz5z6NiDkMQD0XSQJrky/ayNEXbzFzEMggES9myGRSF423HDexPivgZoI kR/VX+dfZj0qu0cQygCLH/fzQPQ9eRRZ4DfgdF22EhJEnVVrD9peoRUIwX/d6yQwlIVj rgnNpLaZ9/pewYE7lQSyUHU/uDpf/JT8pCLxkEwXHRUhMxaFmvjEnGMvmC/bs40VB0FP NLrA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1789024270; x=1789629070; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:content-type:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=coFBv7Mv5wbNaej+mRa8Ws7SbZz/Hg1IXnh9K+sEL7I=; b=UIJV52au7frV73NBBZ0LqX6sTFj8QPLFb+aU+NWPLRXe9l5FddCR/aZw80M41JUrD+ HSB7WAMnCZ1znZN2MftrcFPS7GCU7BtWhxeDMIDjiHhGuQefy/LPEHToP7eX5CvCLJNB LE3mpglp1EMEXNuV3eq2Eqsi2gEo8/j3GvYt4JOULVah3Rw3wDyKJa4fd9mc6LQgDC01 F8wEccmjb9SDKm6vLyDpqiBIrZQbggcAnjjjfYdremAkS7S9cxmzJNEHKCyIUITKRmBo 7f/Ts67K0n8bYDJLjFCJvSvwzaS16/cDsiL163jK1iXBoEIHQ2rPPomLMFnHWmbtw5FL Jqgg== X-Gm-Message-State: AFuF++k7BUnddZcc4DRKNefkbDX/RAeoDn3uPbIjzUjkMZuo6Y8eHrui 9+BVWF7cuLsTWLBXZ4DufPXsXI8/WxvaP7wW3nUNMnS8BfNKGv6DIHdz X-Gm-Gg: AYBFou1GXvhwc7hGkL3DMev0yn9DsztQXKgHxF1pOAQD5xDKQGaw4N2nm43oAP6rqzK RFOCTulgSanPYOo+q7IttuOX+yHBphvYHrkPULylA+X/sZQMTuN4ZHT80MC1k1UUgeU2pbkCoaB 7qT4p5AHgZ9p6FG5rc68AX/W6AFCs7f37Sa8tCvk/0PyiVBDz+gcglHFw0WfT8UavqLkhy1sHFk Iz8zWPHaG7zmV8NotVFBb1oiwhu/lHcgl8a4H6OW3i5XbMxZJM6Zhduo6peQyXvEZCvM98n4wEM W2HqrZjufTFOtg2T7XEy/onGpJ8CkTRtoO3hg72Y6Rj0MfzjIVycMOoEP5lR4/LNMEtPQ6c5G2u SuYFV867Ymmc2j+Vy5mC5y2wyWS+9cM5Kqn4CXkGbLx6XAjvT4HbVANepLK6WjaygS6EqiCNlbz XHocKO0N8QkLFiy/+NBIeqIG+HzVOuiTignl1pVEEnday+xaBU03GPx6VOQWJBZ4tWZJIeSjVRK BLbvzV4 X-Received: by 2002:a17:90b:5287:b0:38e:6a44:671b with SMTP id 98e67ed59e1d1-39b25eeeef9mr63023554a91.0.1789024269762; Thu, 10 Sep 2026 00:11:09 -0700 (PDT) Received: from smtpclient.apple ([185.135.79.125]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-39bae918fe5sm2859863a91.1.2026.09.10.00.11.06 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 10 Sep 2026 00:11:09 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3864.700.51.1.1\)) Subject: Re: Review items for EXCEPT TABLE publication From: Chao Li In-Reply-To: Date: Thu, 10 Sep 2026 15:10:32 +0800 Cc: PostgreSQL Hackers Content-Transfer-Encoding: quoted-printable Message-Id: <23BC758C-7DBC-4270-9232-2CC09C3679FB@gmail.com> References: To: vignesh C X-Mailer: Apple Mail (2.3864.700.51.1.1) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk > On Sep 10, 2026, at 13:39, vignesh C wrote: >=20 > Hi, >=20 > I ran claude to identify issues related to the EXCEPT TABLE > publication changes. After reviewing the findings, I found the > following issues that need to be fixed. > Finding #1: ALTER PUBLICATION race > AlterPublicationOptions() performs validation using the publication > tuple before acquiring the publication lock. A concurrent ALTER > PUBLICATION ... SET ALL TABLES can change puballtables while the > second command is waiting for the lock. Since the tuple is not > re-fetched after acquiring the lock, the validation can proceed based > on stale state while subsequent catalog lookups see the updated state. > In an assert-enabled build, this can trigger the assertion in > GetIncludedPublicationRelations() because of > "Assert(!GetPublication(pubid)->alltables)" and crash the backend. >=20 > Test to reproduce: > -- session 1: -- session 2: > CREATE PUBLICATION p; > BEGIN; > ALTER PUBLICATION p > SET ALL TABLES; > ALTER PUBLICATION p > SET > (publish_via_partition_root =3D false); > -- reads = puballtables=3Dfalse, > -- enters the branch > -- blocks while acquiring > -- AccessShareLock > COMMIT; -- resumes and assertion fires >=20 > The fix is to check the current publication state after acquiring the > publication lock. >=20 > Regards, > Vignesh > = Since each commit addresses one finding, I=E2=80=99ll review and reply = to the commits one by one. For 0001, I have two comments: 1. I don=E2=80=99t think this fix completely resolves the race. With = GetPublication(pubform->oid)->alltables moved after acquiring the lock, = S2 has to wait for S1 to commit, so it can see the alltables change made = by S1. However, tup was fetched before AlterPublicationOptions() was called. = After S1 commits its update, a new tuple version has been created, so = the tup held by S2 is stale. I think S2 should re-fetch the publication = tuple after acquiring the lock, so that both the validation and the = subsequent catalog update operate on the current tuple version. 2. =46rom a code-structure perspective, before this patch the = relation-validation block was entered only when the publication was not = FOR ALL TABLES. With this patch, the outer if is entered regardless of = puballtables, and when GetPublication(pubform->oid)->alltables is true, = root_relids is simply left empty. This is not a problem today because the only code that follows is the = foreach, which does nothing when root_relids is empty. However, if more = code is added after the loop in the future, it may unintentionally run = for an ALL TABLESpublication as well. I think it would be clearer and safer to keep the whole = relation-validation section, including the foreach, inside the post-lock = !alltables branch. Best regards, -- Chao Li (Evan) HighGo Software Co., Ltd. https://www.highgo.com/