[YSQL] ALTER TABLE ... SET SCHEMA pg_catalog bypasses system catalog modification protection
Jira Link: DB-23874
Description
YugabyteDB prevents users from creating tables directly in the pg_catalog schema, reporting that system catalog modifications are disallowed. However, this restriction can be bypassed using ALTER TABLE ... SET SCHEMA.
A user can first create a table in the default schema and then move it into pg_catalog. The operation succeeds, allowing a user-defined table to be placed in a protected system schema.
Reproduction
-- ysqlsh (15.12-YB-2026.1.1.2-b0)
Type "help" for help.
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 tar get | Description
-- --------+---------+-----------+----------+---------+---------+-------------+--------------+-------------
-- i | integer | | | | plain | | |
-- Replica Identity: ???
-- Access method: heap
DROP TABLE pg_catalog.t;
-- DROP TABLEActual behavior
Although direct table creation in pg_catalog is prohibited, ALTER TABLE ... SET SCHEMA pg_catalog succeeds.
The table is successfully moved into the protected system schema and can subsequently be dropped. This allows users to bypass the restriction on creating user-defined objects in pg_catalog.
ALTER TABLE t SET schema pg_catalog;
-- ALTER TABLE
\dS+ t
-- Table "pg_catalog.t"
-- Column | Type | Collation | Nullable | Default | Storage | Compression | Stats tar get | Description
-- --------+---------+-----------+----------+---------+---------+-------------+--------------+-------------
-- i | integer | | | | plain | | |
-- Replica Identity: ???
-- Access method: heap
DROP TABLE pg_catalog.t;
-- DROP TABLEExpected behavior
YugabyteDB should consistently enforce system schema protection across DDL operations.
ALTER TABLE ... SET SCHEMA pg_catalog should be rejected under the same restrictions that prevent direct table creation in pg_catalog, rather than allowing a user-defined table to be moved into the protected schema.
Environment
- DBMS: YugabyteDB
- Version: 15.12-YB-2026.1.1.2-b0
- OS: Ubuntu 22.04
Issue Type
kind/bug
Warning: Please confirm that this issue does not contain any sensitive information
- I confirm this issue does not contain any sensitive information.
Source: yugabyte/yugabyte-db