ALTER_DEFAULT_PRIVILEGES(7)
โจ ALTER_DEFAULT_PRIVILEGES โจ
okay bestie, gather round, because this is the page for ALTER_DEFAULT_PRIVILEGES (that's the 7 manual, we're in PostgreSQL 18.6 Documentation land ๐
). it's literally about setting the default access privileges โ i.e. the rules that get auto-applied to stuff you haven't even created yet. iconic behavior tbh. ๐
๐ธ NAME ๐ธ
ALTER_DEFAULT_PRIVILEGES โ define default access privileges
๐ฆ SYNOPSIS ๐ฆ
ALTER DEFAULT PRIVILEGES
[ FOR { ROLE | USER } target_role [, ...] ]
[ IN SCHEMA schema_name [, ...] ]
abbreviated_grant_or_revoke
where abbreviated_grant_or_revoke is one of:
GRANT { { SELECT | INSERT | UPDATE | DELETE | TRUNCATE | REFERENCES | TRIGGER | MAINTAIN }
[, ...] | ALL [ PRIVILEGES ] }
ON TABLES
TO { [ GROUP ] role_name | PUBLIC } [, ...] [ WITH GRANT OPTION ]
GRANT { { USAGE | SELECT | UPDATE }
[, ...] | ALL [ PRIVILEGES ] }
ON SEQUENCES
TO { [ GROUP ] role_name | PUBLIC } [, ...] [ WITH GRANT OPTION ]
GRANT { EXECUTE | ALL [ PRIVILEGES ] }
ON { FUNCTIONS | ROUTINES }
TO { [ GROUP ] role_name | PUBLIC } [, ...] [ WITH GRANT OPTION ]
GRANT { USAGE | ALL [ PRIVILEGES ] }
ON TYPES
TO { [ GROUP ] role_name | PUBLIC } [, ...] [ WITH GRANT OPTION ]
GRANT { { USAGE | CREATE }
[, ...] | ALL [ PRIVILEGES ] }
ON SCHEMAS
TO { [ GROUP ] role_name | PUBLIC } [, ...] [ WITH GRANT OPTION ]
GRANT { { SELECT | UPDATE }
[, ...] | ALL [ PRIVILEGES ] }
ON LARGE OBJECTS
TO { [ GROUP ] role_name | PUBLIC } [, ...] [ WITH GRANT OPTION ]
REVOKE [ GRANT OPTION FOR ]
{ { SELECT | INSERT | UPDATE | DELETE | TRUNCATE | REFERENCES | TRIGGER | MAINTAIN }
[, ...] | ALL [ PRIVILEGES ] }
ON TABLES
FROM { [ GROUP ] role_name | PUBLIC } [, ...]
[ CASCADE | RESTRICT ]
REVOKE [ GRANT OPTION FOR ]
{ { USAGE | SELECT | UPDATE }
[, ...] | ALL [ PRIVILEGES ] }
ON SEQUENCES
FROM { [ GROUP ] role_name | PUBLIC } [, ...]
[ CASCADE | RESTRICT ]
REVOKE [ GRANT OPTION FOR ]
{ EXECUTE | ALL [ PRIVILEGES ] }
ON { FUNCTIONS | ROUTINES }
FROM { [ GROUP ] role_name | PUBLIC } [, ...]
[ CASCADE | RESTRICT ]
REVOKE [ GRANT OPTION FOR ]
{ USAGE | ALL [ PRIVILEGES ] }
ON TYPES
FROM { [ GROUP ] role_name | PUBLIC } [, ...]
[ CASCADE | RESTRICT ]
REVOKE [ GRANT OPTION FOR ]
{ { USAGE | CREATE }
[, ...] | ALL [ PRIVILEGES ] }
ON SCHEMAS
FROM { [ GROUP ] role_name | PUBLIC } [, ...]
[ CASCADE | RESTRICT ]
REVOKE [ GRANT OPTION FOR ]
{ { SELECT | UPDATE }
[, ...] | ALL [ PRIVILEGES ] }
ON LARGE OBJECTS
FROM { [ GROUP ] role_name | PUBLIC } [, ...]
[ CASCADE | RESTRICT ]
๐ DESCRIPTION ๐
so ALTER DEFAULT PRIVILEGES lets you set the privileges that get applied to objects created in the future. huge distinction, okay? it does not affect privileges assigned to objects that already exist. past is past, she's not coming back. ๐
you can set these privileges globally (i.e., for all objects created in the current database), or just for objects created in specific schemas you name. pick your vibe.
and here's a little plot twist ๐ โ while you can change your own default privileges and the defaults of roles that you're 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. so no, your friend's defaults don't rub off on you. main character energy only. โจ
as explained in Section 5.8, the default privileges for any object type normally grant all grantable permissions to the object owner, and may grant some privileges to PUBLIC as well. but this behavior can be changed by altering the global default privileges with ALTER DEFAULT PRIVILEGES. slay, customization.
currently, only the privileges for schemas, tables (including views and foreign tables), sequences, functions, types (including domains), and large objects can be altered. for this command, functions include aggregates and procedures. the words FUNCTIONS and ROUTINES are equivalent in this command. (ROUTINES is preferred going forward as the standard term for functions and procedures taken together. in earlier PostgreSQL releases, only the word FUNCTIONS was allowed. it is not possible to set default privileges for functions and procedures separately โ they're a package deal, bestie. ๐ซถ)
default privileges that are specified per-schema get added to whatever the global default privileges are for that particular object type. which meansโฆ you cannot revoke privileges per-schema if they are granted globally (either by default, or according to a previous ALTER DEFAULT PRIVILEGES command that didn't specify a schema). per-schema REVOKE is only useful to reverse the effects of a previous per-schema GRANT. it's giving subtraction-only-if-you-added-it. ๐ญ
๐ Parameters ๐
target_roleโ change default privileges for objects created by thetarget_role, or the current role if unspecified.schema_nameโ the name of an existing schema. if specified, the default privileges are altered for objects later created in that schema. ifIN SCHEMAis omitted, the global default privileges are altered.IN SCHEMAis not allowed when setting privileges for schemas and large objects, since schemas can't be nested and large objects don't belong to a schema. no nesting, no schema-having, sorry. ๐role_nameโ the name of an existing role to grant or revoke privileges for. this parameter, and all the other parameters inabbreviated_grant_or_revoke, act as described underGRANT(7)orREVOKE(7), except that one is setting permissions for a whole class of objects rather than specific named objects. it's the group-chat version of permissions, not the DM version. ๐ฌ
๐ฅ NOTES ๐ฅ
use psql(1)'s \ddp command to obtain information about existing assignments of default privileges. the meaning of the privilege display is the same as explained for \dp in Section 5.8. go peek, it's lowkey satisfying. ๐
if you wish to drop a role for which the default privileges have been altered, it is necessary to reverse the changes in its default privileges or use DROP OWNED BY to get rid of the default privileges entry for the role. you can't just ghost a role that still has default privileges on the books, bestie โ clean up your mess first. ๐
๐ EXAMPLES ๐
grant SELECT privilege to everyone for all tables (and views) you subsequently create in schema myschema, and allow role webuser to INSERT into them too:
ALTER DEFAULT PRIVILEGES IN SCHEMA myschema GRANT SELECT ON TABLES TO PUBLIC;
ALTER DEFAULT PRIVILEGES IN SCHEMA myschema GRANT INSERT ON TABLES TO webuser;
undo the above, so that subsequently-created tables won't have any more permissions than normal:
ALTER DEFAULT PRIVILEGES IN SCHEMA myschema REVOKE SELECT ON TABLES FROM PUBLIC;
ALTER DEFAULT PRIVILEGES IN SCHEMA myschema REVOKE INSERT ON TABLES FROM webuser;
remove the public EXECUTE permission that is normally granted on functions, for all functions subsequently created by role admin:
ALTER DEFAULT PRIVILEGES FOR ROLE admin REVOKE EXECUTE ON FUNCTIONS FROM PUBLIC;
note however that you cannot accomplish that effect with a command limited to a single schema. this command has no effect, unless it is undoing a matching GRANT:
ALTER DEFAULT PRIVILEGES IN SCHEMA public REVOKE EXECUTE ON FUNCTIONS FROM PUBLIC;
that's because per-schema default privileges can only add privileges to the global setting, not remove privileges granted by it. the way that global settings are just built differentโฆ periodt. ๐
โญ COMPATIBILITY โญ
there is no ALTER DEFAULT PRIVILEGES statement in the SQL standard. it's a PostgreSQL original, we don't follow trends, we set them. ๐
๐ง SEE ALSO ๐ง
and that's the whole page, bestie! ๐ซถ this was PostgreSQL 18.6, dated 2026, and you just read the ALTER_DEFAULT_PRIVILEGES(7) manual page. go forth and set some defaults. you ate. ๐โจ๐
๐ฆ where this page comes from
- alpine 3.23: postgresql18-doc 18.6-r0 ยท PostgreSQL
- alpine 3.24: postgresql18-doc 18.6-r0 ยท PostgreSQL
- arch rolling: postgresql 18.6-4 ยท PostgreSQL
- fedora 43: postgresql 18.6-1.fc43 ยท PostgreSQL
- fedora 43: postgresql 18.6-1.fc43 ยท PostgreSQL
- fedora 44: postgresql 18.6-1.fc44 ยท PostgreSQL
- fedora 44: postgresql 18.6-1.fc44 ยท PostgreSQL
- nixos 26.05: postgresql 18.6
- ubuntu resolute: postgresql-client-18 18.6-0ubuntu0.26.04.1 ยท PostgreSQL
- ubuntu stonking: postgresql-client-18 18.6-3build2 ยท PostgreSQL
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms