PostgreSQL Default Privileges: A Guide to Future Object Access
Test PostgreSQL default privileges on future tables and sequences. Use a disposable SQL fixture to check which creator role controls each object grant.
ALTER DEFAULT PRIVILEGES changes the access control list applied at creation time to objects created later by a specific role, optionally within specific schemas. It never modifies existing objects, and per-schema entries can only add to global defaults, never subtract from them. This guide gives you a runnable fixture on a disposable local database that proves which grants a new table actually receives, and shows how the creating role, the app role, the schema, pg_default_acl and ddp interact when a migration creates tables you did not grant by hand.
Author: jackey.ye · Updated: 2026-12-01
What Does ALTER DEFAULT PRIVILEGES Actually Change?
It writes a row into pg_default_acl, and that row is consulted only at the moment an object is created. A new table therefore receives an explicit ACL built from your entry instead of the hard-wired default, which for tables grants nothing to PUBLIC. The ALTER DEFAULT PRIVILEGES reference states the scope plainly: the command sets privileges applied to objects created in the future and does not affect privileges assigned to already-existing objects.
There are two entry kinds. A global entry has defaclnamespace = 0 and overrides the normal hard-wired default for that object type. A per-schema entry references a particular namespace and represents privileges to be added to the global or hard-wired default, as the pg_default_acl catalog page describes.
The command covers schemas, tables (including views and foreign tables), sequences, functions, types (including domains) and large objects. For this command, functions include aggregates and procedures, and FUNCTIONS and ROUTINES are equivalent — ROUTINES is the preferred term going forward, and you cannot set defaults for functions and procedures separately. IN SCHEMA is not allowed when setting privileges for schemas and large objects, since schemas cannot be nested and large objects do not belong to a schema.
Which Role's Default Privileges Apply to a New Table?
The defaults of the role that executes CREATE TABLE — the current role at creation time — and nothing else. The documentation is explicit that while you can change your own default privileges and the defaults of roles you are a member of, at object creation time new object permissions are only affected by the default privileges of the current role and are not inherited from any roles in which the current role is a member.
That single rule explains most "my defaults did not apply" tickets. A migration runner that connects as deploy and creates tables will apply deploy's defaults, even if deploy is a member of app_owner and you configured defaults for app_owner. Membership grants you the right to alter another role's defaults; it does not make those defaults apply to your own DDL.
Use FOR ROLE target_role to pre-set defaults for a role you are not currently logged in as. A typical split: app_owner owns the schema and holds the defaults, deploy runs migrations, and the migration script either runs as app_owner or is preceded by an administrative session that issues ALTER DEFAULT PRIVILEGES FOR ROLE app_owner .... Decide which of the two you standardize on before you write the first migration, because switching later leaves a mixed set of tables behind.
Global vs Per-Schema Defaults: How Do They Combine?
They combine asymmetrically: a global entry replaces the hard-wired default, while a per-schema entry is layered on top of whatever the global or hard-wired default already grants. The practical consequence is that a schema-scoped REVOKE can only undo a matching schema-scoped GRANT.
Scope clause | Catalog representation | Effect on built-in default | Can REVOKE subtract? | Practical use case |
|---|---|---|---|---|
No |
| Overrides it for the whole database | Yes — it replaces the default | Remove |
|
| Added to the global or hard-wired default | Only reverses a matching per-schema GRANT | Give the app role DML on tables in one schema |
Both present | Two rows for the same role and object type | Global replaces; schema entry adds | Per-schema REVOKE cannot cancel a global GRANT | Broad baseline plus schema-specific extras |
The documented example makes the trap concrete. ALTER DEFAULT PRIVILEGES FOR ROLE admin REVOKE EXECUTE ON FUNCTIONS FROM PUBLIC removes the normal PUBLIC EXECUTE grant for functions subsequently created by admin. The schema-limited version, ALTER DEFAULT PRIVILEGES IN SCHEMA public REVOKE EXECUTE ON FUNCTIONS FROM PUBLIC, has no effect unless it is undoing a matching GRANT, because per-schema default privileges can only add privileges to the global setting, not remove privileges granted by it.
How Do I Set Defaults So New Tables Are Usable Without Manual Grants?
Run these steps as one login in a scratch database you can drop. Create it with createdb dp_fixture, connect with psql dp_fixture, and keep the same session for every statement unless a step says otherwise. Every output block below is expected output from an unexecuted fixture, not a captured transcript — run it yourself and compare.
Create the app role and the schema.
CREATE ROLE app_rw LOGIN PASSWORD 'change_me';thenCREATE SCHEMA app;. Expected:CREATE ROLEandCREATE SCHEMA.Grant schema access.
GRANT USAGE ON SCHEMA app TO app_rw;. Expected:GRANT. WithoutUSAGE, table privileges are unusable because the role cannot resolve names in the schema.Set the table defaults. As the role that will create tables:
ALTER DEFAULT PRIVILEGES IN SCHEMA app
GRANT SELECT, INSERT, UPDATE, DELETE ON TABLES TO app_rw;
Expected: ALTER DEFAULT PRIVILEGES.
Set the sequence defaults. A
serialor identity column draws from a sequence object with its own ACL, so table grants alone leaveINSERTfailing atnextval. Grant sequence privileges in the same schema:
ALTER DEFAULT PRIVILEGES IN SCHEMA app
GRANT USAGE, SELECT ON SEQUENCES TO app_rw;
Expected: ALTER DEFAULT PRIVILEGES. The CREATE SEQUENCE page documents OWNED BY, which ties a sequence's lifetime to its column but does not transfer privileges.
Create a test table with a
bigserialcolumn.
CREATE TABLE app.orders (
id bigserial PRIMARY KEY,
note text
);
Expected: CREATE TABLE, plus a notice that the implicit sequence was created.
Verify before you trust it. Move to the verification queries in the next section; do not consider the change complete until they pass.
How Do I Prove a New Table Received the Intended Grants?
Query the object's actual ACL through the privilege-test functions, then compare against the configured defaults. The system information functions page lists has_table_privilege, has_sequence_privilege and has_schema_privilege with their allowable privilege types.
SELECT
has_schema_privilege('app_rw', 'app', 'USAGE') AS schema_usage,
has_table_privilege('app_rw', 'app.orders', 'SELECT') AS tbl_select,
has_table_privilege('app_rw', 'app.orders', 'INSERT') AS tbl_insert,
has_sequence_privilege('app_rw', 'app.orders_id_seq', 'USAGE') AS seq_usage;
Expected output from the unexecuted fixture:
schema_usage | tbl_select | tbl_insert | seq_usage
--------------+------------+------------+-----------
t | t | t | t
(1 row)
Next, confirm the configured defaults are attached to the right role and schema. This query joins pg_default_acl to pg_roles and pg_namespace so a zero namespace is visible as a global entry:
SELECT r.rolname,
COALESCE(n.nspname, '(global)') AS scope,
d.defaclobjtype,
d.defaclacl
FROM pg_default_acl d
JOIN pg_roles r ON r.oid = d.defaclrole
LEFT JOIN pg_namespace n ON n.oid = d.defaclnamespace
ORDER BY 1, 2, 3;
Expected output from the unexecuted fixture (ACL text varies with the creating role's name):
rolname | scope | defaclobjtype | defaclacl
---------+---------+---------------+--------------------------
deploy | app | r | {deploy=arwdDxt/deploy,app_rw=arwd/deploy}
deploy | app | S | {deploy=rwU/deploy,app_rw=rU/deploy}
(2 rows)
Finally, read the psql front ends: ddp lists configured default ACLs, and dp app.orders shows the table's actual ACL. Expected from the unexecuted fixture: ddp shows two rows under deploy with schema app, and dp shows app_rw=arwd/deploy on the table. Pass rule: every check returns t and ddp shows the entry under the creating role and the intended schema. Any f is a failure to investigate before the change ships.
Why Did My Default Privileges Not Apply to a Table Created by Another Role?
The table was created by a role whose defaults you did not set, and defaults are not inherited through membership. Work the diagnostic order rather than guessing.
Confirm the creator.
dt+ app.ordersshows the owner column, or querySELECT relowner::regrole FROM pg_class WHERE oid = 'app.orders'::regclass;.Confirm the schema the table landed in. A table created without schema qualification goes to the first writable schema in
search_path, which may not be the one you configured.Check
ddpfor an entry under that creator. If the owner isdeployand your entry is underapp_owner, that is the whole story.Check whether you expected a per-schema entry to override a global one. It cannot; per-schema entries only add.
The fix is to target the actual creator with FOR ROLE, or to run the DDL as the role that holds the defaults. Either way, correcting the defaults does not retroactively repair the table already created — that needs an explicit GRANT on the existing object.
Why Does My App Role Still Get Permission Denied on INSERT?
The table grant usually succeeded; something adjacent to it did not. Triage in this order, one query per cause.
Sequence privilege. Check
SELECT has_sequence_privilege('app_rw', 'app.orders_id_seq', 'USAGE');. Aserialor identity column callsnextval, which requiresUSAGEon the sequence object.Schema
USAGE. CheckSELECT has_schema_privilege('app_rw', 'app', 'USAGE');. Without it the role cannot look up objects in the schema even when the table ACL is correct.Row-level security. Check
SELECT row_security_active('app.orders');in the app role's context. If RLS is active, the insert may be rejected by a policy rather than by a table privilege, and the error text will differ.
If all three checks return the expected values and the insert still fails, capture the exact error message and the statement — the remaining causes are not distinguishable by these queries alone.
Do Default Privileges Change Permissions on Existing Tables?
No. ALTER DEFAULT PRIVILEGES affects only objects created afterward, and existing objects keep their current ACL. A migration that introduces defaults mid-project therefore leaves every earlier table untouched.
Backfill explicitly, once, for objects that already exist:
GRANT SELECT, INSERT, UPDATE, DELETE ON ALL TABLES IN SCHEMA app TO app_rw;
GRANT USAGE, SELECT ON ALL SEQUENCES IN SCHEMA app TO app_rw;
That statement covers the tables present when it runs; it is not a standing rule, so either re-run it after each migration that creates objects outside the defaults or rely on the defaults going forward and treat the backfill as a one-time catch-up.
You can tell the two apart in dp. An object whose privileges came from ALTER DEFAULT PRIVILEGES always shows an explicit privilege entry that includes the effects of the ALTER, whereas an empty access-privileges column means the built-in default applies — a null ACL entry represents the hard-wired default, not whatever currently sits in pg_default_acl.
Which Catalog Views Show Default ACLs Versus Actual Table ACLs?
pg_default_acl holds configured defaults and is consulted only during object creation; pg_class.relacl holds the object's actual ACL. The psql front ends are ddp for defaults and dp (or \z) for objects, both documented on the psql page, and the privileges chapter explains how the ACL entries are displayed.
The trap worth memorizing: when an ACL entry in another catalog is null, it represents the hard-wired default privileges for its object, not whatever might be in pg_default_acl at the moment. Reading relacl as a proxy for your configured defaults will mislead you on every table created before the change.
information_schema.role_table_grants is a convenient reporting view, but the role_table_grants documentation notes that it omits tables made accessible to the current user by way of a grant to PUBLIC — so it is not a complete audit source. For column-scoped grants, the companion technique in PostgreSQL column privileges covers granting and testing at column granularity, which has_table_privilege alone will not confirm. When these checks need to run as standing audit evidence rather than a one-off query, see Compliance Automation: Controls, Evidence and Operational Gains.
Reusable Checklist for Default-Privilege Changes
Paste this into the change ticket and tick each item against a real query result, not an assumption.
Creating role identified by name, and it matches the role the migration actually connects as.
Target schema named explicitly;
search_pathat creation time confirmed.Table defaults present:
SELECT, INSERT, UPDATE, DELETE(or the subset the app needs).Sequence defaults present:
USAGE, SELECTon sequences in the same schema.Schema
USAGEgranted to the app role.ddpshows the entry under the correct role and schema.A freshly created test table passes
has_table_privilegeandhas_sequence_privilegefor every intended privilege.Existing objects backfilled with an explicit
GRANT ... ON ALL TABLES IN SCHEMA.Role-drop procedure accounts for the default ACL entries — reverse them or use
DROP OWNED BY, since a role with altered defaults cannot simply be dropped.The same statements are committed to the migration repository and applied in every environment and database, not just the one where the problem appeared.
Where Default Privileges Fit in a Governed Data Platform
Default privileges are a per-database, per-role control. They are not global to a cluster and they are not versioned by PostgreSQL itself, so the only way to keep them consistent is to codify them in migrations and verify them in CI with the same privilege-test queries you ran above. A team that treats ALTER DEFAULT PRIVILEGES as a one-off console command will eventually find one environment where the entry is missing, and the failure will surface as a permission error in production rather than in review.
Singdata's lakehouse and Postgres-based systems are where some teams apply and audit that access policy across environments, alongside the rest of their data governance controls; the mechanism itself remains the PostgreSQL one described here, and the checklist above is what makes it verifiable.
Frequently Asked Questions
Do default privileges apply to tables that already exist? No. The command sets privileges for objects created in the future and does not affect privileges assigned to already-existing objects. Backfill existing tables with an explicit GRANT ... ON ALL TABLES IN SCHEMA.
Why did defaults not apply to a table created by another role? At creation time only the current role's default privileges apply, and they are not inherited from roles the current role is a member of. Target the actual creator with FOR ROLE, or run the DDL as the role that holds the defaults.
Why does INSERT still fail after table defaults are set? Most often the sequence behind a serial or identity column lacks USAGE, or the role lacks schema USAGE. Check both with has_sequence_privilege and has_schema_privilege before looking further.
Can a schema-scoped REVOKE override a global GRANT? No. Per-schema default privileges can only add to the global setting, so a per-schema REVOKE is useful only to reverse a previous per-schema GRANT. To remove a globally granted privilege, use a global REVOKE.
Which view shows configured defaults versus actual ACLs? pg_default_acl (or ddp) shows configured defaults; pg_class.relacl (or dp) shows the object's actual ACL. A null relacl means the hard-wired default, not the contents of pg_default_acl. The ALTER DEFAULT PRIVILEGES reference carries the governing rules for all of these.