1ALTER ROLE(7) PostgreSQL 10.7 Documentation ALTER ROLE(7)
2
3
4
6 ALTER_ROLE - change a database role
7
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'
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_USER
35 | SESSION_USER
36
38 ALTER ROLE changes the attributes of a PostgreSQL role.
39
40 The first variant of this command listed in the synopsis can change
41 many of the role attributes that can be specified in CREATE ROLE
42 (CREATE_ROLE(7)). (All the possible attributes are covered, except that
43 there are no options for adding or removing memberships; use GRANT(7)
44 and REVOKE(7) for that.) Attributes not mentioned in the command retain
45 their previous settings. Database superusers can change any of these
46 settings for any role. Roles having CREATEROLE privilege can change any
47 of these settings, but only for non-superuser and non-replication
48 roles. Ordinary roles can only change their own password.
49
50 The second variant changes the name of the role. Database superusers
51 can rename any role. Roles having CREATEROLE privilege can rename
52 non-superuser roles. The current session user cannot be renamed.
53 (Connect as a different user if you need to do that.) Because
54 MD5-encrypted passwords use the role name as cryptographic salt,
55 renaming a role clears its password if the password is MD5-encrypted.
56
57 The remaining variants change a role's session default for a
58 configuration variable, either for all databases or, when the IN
59 DATABASE clause is specified, only for sessions in the named database.
60 If ALL is specified instead of a role name, this changes the setting
61 for all roles. Using ALL with IN DATABASE is effectively the same as
62 using the command ALTER DATABASE ... SET ....
63
64 Whenever the role subsequently starts a new session, the specified
65 value becomes the session default, overriding whatever setting is
66 present in postgresql.conf or has been received from the postgres
67 command line. This only happens at login time; executing SET ROLE
68 (SET_ROLE(7)) or SET SESSION AUTHORIZATION
69 (SET_SESSION_AUTHORIZATION(7)) does not cause new configuration values
70 to be set. Settings set for all databases are overridden by
71 database-specific settings attached to a role. Settings for specific
72 databases or specific roles override settings for all roles.
73
74 Superusers can change anyone's session defaults. Roles having
75 CREATEROLE privilege can change defaults for non-superuser roles.
76 Ordinary roles can only set defaults for themselves. Certain
77 configuration variables cannot be set this way, or can only be set if a
78 superuser issues the command. Only superusers can change a setting for
79 all roles in all databases.
80
82 name
83 The name of the role whose attributes are to be altered.
84
85 CURRENT_USER
86 Alter the current user instead of an explicitly identified role.
87
88 SESSION_USER
89 Alter the current session user instead of an explicitly identified
90 role.
91
92 SUPERUSER
93 NOSUPERUSER
94 CREATEDB
95 NOCREATEDB
96 CREATEROLE
97 NOCREATEROLE
98 INHERIT
99 NOINHERIT
100 LOGIN
101 NOLOGIN
102 REPLICATION
103 NOREPLICATION
104 BYPASSRLS
105 NOBYPASSRLS
106 CONNECTION LIMIT connlimit
107 [ ENCRYPTED ] PASSWORD password
108 VALID UNTIL 'timestamp'
109 These clauses alter attributes originally set by CREATE ROLE
110 (CREATE_ROLE(7)). For more information, see the CREATE ROLE
111 reference page.
112
113 new_name
114 The new name of the role.
115
116 database_name
117 The name of the database the configuration variable should be set
118 in.
119
120 configuration_parameter
121 value
122 Set this role's session default for the specified configuration
123 parameter to the given value. If value is DEFAULT or, equivalently,
124 RESET is used, the role-specific variable setting is removed, so
125 the role will inherit the system-wide default setting in new
126 sessions. Use RESET ALL to clear all role-specific settings. SET
127 FROM CURRENT saves the session's current value of the parameter as
128 the role-specific value. If IN DATABASE is specified, the
129 configuration parameter is set or removed for the given role and
130 database only.
131
132 Role-specific variable settings take effect only at login; SET ROLE
133 (SET_ROLE(7)) and SET SESSION AUTHORIZATION
134 (SET_SESSION_AUTHORIZATION(7)) do not process role-specific
135 variable settings.
136
137 See SET(7) and Chapter 19 for more information about allowed
138 parameter names and values.
139
141 Use CREATE ROLE (CREATE_ROLE(7)) to add new roles, and DROP ROLE
142 (DROP_ROLE(7)) to remove a role.
143
144 ALTER ROLE cannot change a role's memberships. Use GRANT(7) and
145 REVOKE(7) to do that.
146
147 Caution must be exercised when specifying an unencrypted password with
148 this command. The password will be transmitted to the server in
149 cleartext, and it might also be logged in the client's command history
150 or the server log. psql(1) contains a command \password that can be
151 used to change a role's password without exposing the cleartext
152 password.
153
154 It is also possible to tie a session default to a specific database
155 rather than to a role; see ALTER DATABASE (ALTER_DATABASE(7)). If there
156 is a conflict, database-role-specific settings override role-specific
157 ones, which in turn override database-specific ones.
158
160 Change a role's password:
161
162 ALTER ROLE davide WITH PASSWORD 'hu8jmn3';
163
164 Remove a role's password:
165
166 ALTER ROLE davide WITH PASSWORD NULL;
167
168 Change a password expiration date, specifying that the password should
169 expire at midday on 4th May 2015 using the time zone which is one hour
170 ahead of UTC:
171
172 ALTER ROLE chris VALID UNTIL 'May 4 12:00:00 2015 +1';
173
174 Make a password valid forever:
175
176 ALTER ROLE fred VALID UNTIL 'infinity';
177
178 Give a role the ability to create other roles and new databases:
179
180 ALTER ROLE miriam CREATEROLE CREATEDB;
181
182 Give a role a non-default setting of the maintenance_work_mem
183 parameter:
184
185 ALTER ROLE worker_bee SET maintenance_work_mem = 100000;
186
187 Give a role a non-default, database-specific setting of the
188 client_min_messages parameter:
189
190 ALTER ROLE fred IN DATABASE devel SET client_min_messages = DEBUG;
191
193 The ALTER ROLE statement is a PostgreSQL extension.
194
196 CREATE ROLE (CREATE_ROLE(7)), DROP ROLE (DROP_ROLE(7)), ALTER DATABASE
197 (ALTER_DATABASE(7)), SET(7)
198
199
200
201PostgreSQL 10.7 2019 ALTER ROLE(7)