ALTER ROLE
Changes a database role (user or group).
Synopsis
ALTER ROLE <name> RENAME TO <new_name>
ALTER ROLE { <name> | ALL } [ IN DATABASE <database_name> ] SET <configuration_parameter> { TO | = } { <value> | DEFAULT }
ALTER ROLE { <name> | ALL } [ IN DATABASE <database_name> ] SET <configuration_parameter> FROM CURRENT
ALTER ROLE { <name> | ALL } [ IN DATABASE <database_name> ] RESET <configuration_parameter>
ALTER ROLE { <name> | ALL } [ IN DATABASE <database_name> ] RESET ALL
ALTER ROLE <name> RESOURCE QUEUE {<queue_name> | NONE}
ALTER ROLE <name> RESOURCE GROUP {<group_name> | NONE}
ALTER ROLE <name> [ [ WITH ] <option> [ ... ] ]
where option can be:
SUPERUSER | NOSUPERUSER
| CREATEDB | NOCREATEDB
| CREATEROLE | NOCREATEROLE
| CREATEEXTTABLE | NOCREATEEXTTABLE [ ( <attribute>='<value>' [, ...] ) ]
| INHERIT | NOINHERIT
| LOGIN | NOLOGIN
| REPLICATION | NOREPLICATION
| CONNECTION LIMIT <connlimit>
| [ ENCRYPTED | UNENCRYPTED ] PASSWORD '<password>'
| VALID UNTIL '<timestamp>'
where attribute and value are:
type='readable'|'writable'
protocol='gpfdist'|'gpfdists'|'http'
Description
ALTER ROLE changes the attributes of a Greengage DB role.
There are several variants of this command.
-
WITH <option>— changes many of the role attributes that can be specified inCREATE ROLE. All of the possible attributes are covered, except that there are no options for adding or removing memberships; useGRANTandREVOKEfor that. Attributes not mentioned in the command retain their previous settings. Database superusers can change any of these settings for any role. Roles having theCREATEROLEprivilege can change any of these settings, but only for non-superuser and non-replication roles. Ordinary roles can only change their own password. -
RENAME— changes the name of the role. Database superusers can rename any role. Roles having theCREATEROLEprivilege can rename non-superuser roles. The current session user cannot be renamed (connect as a different user to rename a role). Because MD5-encrypted passwords use the role name as cryptographic salt, renaming a role clears its password if the password is MD5-encrypted. -
SET | RESET— changes a role’s session default for a specified configuration parameter, either for all databases or, when theIN DATABASEclause is specified, only for sessions in the named database. IfALLis specified instead of a role name, this changes the setting for all roles. UsingALLwithIN DATABASEis effectively the same as using the commandALTER DATABASE … SET ….Whenever the role subsequently starts a new session, the specified value becomes the session default, overriding whatever setting is present in the server configuration file (postgresql.conf) or has been received from the
postgrescommand line. This only happens at login time; runningSET ROLEorSET SESSION AUTHORIZATIONdoes not cause new configuration values to be set.Database-specific settings attached to a role override settings for all databases. Settings for specific databases or specific roles override settings for all roles.
For a role without
LOGINprivilege, session defaults have no effect. Ordinary roles can change their own session defaults. Superusers can change anyone’s session defaults. Roles havingCREATEROLEprivilege can change defaults for non-superuser roles. Ordinary roles can only set defaults for themselves. Certain configuration variables cannot be set this way, or can only be set if a superuser issues the command. Only superusers can change a setting for all roles in all databases. -
RESOURCE QUEUE— assigns the role to a resource queue. The role would then be subject to the limits assigned to the resource queue when issuing queries. SpecifyNONEto assign the role to the default resource queue. A role can only belong to one resource queue. For a role withoutLOGINprivilege, resource queues have no effect. SeeCREATE RESOURCE QUEUEfor more information. -
RESOURCE GROUP— assigns a resource group to the role. The role would then be subject to the concurrent transaction, memory, and CPU limits configured for the resource group. You can assign a single resource group to one or more roles. You cannot assign a resource group that you create for an external component to a role. SeeCREATE RESOURCE GROUPfor additional information.
Parameters
| Parameter | Description |
|---|---|
name |
The name of the role whose attributes are to be altered |
new_name |
The new name of the role |
database_name |
The name of the database in which to set the configuration parameter |
<configuration_parameter>=<value> |
Set this role’s session default for the specified configuration parameter to the given value.
If value is Role-specific variable settings take effect only at login; |
group_name |
The name of the resource group to assign to this role.
Setting the |
queue_name |
The name of the resource queue to which the user-level role is to be assigned.
Only roles with |
SUPERUSER | NOSUPERUSER |
|
CREATEEXTTABLE | NOCREATEEXTTABLE [(<attribute>='<value>')] |
If |
INHERIT | NOINHERIT |
These clauses alter role attributes originally set by |
DENY <deny_point> DENY BETWEEN <deny_point> AND <deny_point> |
The
The two parts of the
For
The
For example:
|
DROP DENY FOR <deny_point> |
The |
Notes
Use CREATE ROLE to add new roles, and DROP ROLE to remove a role.
Use GRANT and REVOKE for adding and removing role memberships.
Caution must be exercised when specifying an unencrypted password with this command.
The password will be transmitted to the server in clear text, and it might also be logged in the client’s command history or the server log.
The psql command-line client contains a meta-command \password that can be used to change a role’s password without exposing the clear text password.
It is also possible to tie a session default to a specific database rather than to a role; see ALTER DATABASE.
If there is a conflict, database-role-specific settings override role-specific ones, which in turn override database-specific ones.
Examples
Change the password for a role:
ALTER ROLE daria WITH PASSWORD 'passwd123';
Remove a role’s password:
ALTER ROLE daria WITH PASSWORD NULL;
Change a password expiration date:
ALTER ROLE scott VALID UNTIL 'May 4 12:00:00 2015 +1';
Make a password valid forever:
ALTER ROLE luke VALID UNTIL 'infinity';
Give a role the ability to create other roles and new databases:
ALTER ROLE anakin CREATEROLE CREATEDB;
Give a role a non-default setting of the maintenance_work_mem parameter:
ALTER ROLE admin SET maintenance_work_mem = 100000;
Give a role a non-default, database-specific setting of the client_min_messages parameter:
ALTER ROLE fred IN DATABASE devel SET client_min_messages = DEBUG;
Assign a role to a resource queue:
ALTER ROLE darth RESOURCE QUEUE poweruser;
Give a role permission to create writable external tables:
ALTER ROLE load CREATEEXTTABLE (type='writable');
Alter a role so it does not allow login access on Sundays:
ALTER ROLE user3 DENY DAY 'Sunday';
Alter a role to remove the constraint that does not allow login access on Sundays:
ALTER ROLE user3 DROP DENY FOR DAY 'Sunday';
Assign a new resource group to a role:
ALTER ROLE parttime_user RESOURCE GROUP rg_light;
Compatibility
The ALTER ROLE statement is a Greengage DB extension.