ALTER DEFAULT PRIVILEGES IN SCHEMA pg_conflict silently has no effect

From: shveta malik <shveta(dot)malik(at)gmail(dot)com>
To: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Cc: Dilip Kumar <dilipbalaut(at)gmail(dot)com>, Amit Kapila <amitkapila16(at)gmail(dot)com>, Nisha Moond <nisha(dot)moond412(at)gmail(dot)com>, shveta malik <shvetamalik(at)gmail(dot)com>
Subject: ALTER DEFAULT PRIVILEGES IN SCHEMA pg_conflict silently has no effect
Date: 2026-12-01 09:19:38
Message-ID: CAJpy0uCT-VvYVHiySQs+FJwGy=qFfcQqQgd+qpdF+ZRxe3fUKw@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi All,
(CCing the authors and reviewers of the CLT feature)

While reviewing another patch related to CLT, I noticed a concerning
behaviour on HEAD:

'ALTER DEFAULT PRIVILEGES IN SCHEMA pg_conflict' is accepted, but the
privileges are not applied to newly created CLTs. This is because
create_conflict_log_table() passes use_user_acl = false to
heap_create_with_catalog(). So the command silently has no effect. See
testcase [1]

I think this needs handling because CLTs are meant to be queried by
users, and a new CLT gets created for each subscription. So a user
wanting a role (e.g. for monitoring) to read all CLTs would tend to
use ALTER DEFAULT PRIVILEGES, and would get no error or warning that
it did nothing.

Note that ALTER DEFAULT PRIVILEGES IN SCHEMA pg_toast is also accepted
and not applied to new toast tables, but that does not matter there,
as non-superusers have no USAGE on pg_toast and access toast data only
through the parent table. CLTs, on the other hand, are meant to be
queried by users, so here the user would expect it to work. Thoughts?

If others also think that this at least needs some handling, here are
the options:

1) Emit an error for this command (modify
ExecAlterDefaultPrivilegesStmt?), something like:
ERROR: cannot set default privileges in schema "pg_conflict"

2) Document that default privileges are not applied to conflict log
tables, and that privileges must be granted on each CLT after it is
created.

3) Let the default privileges be applied to the CLTs (use_user_acl =
true), as the user may need it for monitoring purposes, and thus may
not need to grant privileges on each individual CLT. Note that with
this, global default privileges of the subscription owner (ALTER
DEFAULT PRIVILEGES FOR ROLE ... without IN SCHEMA) will also get
applied to the CLTs.

[1]:

Testcase:
Pub:
CREATE PUBLICATION pub1;

Sub:
CREATE ROLE r1;

-- Setup: r1 can use both schemas (pg_conflict already grants USAGE to PUBLIC)
CREATE SCHEMA s1;
GRANT USAGE ON SCHEMA s1 TO r1;

-- Default privilege for future tables in both schemas (both accepted)
ALTER DEFAULT PRIVILEGES IN SCHEMA s1 GRANT SELECT ON TABLES TO r1;
ALTER DEFAULT PRIVILEGES IN SCHEMA pg_conflict GRANT SELECT ON TABLES TO r1;

SELECT defaclnamespace::regnamespace AS schema, defaclacl FROM
pg_default_acl ORDER BY 1;
schema | defaclacl
-------------+-----------------
pg_conflict | {r1=r/shveta}
s1 | {r1=r/shveta}

-- Create a new ordinary table and a new CLT
CREATE TABLE s1.t1 (a int);
INSERT INTO s1.t1 values(10);
CREATE SUBSCRIPTION sub1 CONNECTION 'dbname=postgres ...' PUBLICATION
pub1 WITH(conflict_log_destination='all');

-- Compare the ACLs and SELECT privilege of r1
SELECT c.oid::regclass AS table_name, c.relacl,
has_table_privilege('r1', c.oid, 'SELECT') AS r1_can_select
FROM pg_class c
WHERE c.oid IN ('s1.t1'::regclass,
(SELECT subconflictlogrelid FROM pg_subscription WHERE
subname = 'sub1'))
ORDER BY 1;
table_name | relacl
| r1_can_select
-----------------------------------+--------------------------------------------+---------------
s1.t1 |
{shveta=arwdDxtm/shveta,r1=r/shveta} | t
pg_conflict.pg_conflict_log_16391 |
| f

-- Verify as r1
SET ROLE r1;
SELECT count(*) FROM s1.t1;
count
-------
1

SELECT count(*) FROM pg_conflict.pg_conflict_log_16391;
ERROR: permission denied for table pg_conflict_log_16391
RESET ROLE;

r1 can read s1.t1 but not the CLT, even though both default privileges
were accepted.

thanks
Shveta

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Yuefei Shi 2026-12-01 09:21:47 Re: [PATCH] Handle SQL NULL results from casts in JSON generation
Previous Message Zhijie Hou 2026-12-01 09:06:38 Re: Add a hook for handling logical decoding messages on subscribers.