Re: Fix unqualified catalog references in psql describe queries

From: Tingchuan Sun <suntingchuan1996(at)163(dot)com>
To: Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com>, Postgres hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Cc: Fujii Masao <masao(dot)fujii(at)gmail(dot)com>, Peter Eisentraut <peter(at)eisentraut(dot)org>, Jeff Davis <pgsql(at)j-davis(dot)com>, Ashutosh Bapat <ashutosh(dot)bapat(dot)oss(at)gmail(dot)com>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>
Subject: Re: Fix unqualified catalog references in psql describe queries
Date: 2026-06-09 07:01:21
Message-ID: e6bdd41a-4390-4711-9646-aa9de10f6c5e@163.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers


在 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

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Hayato Kuroda (Fujitsu) 2026-06-09 07:05:20 RE: t/035_standby_logical_decoding.pl might fail on attempt to read wrong timeline
Previous Message Chao Li 2026-06-09 06:59:17 Re: First draft of PG 19 release notes