1ALTER ROLE(7)            PostgreSQL 16.1 Documentation           ALTER ROLE(7)
2
3
4

NAME

6       ALTER_ROLE - change a database role
7

SYNOPSIS

9       ALTER ROLE role_specification [ WITH ] option [ ... ]
10
11       where option can be:
12
13             SUPERUSER | NOSUPERUSER
14           | CREATEDB | NOCREATEDB
15           | CREATEROLE | NOCREATEROLE
16           | INHERIT | NOINHERIT
17           | LOGIN | NOLOGIN
18           | REPLICATION | NOREPLICATION
19           | BYPASSRLS | NOBYPASSRLS
20           | CONNECTION LIMIT connlimit
21           | [ ENCRYPTED ] PASSWORD 'password' | PASSWORD NULL
22           | VALID UNTIL 'timestamp'
23
24       ALTER ROLE name RENAME TO new_name
25
26       ALTER ROLE { role_specification | ALL } [ IN DATABASE database_name ] SET configuration_parameter { TO | = } { value | DEFAULT }
27       ALTER ROLE { role_specification | ALL } [ IN DATABASE database_name ] SET configuration_parameter FROM CURRENT
28       ALTER ROLE { role_specification | ALL } [ IN DATABASE database_name ] RESET configuration_parameter
29       ALTER ROLE { role_specification | ALL } [ IN DATABASE database_name ] RESET ALL
30
31       where role_specification can be:
32
33           role_name
34         | CURRENT_ROLE
35         | CURRENT_USER
36         | SESSION_USER
37

DESCRIPTION

39       ALTER ROLE changes the attributes of a PostgreSQL role.
40
41       The first variant of this command listed in the synopsis can change
42       many of the role attributes that can be specified in CREATE ROLE. (All
43       the possible attributes are covered, except that there are no options
44       for adding or removing memberships; use GRANT and REVOKE for that.)
45       Attributes not mentioned in the command retain their previous settings.
46       Database superusers can change any of these settings for any role.
47       Non-superuser roles having CREATEROLE privilege can change most of
48       these properties, but only for non-superuser and non-replication roles
49       for which they have been granted ADMIN OPTION. Non-superusers cannot
50       change the SUPERUSER property and can change the CREATEDB, REPLICATION,
51       and BYPASSRLS properties only if they possess the corresponding
52       property themselves. Ordinary roles can only change their own password.
53
54       The second variant changes the name of the role. Database superusers
55       can rename any role. Roles having CREATEROLE privilege can rename
56       non-superuser roles for which they have been granted ADMIN OPTION. The
57       current session user cannot be renamed. (Connect as a different user if
58       you need to do that.) Because MD5-encrypted passwords use the role name
59       as cryptographic salt, renaming a role clears its password if the
60       password is MD5-encrypted.
61
62       The remaining variants change a role's session default for a
63       configuration variable, either for all databases or, when the IN
64       DATABASE clause is specified, only for sessions in the named database.
65       If ALL is specified instead of a role name, this changes the setting
66       for all roles. Using ALL with IN DATABASE is effectively the same as
67       using the command ALTER DATABASE ... SET ....
68
69       Whenever the role subsequently starts a new session, the specified
70       value becomes the session default, overriding whatever setting is
71       present in postgresql.conf or has been received from the postgres
72       command line. This only happens at login time; executing SET ROLE or
73       SET SESSION AUTHORIZATION does not cause new configuration values to be
74       set. Settings set for all databases are overridden by database-specific
75       settings attached to a role. Settings for specific databases or
76       specific roles override settings for all roles.
77
78       Superusers can change anyone's session defaults. Roles having
79       CREATEROLE privilege can change defaults for non-superuser roles for
80       which they have been granted ADMIN OPTION. Ordinary roles can only set
81       defaults for themselves. Certain configuration variables cannot be set
82       this way, or can only be set if a superuser issues the command. Only
83       superusers can change a setting for all roles in all databases.
84

PARAMETERS

86       name
87           The name of the role whose attributes are to be altered.
88
89       CURRENT_ROLE
90       CURRENT_USER
91           Alter the current user instead of an explicitly identified role.
92
93       SESSION_USER
94           Alter the current session user instead of an explicitly identified
95           role.
96
97       SUPERUSER
98       NOSUPERUSER
99       CREATEDB
100       NOCREATEDB
101       CREATEROLE
102       NOCREATEROLE
103       INHERIT
104       NOINHERIT
105       LOGIN
106       NOLOGIN
107       REPLICATION
108       NOREPLICATION
109       BYPASSRLS
110       NOBYPASSRLS
111       CONNECTION LIMIT connlimit
112       [ ENCRYPTED ] PASSWORD 'password'
113       PASSWORD NULL
114       VALID UNTIL 'timestamp'
115           These clauses alter attributes originally set by CREATE ROLE. For
116           more information, see the CREATE ROLE reference page.
117
118       new_name
119           The new name of the role.
120
121       database_name
122           The name of the database the configuration variable should be set
123           in.
124
125       configuration_parameter
126       value
127           Set this role's session default for the specified configuration
128           parameter to the given value. If value is DEFAULT or, equivalently,
129           RESET is used, the role-specific variable setting is removed, so
130           the role will inherit the system-wide default setting in new
131           sessions. Use RESET ALL to clear all role-specific settings.  SET
132           FROM CURRENT saves the session's current value of the parameter as
133           the role-specific value. If IN DATABASE is specified, the
134           configuration parameter is set or removed for the given role and
135           database only.
136
137           Role-specific variable settings take effect only at login; SET ROLE
138           and SET SESSION AUTHORIZATION do not process role-specific variable
139           settings.
140
141           See SET(7) and Chapter 20 for more information about allowed
142           parameter names and values.
143

NOTES

145       Use CREATE ROLE to add new roles, and DROP ROLE to remove a role.
146
147       ALTER ROLE cannot change a role's memberships. Use GRANT and REVOKE to
148       do that.
149
150       Caution must be exercised when specifying an unencrypted password with
151       this command. The password will be transmitted to the server in
152       cleartext, and it might also be logged in the client's command history
153       or the server log.  psql(1) contains a command \password that can be
154       used to change a role's password without exposing the cleartext
155       password.
156
157       It is also possible to tie a session default to a specific database
158       rather than to a role; see ALTER DATABASE (ALTER_DATABASE(7)). If there
159       is a conflict, database-role-specific settings override role-specific
160       ones, which in turn override database-specific ones.
161

EXAMPLES

163       Change a role's password:
164
165           ALTER ROLE davide WITH PASSWORD 'hu8jmn3';
166
167       Remove a role's password:
168
169           ALTER ROLE davide WITH PASSWORD NULL;
170
171       Change a password expiration date, specifying that the password should
172       expire at midday on 4th May 2015 using the time zone which is one hour
173       ahead of UTC:
174
175           ALTER ROLE chris VALID UNTIL 'May 4 12:00:00 2015 +1';
176
177       Make a password valid forever:
178
179           ALTER ROLE fred VALID UNTIL 'infinity';
180
181       Give a role the ability to manage other roles and create new databases:
182
183           ALTER ROLE miriam CREATEROLE CREATEDB;
184
185       Give a role a non-default setting of the maintenance_work_mem
186       parameter:
187
188           ALTER ROLE worker_bee SET maintenance_work_mem = 100000;
189
190       Give a role a non-default, database-specific setting of the
191       client_min_messages parameter:
192
193           ALTER ROLE fred IN DATABASE devel SET client_min_messages = DEBUG;
194

COMPATIBILITY

196       The ALTER ROLE statement is a PostgreSQL extension.
197

SEE ALSO

199       CREATE ROLE (CREATE_ROLE(7)), DROP ROLE (DROP_ROLE(7)), ALTER DATABASE
200       (ALTER_DATABASE(7)), SET(7)
201
202
203
204PostgreSQL 16.1                      2023                        ALTER ROLE(7)
Impressum