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 1wgkhe-006NH6-0R for pgsql-hackers@arkaria.postgresql.org; Mon, 06 Jul 2026 14:53:46 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wgkhc-001L6C-2f for pgsql-hackers@arkaria.postgresql.org; Mon, 06 Jul 2026 14:53:44 +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.96) (envelope-from ) id 1wgkhc-001L64-1g for pgsql-hackers@lists.postgresql.org; Mon, 06 Jul 2026 14:53:44 +0000 Received: from mail-wm1-x335.google.com ([2a00:1450:4864:20::335]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wgkha-000000024gN-0pSp for pgsql-hackers@lists.postgresql.org; Mon, 06 Jul 2026 14:53:44 +0000 Received: by mail-wm1-x335.google.com with SMTP id 5b1f17b1804b1-493b1710405so19342045e9.2 for ; Mon, 06 Jul 2026 07:53:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1783349621; x=1783954421; darn=lists.postgresql.org; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=NKo3NylDbop3JwOupTYdb/ZKK1O559vOmmRLPwVZYuI=; b=C2brTOzZYlO9/4259TBn16rW6aEGSBoDgs87XqR6dnJGnOIJiqQzHIarpTnOzLbwn/ UDnBlNIxV9AVOweinglsmGXZdHm2RWTnvNjZcHBBX2fUICzprltQqZBVbPTGdXd9gywN OC9JK9hAgSuP1xTb0XKLHhMLmQfVODHqiMStn8m6Aedbh/2KLy+J/lwddmQwpumicIHE 2cmRr4FbmJIc9d3imXv8pryvRU8A8BZ1+cbxHdI/8Kz6x6+uFQ9zIrlHf0//pDla0MDj FpztkvoGPA/GRNWizwgL+dg2ek9MmL4/xBvazo3by4HAMqgw0jP2n7qR6EJ7hvp+A3B6 ztYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783349621; x=1783954421; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=NKo3NylDbop3JwOupTYdb/ZKK1O559vOmmRLPwVZYuI=; b=m/16TjNcObE9Ovi6lfUggHDJWokl1fSG8PQWWAy+7wpNcFaAlg4pCDjRyTrRG880gu +54s89JGms9h1+g/RN549Vlff+Bn/3SXvsnEzsuNl/EFnbPpomd4aCZCDUQr+/Fqfy0e QFsztSxdhMWrcYhjtfzO3v7nkriqau9YbhTI1G1HwapaP7n75qRnlVs3vBgIB7Zi3lzQ cRGRQnWRCFXB0+3VYjAyyNvFGbhssPEhcT1RmQK+q8zmUdLxl8X2KHyXRIpeKns0xIhA x/jC+mqiCFH1YSF8gKfpnKsNfAgkyQ1qDV05cN2MTL2oOvSm5KBWaAlURZDz0PET3oaj dcKQ== X-Forwarded-Encrypted: i=1; AHgh+Rrj15dMF66BPyAg9SMb7NpyYB4GSKf7TpoSX51eWuVFEqQXrrWfLj8rl1vWveaqJfnIiBT3gXbrfmoH77HN@lists.postgresql.org X-Gm-Message-State: AOJu0YyxEwGnaRYPtsddaYNNUElr4JMBikAGBYWcoRur6P2fN3qtmjtm 6uFOdleQQqrAIh3FkYXeDeSriERTiw2wflmSVEA7ZeK+rOq+wx4aAGW3 X-Gm-Gg: AfdE7cnHvySg+gzwyLCLH16L+wtKs3Ym4JPMHBOX95z71TAj+AUwFm7l8T+qetSwfFY Ii1JEZRVBAxmb3AtZnLog3ctLOx6aqqHvoznlunuOrgf/7L08sZ8ldXSqJ05i+jfuCEl6WA7hwK 0lNy92kxkFCVBf/aMr2O+v8UL1KgwxPjpV4fx+5JmSfZ6Zuv+WdIqdY5rYCXVsr+m13AnMY+2NI T7NWpB/hY/WJSOypqZ1A8MLPfmiriH9oSl6vg4D7JwG6XwduFQ7u065/7+8LGR+QHErw3MKO/3x 9b1ifMM6GS6vFFFQmN7JT03JugZWvZZjAGcVa8bVMWZQANgcVuUiOvTncAkcQPKJJnQh71zPM1Z uAjLe8XgqdoLR2NA5H5FDoxJYey/5X6BALpD1qtGou1CqzTblfxkpZHujVpbKqRDD6tJOm5wyGv DMrA+LU8zfhI1wh9qK8vwHJLrHFK+IleCK0iZwB20Echud4kx4rHELFXqhEqcTE0cECsj/4jTK X-Received: by 2002:a05:600c:548d:b0:493:c76a:2363 with SMTP id 5b1f17b1804b1-493df062bbfmr10605955e9.6.1783349620830; Mon, 06 Jul 2026 07:53:40 -0700 (PDT) Received: from bdtpg (ec2-15-237-197-144.eu-west-3.compute.amazonaws.com. [15.237.197.144]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-493c63ba97csm365196355e9.12.2026.07.06.07.53.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Jul 2026 07:53:40 -0700 (PDT) Date: Mon, 6 Jul 2026 14:53:39 +0000 From: Bertrand Drouvot To: Amit Kapila Cc: "Zhijie Hou (Fujitsu)" , Dilip Kumar , "Hayato Kuroda (Fujitsu)" , "pgsql-hackers@lists.postgresql.org" Subject: Re: Re-read subscription state after lock in AlterSubscription Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, On Mon, Jul 06, 2026 at 03:07:24PM +0530, Amit Kapila wrote: > On Mon, Jul 6, 2026 at 11:13 AM Bertrand Drouvot > wrote: > > > > > It seems RangeVarGetRelidExtended() also doesn't do the additional > > > invalidation handling if the caller already has an appropriate lock, > > > see comments [1]. > > > > From what I can see, the NoLock callers of RangeVarGetRelidExtended(), are for > > callers that don't modify objects (they are "read only" callers). The only > > exception is nextval() but there is an XXX that mentions it. > > > > Here we modify the subscription or publication, so I don't think we are in the > > NoLock spirit of RangeVarGetRelidExtended(). > > > > IIUC, here the risk is that during the first read and before we take > the Lock, if the same OID is reused for a different subscription then > we may end up modifying an unintended subscription. I think that is a > theoretical risk rather than a practical one. I agree OID reuse itself is theoretical. > As per my understanding the loop exists in RangeVarGetRelidExtended() > because relation lookup follows the name, and no lock can pin a > name->OID binding, so the binding can be rebound by concurrent DDL > between lookup and lock. Concretely, our lock protects relation X's > OID, but it can't stop someone renaming X away and handing X's old > name to a different relation Y. Not sure it's only about renaming. The commit message of 4240e429d0c mentions "This was particularly problematic in the case where a table had been dropped and recreated". b3ad5d02c9c also used the same logic and reasoning "avoids needlessly failing when the object of interest is concurrently dropped and recreated". Also in 4240e429d0c: "there's nothing at all here to guard against similar race conditions for non-relations": I think that subscriptions and publications are among those non-relations cases. > The lockable thing (the OID) and the > thing that changes (the name binding) are different objects. The loop > detects exactly this: acquiring the lock runs > AcceptInvalidationMessages(), and if any invalidations arrived while > we waited (inval_count == SharedInvalidMessageCounter), it re-resolves > the name. If the name now maps to a different OID than the one we > locked, it releases the old lock and locks the new OID. It repeats > until the name resolves to the same OID across a lock acquisition — > i.e. until the binding is stable while locked. OTOH, the subscription > path follows the locked OID instead, so it needs only a single > re-read. I think that's for example what RemoveRelations() was doing before 4240e429d0c and what get_object_address() was doing before b3ad5d02c9c: 1/ Resolve name to OID 2/ Lock by OID 3/ Check if it still exists 4/ If gone then elog(ERROR.. but has been changed in b3ad5d02c9c with a retry loop. Also looking at get_object_address(), I can see that it handles publications and subscriptions: case OBJECT_PUBLICATION: case OBJECT_SUBSCRIPTION: address = get_object_address_unqualified(objtype, castNode(String, object), missing_ok); and that DROP PUBLICATION goes through it, so that it already benefits from the retry loop in get_object_address(). DROP SUBSCRIPTION however has its own dedicated code path and does not go through get_object_address(): 0003 adds the retry loop for it. And if DROP already uses the retry loop then ALTER should probably use it too (also done in 0003 and 0004). Regards, -- Bertrand Drouvot PostgreSQL Contributors Team RDS Open Source Databases Amazon Web Services: https://aws.amazon.com