Re: BUG #19097: System catalog modifications are allowed by alter

Laurenz Albe <laurenz.albe@cybertec.at>

From: Laurenz Albe <laurenz.albe@cybertec.at>
To: rekgrpth@gmail.com, pgsql-bugs@lists.postgresql.org
Date: 2025-10-29T12:09:32Z
Lists: pgsql-bugs
On Wed, 2025-10-29 at 04:41 +0000, PG Bug reporting form wrote:
> 
> PostgreSQL version: 18.0
> 
> ```sql
> create table pg_catalog.t (i int);
> ERROR:  permission denied to create "pg_catalog.t"
> DETAIL:  System catalog modifications are currently disallowed.
> 
> create table t (i int);
> CREATE TABLE
> 
> alter table t set schema pg_catalog;
> ALTER TABLE
> 
> \dS+ t
>                                           Table "pg_catalog.t"
>  Column |  Type   | Collation | Nullable | Default | Storage | Compression |
> Stats target | Description
> --------+---------+-----------+----------+---------+---------+-------------+--------------+-------------
>  i      | integer |           |          |         | plain   |             |
> > 
> Replica Identity: NOTHING
> Access method: heap
> 
> drop table pg_catalog.t;
> DROP TABLE
> ```

That is confusing, but it seems intentional.  See the following comment in
src/backend/catalog/heap.c:

    /*
     * Don't allow creating relations in pg_catalog directly, even though it
     * is allowed to move user defined relations there. Semantics with search
     * paths including pg_catalog are too confusing for now.
     *
     * But allow creating indexes on relations in pg_catalog even if
     * allow_system_table_mods = off, upper layers already guarantee it's on a
     * user defined relation, not a system one.
     */

This was deliberately added by commit 8e18d04d4daf.
I couldn't find the pertinent discussion in the archives.

I don't think it is necessary to document that...

Yours,
Laurenz Albe