psql internals queries breaks in presence of user-defined operators

From: Kirill Reshke <reshkekirill(at)gmail(dot)com>
To: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: psql internals queries breaks in presence of user-defined operators
Date: 2026-06-25 06:33:25
Message-ID: CALdSSPhZjj01YN5E2UmVOcr4QWKzgJ_hRQfv0x+MHwjk-dw=Dw@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi!
If a user creates a malformed operator in theirs database, like:

```
create or replace function f (name, name) RETURNS boolean AS $$ begin
RETURN $1::text = $2::text; end; $$ LANGUAGE plpgsql;
CREATE OPERATOR public.!~ ( LEFTARG = name, RIGHTARG = name, FUNCTION = f);
```

then psql's meta-commands queries like \du stop working.

That's because the catalog misses operators for leftarg = name,
rightarg = name and oprname = '!~'.

I think this can be enhanced a little by schema-qualifying psql's
internal query.
While this issue is fully the user's fault, I think psql can still be
a little more conservative in operator selection, and work anyways.
PFA POC patch.

This is not a security issue, per:
https://www.postgresql.org/docs/current/app-psql.html says:

If untrusted users have access to a database that has not adopted a secure
schema usage pattern, begin your session by removing publicly-writable
schemas from search_path.

--
Best regards,
Kirill Reshke

Attachment Content-Type Size
v1-0001-Schema-qualify-psql-internal-query-operators.patch application/octet-stream 2.6 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message vignesh C 2026-06-25 06:37:30 Re: DOCS - clarify CREATE SUBSCRIPTION only synchronizes sequences when copy_data=true
Previous Message Michael Paquier 2026-06-25 06:19:57 Re: Handle concurrent drop when doing whole database vacuum