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 1wWqTB-002tSp-2J for pgsql-hackers@arkaria.postgresql.org; Tue, 09 Jun 2026 07:01:54 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wWqTA-005UUE-1o for pgsql-hackers@arkaria.postgresql.org; Tue, 09 Jun 2026 07:01:52 +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 1wWqT9-005UU5-24 for pgsql-hackers@lists.postgresql.org; Tue, 09 Jun 2026 07:01:52 +0000 Received: from m16.mail.163.com ([220.197.31.4]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1wWqT1-00000001oDj-26iM for pgsql-hackers@lists.postgresql.org; Tue, 09 Jun 2026 07:01:50 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=Message-ID:Date:MIME-Version:Subject:To:From: Content-Type; bh=yJmAhA8dDiP0y5b6J5lGKfWbAd+xgXKb6HmU/47dg6Q=; b=ElwsZzdi59tSW0UWMECfFQZFsRb8t8FacwuzIv0Glj2UJKm78erqI3bIpPyRdx +hp5Rcu/nJ8nDC/L3zS4YG4zzaaMfIplmUchIQxJ/bKgEhNEejsaSwOTzjKrbYjh M/fN/voTxBdfIRPxYVWTPozZ673ZsT3/o6e09EmY0CceQ= Received: from [192.168.9.88] (unknown []) by gzga-smtp-mtada-g0-2 (Coremail) with SMTP id _____wAXX_dBuidqaBhQCQ--.25851S2; Tue, 09 Jun 2026 15:01:22 +0800 (CST) Message-ID: Date: Tue, 9 Jun 2026 15:01:21 +0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Fix unqualified catalog references in psql describe queries To: Chao Li , Postgres hackers Cc: Fujii Masao , Peter Eisentraut , Jeff Davis , Ashutosh Bapat , Amit Kapila References: From: Tingchuan Sun In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-CM-TRANSID: _____wAXX_dBuidqaBhQCQ--.25851S2 X-Coremail-Antispam: 1Uf129KBjvJXoWxZFWDKFWrCFyrKrW7WryDWrg_yoWrCF4kpr 4fJr17JF18Jr1UZryDJ3yUJr1rJF1rJr1DtFnrK34Iqr1ayr4Utw1Utr18JryUJry8Xr1U XFyUJw1UJr1UAr7anT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07bbDGOUUUUU= X-Originating-IP: [124.133.18.218] X-CM-SenderInfo: xvxq3xxqjfx31dqrmmqw6rljoofrz/xtbC3wMj7WonukO0DgAA3c List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk 在 2026/6/8 16:46, Chao Li 写道: > Hi, > > While testing "[aecc55866] psql: Show comments in \dRp+, \dRs+, and \dX+", I noticed a small issue that was actually introduced by "[8185bb534] CREATE SUBSCRIPTION … SERVER”. > > The problem is that, when querying pg_foreign_server, it misses the "pg_catalog" schema qualification: > ``` > appendPQExpBuffer(&buf, > ", (select srvname from pg_foreign_server where oid=subserver) AS \"%s\"\n", > gettext_noop("Server")); > ``` > > This is not a big problem, but it provides a way to pollute the result of \dRs+ by adding a fake pg_foreign_server earlier in search_path. See this repro: > > 1. Setup: create a server and a sub > ``` > evantest=# create extension postgres_fdw; > CREATE EXTENSION > evantest=# create publication pub; > CREATE PUBLICATION > evantest=# create server s foreign data wrapper postgres_fdw options (dbname 'postgres'); > CREATE SERVER > evantest=# create user mapping for current_user server s; > CREATE USER MAPPING > evantest=# create subscription sub server s publication pub with (connect=false, slot_name=none); > WARNING: subscription was created, but is not connected > HINT: To initiate replication, you must manually create the replication slot, enable the subscription, and alter the subscription to refresh publications. > CREATE SUBSCRIPTION > evantest=# \dRs+ sub; > List of subscriptions > Name | Owner | Enabled | Publication | Binary | Streaming | Two-phase commit | Disable on error | Origin | Password required | Run as owner? | Failover | Server | Retain dead tuples | Max retention duration | Retention active | Synchronous commit | Conninfo | Receiver timeout | Skip LSN | Description > ------+-------+---------+-------------+--------+-----------+------------------+------------------+--------+-------------------+---------------+----------+--------+--------------------+------------------------+------------------+--------------------+----------+------------------+------------+------------- > sub | chaol | f | {pub} | f | parallel | d | f | any | t | f | f | s | f | 0 | f | off | | -1 | 0/00000000 | > (1 row) > ``` > > As shown above, “Server” column shows the correct server name “s”. > > 2. Now, pollute the result > ``` > evantest=# create temp table pg_foreign_server (oid oid, srvname name); > CREATE TABLE > evantest=# insert into pg_foreign_server select oid, 'fake_s'::name from pg_catalog.pg_foreign_server where srvname='s'; > INSERT 0 1 > evantest=# \dRs+ sub; > List of subscriptions > Name | Owner | Enabled | Publication | Binary | Streaming | Two-phase commit | Disable on error | Origin | Password required | Run as owner? | Failover | Server | Retain dead tuples | Max retention duration | Retention active | Synchronous commit | Conninfo | Receiver timeout | Skip LSN | Description > ------+-------+---------+-------------+--------+-----------+------------------+------------------+--------+-------------------+---------------+----------+--------+--------------------+------------------------+------------------+--------------------+----------+------------------+------------+------------- > sub | chaol | f | {pub} | f | parallel | d | f | any | t | f | f | fake_s | f | 0 | f | off | | -1 | 0/00000000 | > (1 row) > ``` > > Now, the "Server" column shows the fake server name that I supplied. I just tried the repro. I never knew a way to make \dRs+ to output wrong data like this, this is interesting. > The fix is to add the schema qualification, using "pg_catalog.pg_foreign_server". In describe.c, catalog objects are generally referenced by qualified names. I found 3 other occurrences that missed schema qualification, so I fixed them as well. > > There are 4 spots in total. Two are v19-new, oversights of 8185bb53476378443240d57f7d844347d5fae1bf and 2f094e7ac691abc9d2fe0f4dcf0feac4a6ce1d9c. The other two are older and might be worth back-patching. So I split the fix into 2 commits: 0001 is v19-new, and 0002 is a back-patch candidate. > > Best regards, > -- > Chao Li (Evan) > HighGo Software Co., Ltd. > https://www.highgo.com/ > > > The patch looks good to me. I applied the patch locally and verified it with “make check-world”. Regards, Tingchuan Sun