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 1w76D4-004xVJ-1r for pgsql-hackers@arkaria.postgresql.org; Mon, 30 Mar 2026 06:34:50 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1w76C2-001h61-0j for pgsql-hackers@arkaria.postgresql.org; Mon, 30 Mar 2026 06:33:46 +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 1w76C1-001h5t-2d for pgsql-hackers@lists.postgresql.org; Mon, 30 Mar 2026 06:33:46 +0000 Received: from mail-pf1-x430.google.com ([2607:f8b0:4864:20::430]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1w76Bx-00000001lGT-1kcT for pgsql-hackers@lists.postgresql.org; Mon, 30 Mar 2026 06:33:45 +0000 Received: by mail-pf1-x430.google.com with SMTP id d2e1a72fcca58-829781b2b01so2060230b3a.2 for ; Sun, 29 Mar 2026 23:33:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1774852420; x=1775457220; darn=lists.postgresql.org; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=sR29cX66vvKzKFEn5Su8IsObI0H46l22hUOnuMFCa0I=; b=Je4ViRIv0NIizxr2I+nYKPyjzYUSsUtw+/AtJdlO1jizr21yWpWYNBNu/bEJ0piG1y or7jphrfIHCMTYEqr8xPKXT+/eSMWMKa+a0cADaU8s2EnfXrH9l+smm+wuFFjVTDdWGz ge7yft2V5XA8PYYHpLhNtab0Hb3OWXaeRzHnILvF76DzZ3iRDCekUIS33y/L7XYn3LGc AibkuUIspKVzaFdVNVlAGrwkVsBCH4fJpBW90mSqrWdyF8+MIqjYZmttk1B62lSE4/rW mVCOiJlE0bPTf7kiWErVd6x8jjs8tIsqDF/U6aZwIGOGRZRaOQ2tMV/IDaAECXmwbAzT vEKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774852420; x=1775457220; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:x-gm-gg:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=sR29cX66vvKzKFEn5Su8IsObI0H46l22hUOnuMFCa0I=; b=kjXRP7u3Oqdkfvi5b7Leq0KswRaEkWOqKzbPINXbgLkifF/vEBViOjsUmFl43If/ge F3dm+pa5soinjwY5BhToncmaWaoOx/vFt59lgNtYgEsXk0AKeVXMTcyvEa0O5WmALTMr PgurQ/oCXHwOxMEd7DtPsLvg6kl7KlyiEmbPrY+BJZXlrv1cEPv1xVkklR/QkdukxM6w HD8dhFZzPgA9gV4Fx5z2m1IRO931S3vL6/+YMGRoPTNie+ZqyV3wD6LfrCwbu9wnmds/ 1HF9pNaK1aFks3E/Smgmz17laIMuagETMuV1jQ6RvQepEl4pJEjC9MwLvK2jYPOP2bkf qw6Q== X-Gm-Message-State: AOJu0YzRV2ikcCvU78iFkmWvEHTZz3Hdag7WzncuRexaECnFiiphTClr AP0qhdv4tLkAWH0QJBx0miGFP2rNNl7Q9AVwMqnlde57UtGCAAmdkCoG X-Gm-Gg: ATEYQzwPZ6kpMzfsVfqiL0tCD3ONsG7O1TJj4dbY+Ho9KaTb3NNy3FMMMFNvc6VTFoW X+ZwZqpIuQbo7PTC0OICX3hhY4j7spshABF2GpYkL5SUswBOdK24GpcM90wxZ59M8gNZY8R9EQp +QbilHxWxAzAxvEl4n67PURQ7ikxaeXGZaulQfkraUboIHW1mjD0YL/GjGImP1SVcX+cJhAhg/y 6P+eGwAfbkx9hwiLaCc6D8jv5wNwlg2DEZGO3go2ePrpC9MKjPj/KVtHZ9c45+unRgo2+plz1mq UWyC2/3neaFRTE1HKcU0MIATNo3VsVUYn3upvcKfT631SqCllg88dJ3D8+bc+eraY3VijALc04y pNr8OrJR/j8ogbNvCSoO+W/qaXt1wf9lh7cRmR8IFRJzkOtNNCw30b8RxiKFwc0h55oMovdHbMU amRQHL3pjV/Fz/g7noUqHJ2OxtTVtvln8= X-Received: by 2002:a05:6a00:3697:b0:82a:18a2:91b9 with SMTP id d2e1a72fcca58-82c9602633fmr10771515b3a.49.1774852420017; Sun, 29 Mar 2026 23:33:40 -0700 (PDT) Received: from smtpclient.apple ([45.32.121.103]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-82ca84646d3sm5828963b3a.15.2026.03.29.23.33.38 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 29 Mar 2026 23:33:39 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3864.400.21\)) Subject: Re: Bug: wrong relname in RemoveSubscriptionRel() error detail From: Chao Li In-Reply-To: Date: Mon, 30 Mar 2026 14:33:00 +0800 Cc: PostgreSQL Hackers Content-Transfer-Encoding: quoted-printable Message-Id: References: To: Nisha Moond X-Mailer: Apple Mail (2.3864.400.21) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk > On Mar 30, 2026, at 14:16, Nisha Moond = wrote: >=20 > On Fri, Mar 27, 2026 at 3:22=E2=80=AFPM Chao Li = wrote: >>=20 >> Hi, >>=20 >> I just noticed a wrong relation name in the error detail emitted by = RemoveSubscriptionRel(): >> ``` >> * >> * Drop subscription relation mapping. These can be for a particular >> * subscription, or for a particular relation, or both. >> */ >> void >> RemoveSubscriptionRel(Oid subid, Oid relid) >> { >> Relation rel; >> TableScanDesc scan; >> ScanKeyData skey[2]; >> HeapTuple tup; >> int nkeys =3D 0; >>=20 >> rel =3D table_open(SubscriptionRelRelationId, = RowExclusiveLock); >>=20 >> if (OidIsValid(subid)) >> { >> ScanKeyInit(&skey[nkeys++], >> = Anum_pg_subscription_rel_srsubid, >> BTEqualStrategyNumber, >> F_OIDEQ, >> ObjectIdGetDatum(subid)); >> } >>=20 >> if (OidIsValid(relid)) >> { >> ScanKeyInit(&skey[nkeys++], >> = Anum_pg_subscription_rel_srrelid, >> BTEqualStrategyNumber, >> F_OIDEQ, >> ObjectIdGetDatum(relid)); >> } >>=20 >> /* Do the search and delete what we found. */ >> scan =3D table_beginscan_catalog(rel, nkeys, skey); >> while (HeapTupleIsValid(tup =3D heap_getnext(scan, = ForwardScanDirection))) >> { >> Form_pg_subscription_rel subrel; >>=20 >> subrel =3D (Form_pg_subscription_rel) GETSTRUCT(tup); >>=20 >> if (!OidIsValid(subid) && >> subrel->srsubstate !=3D SUBREL_STATE_READY && >> get_rel_relkind(subrel->srrelid) !=3D = RELKIND_SEQUENCE) >> { >> ereport(ERROR, >> = (errcode(ERRCODE_INVALID_PARAMETER_VALUE), >> errmsg("could not drop = relation mapping for subscription \"%s\"", >> = get_subscription_name(subrel->srsubid, false)), >> errdetail("Table = synchronization for relation \"%s\" is in progress and is in state = \"%c\".", >> = get_rel_name(relid), subrel->srsubstate), // <=3D=3D=3D=3D=3D=3D bug is = here >>=20 >> ``` >>=20 >> In the error detail, it uses relid to get the relation name. But at = that point we are iterating over subrel, and the function argument relid = can be InvalidOid. So the error detail should use subrel->srrelid = instead. >>=20 >> This looks like a first-day bug introducing by ce0fdbf, so I think = it=E2=80=99s worth back-patching. >>=20 >=20 > I tried reproducing the said bug on HEAD, but it doesn=E2=80=99t seem = to exist > in the current code. >=20 > To hit the mentioned error, the subid has to be invalid - > if (!OidIsValid(subid) && <=3D=3D > And currently, the only path that uses an invalid subid is via > heap_drop_with_catalog() : > =E2=80=A6 > /* > * Remove any associated relation synchronization states. > */ > RemoveSubscriptionRel(InvalidOid, relid); > =E2=80=A6 >=20 > But here relid is always a valid OID (it's the table being dropped). > The corresponding pg_class row is deleted after > RemoveSubscriptionRel(), i.e. via a later call to > DeleteRelationTuple(relid); >=20 > It can only happen with a hypothetical future caller of > RemoveSubscriptionRel(InvalidOid, InvalidOid). And in that case, using > "subrel->srrelid" would be correct. >=20 > So this doesn=E2=80=99t appear to be a real issue in the current code, = and > doesn=E2=80=99t look like a bug to fix now. IMO, if such a caller is = added in > the future, we can add a guard at that point. >=20 > -- > Thanks, > Nisha Hi Nisha, Thanks for your review. I think one current call site may have been overlooked. In = DropSubscription(), we have: ``` /* Remove any associated relation synchronization states. */ RemoveSubscriptionRel(subid, InvalidOid); ``` I agree this is an edge-case bug and may be difficult to reproduce in = practice. But from the function=E2=80=99s semantics, it seems clear to = me that the wrong relation OID is used in the error detail, regardless = of how easy it is to trigger today. Best regards, -- Chao Li (Evan) HighGo Software Co., Ltd. https://www.highgo.com/