News:

GinGly.com - Used by 85,000 Members - SMS Backed up 7,35,000 - Contacts Stored  28,850 !!

Main Menu

ALTER ROLE

Started by dhilipkumar, Dec 13, 2008, 08:36 PM

Previous topic - Next topic

dhilipkumar

ALTER ROLE

Name

ALTER ROLE -- change a database role
Synopsis

ALTER ROLE name [ [ WITH ] option [ ... ] ]

where option can be:
   
      SUPERUSER | NOSUPERUSER
    | CREATEDB | NOCREATEDB
    | CREATEROLE | NOCREATEROLE
    | CREATEUSER | NOCREATEUSER
    | INHERIT | NOINHERIT
    | LOGIN | NOLOGIN
    | CONNECTION LIMIT connlimit
    | [ ENCRYPTED | UNENCRYPTED ] PASSWORD 'password'
    | VALID UNTIL 'timestamp'

ALTER ROLE name RENAME TO newname

ALTER ROLE name SET configuration_parameter { TO | = } { value | DEFAULT }
ALTER ROLE name SET configuration_parameter FROM CURRENT
ALTER ROLE name RESET configuration_parameter
ALTER ROLE name RESET ALL
Description

ALTER ROLE changes the attributes of a PostgreSQL role.

The first variant of this command listed in the synopsis can change many of the role attributes that can be specified in CREATE ROLE. (All the possible attributes are covered, except that there are no options for adding or removing memberships; use GRANT and REVOKE for that.) Attributes not mentioned in the command retain their previous settings. Database superusers can change any of these settings for any role. Roles having CREATEROLE privilege can change any of these settings, but only for non-superuser roles. Ordinary roles can only change their own password.

The second variant changes the name of the role. Database superusers can rename any role. Roles having CREATEROLE privilege can rename non-superuser roles. The current session user cannot be renamed. (Connect as a different user if you need to do that.) Because MD5-encrypted passwords use the role name as cryptographic salt, renaming a role clears its password if the password is MD5-encrypted.

The remaining variants change a role's session default for a specified configuration variable. Whenever the role subsequently starts a new session, the specified value becomes the session default, overriding whatever setting is present in postgresql.conf or has been received from the postgres command line. (For a role without LOGIN privilege, session defaults have no effect.) Ordinary roles can change their own session defaults. Superusers can change anyone's session defaults. Roles having CREATEROLE privilege can change defaults for non-superuser roles. Certain variables cannot be set this way, or can only be set if a superuser issues the command.

Parameters

name
The name of the role whose attributes are to be altered.

SUPERUSER
NOSUPERUSER
CREATEDB
NOCREATEDB
CREATEROLE
NOCREATEROLE
CREATEUSER
NOCREATEUSER
INHERIT
NOINHERIT
LOGIN
NOLOGIN
CONNECTION LIMIT connlimit
PASSWORD password
ENCRYPTED
UNENCRYPTED
VALID UNTIL 'timestamp'
These clauses alter attributes originally set by CREATE ROLE. For more information, see the CREATE ROLE reference page.

newname
The new name of the role.

configuration_parameter
value
Set this role's session default for the specified configuration parameter to the given value. If value is DEFAULT or, equivalently, RESET is used, the role-specific variable setting is removed, so the role will inherit the system-wide default setting in new sessions. Use RESET ALL to clear all role-specific settings. SET FROM CURRENT saves the session's current value of the parameter as the role-specific value.

See SET and Chapter 18 for more information about allowed parameter names and values.

Notes

Use CREATE ROLE to add new roles, and DROP ROLE to remove a role.

ALTER ROLE cannot change a role's memberships. Use GRANT and REVOKE to do that.

Caution must be exercised when specifying an unencrypted password with this command. The password will be transmitted to the server in cleartext, and it might also be logged in the client's command history or the server log. psql contains a command \password that can be used to safely change a role's password.

It is also possible to tie a session default to a specific database rather than to a role; see ALTER DATABASE. Role-specific settings override database-specific ones if there is a conflict.

Examples

Change a role's password:

ALTER ROLE davide WITH PASSWORD 'hu8jmn3';
Remove a role's password:

ALTER ROLE davide WITH PASSWORD NULL;
Change a password expiration date, specifying that the password should expire at midday on 4th May 2015 using the time zone which is one hour ahead of UTC:

ALTER ROLE chris VALID UNTIL 'May 4 12:00:00 2015 +1';
Make a password valid forever:

ALTER ROLE fred VALID UNTIL 'infinity';
Give a role the ability to create other roles and new databases:

ALTER ROLE miriam CREATEROLE CREATEDB;
Give a role a non-default setting of the maintenance_work_mem parameter:

ALTER ROLE worker_bee SET maintenance_work_mem = 100000;


nandagopal



Can you explain about creation of roles clearly




thiruvasagamani

For me also its confusing..
please explain for me also........
Thiruvasakamani Karnan


kavee

hey its new .....informatve for me..thank u for it ....da

VelMurugan

CREATE ROLE

Creates a new database role in the current database.


Syntax

CREATE ROLE role_name [ AUTHORIZATION owner_name ]

Arguments

role_name

    Is the name of the role to be created.

AUTHORIZATION owner_name

    Is the database user or role that is to own the new role. If no user is specified, the role will be owned by the user that executes CREATE ROLE.

Remarks

Roles are database-level securables. After you create a role, configure the database-level permissions of the role by using GRANT, DENY, and REVOKE. To add members to a database role, use the sp_addrolemember stored procedure. For more information, see Database-Level Roles.

Database roles are visible in the sys.database_role_members and sys.database_principals catalog views.

Permissions

Requires CREATE ROLE permission on the database. When you use the AUTHORIZATION option, the following permissions are also required:

    * To assign ownership of a role to another user, requires IMPERSONATE permission on that user.
    * To assign ownership of a role to another role, requires membership in the recipient role or ALTER permission on that role.
    * To assign ownership of a role to an application role, requires ALTER permission on the application role.

Examples


A. Creating a database role that is owned by a database user

The following example creates the database role buyers that is owned by user BenMiller.

USE AdventureWorks;
CREATE ROLE buyers AUTHORIZATION BenMiller;
GO


B. Creating a database role called that is owned by a fixed database role

The following example creates the database role auditors that is owned the db_securityadmin fixed database role.

USE AdventureWorks;
CREATE ROLE auditors AUTHORIZATION db_securityadmin;
GO