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