create_role.7
来自「PostgreSQL 8.2中增加了很多企业用户所需要的功能和性能上的提高,其开」· 7 代码 · 共 298 行
7
298 行
.\\" auto-generated by docbook2man-spec $Revision: 1.1.1.1 $.TH "CREATE ROLE" "" "2008-01-03" "SQL - Language Statements" "SQL Commands".SH NAMECREATE ROLE \- define a new database role.SH SYNOPSIS.sp.nfCREATE ROLE \fIname\fR [ [ WITH ] \fIoption\fR [ ... ] ]where \fIoption\fR can be: SUPERUSER | NOSUPERUSER | CREATEDB | NOCREATEDB | CREATEROLE | NOCREATEROLE | CREATEUSER | NOCREATEUSER | INHERIT | NOINHERIT | LOGIN | NOLOGIN | CONNECTION LIMIT \fIconnlimit\fR | [ ENCRYPTED | UNENCRYPTED ] PASSWORD '\fIpassword\fR' | VALID UNTIL '\fItimestamp\fR' | IN ROLE \fIrolename\fR [, ...] | IN GROUP \fIrolename\fR [, ...] | ROLE \fIrolename\fR [, ...] | ADMIN \fIrolename\fR [, ...] | USER \fIrolename\fR [, ...] | SYSID \fIuid\fR .sp.fi.SH "DESCRIPTION".PP\fBCREATE ROLE\fR adds a new role to aPostgreSQL database cluster. A role isan entity that can own database objects and have database privileges;a role can be considered a ``user'', a ``group'', or bothdepending on how it is used. Refer toin the documentation and in the documentation for information about managingusers and authentication. You must have CREATEROLEprivilege or be a database superuser to use this command..PPNote that roles are defined at the database clusterlevel, and so are valid in all databases in the cluster..SH "PARAMETERS".TP\fB\fIname\fB\fRThe name of the new role..TP\fBSUPERUSER\fR.TP\fBNOSUPERUSER\fRThese clauses determine whether the new role is a ``superuser'',who can override all access restrictions within the database.Superuser status is dangerous and should be used only when reallyneeded. You must yourself be a superuser to create a new superuser.If not specified,NOSUPERUSER is the default..TP\fBCREATEDB\fR.TP\fBNOCREATEDB\fRThese clauses define a role's ability to create databases. IfCREATEDB is specified, the role beingdefined will be allowed to create new databases. SpecifyingNOCREATEDB will deny a role the ability tocreate databases. If not specified,NOCREATEDB is the default..TP\fBCREATEROLE\fR.TP\fBNOCREATEROLE\fRThese clauses determine whether a role will be permitted tocreate new roles (that is, execute \fBCREATE ROLE\fR).A role with CREATEROLE privilege can also alterand drop other roles.If not specified,NOCREATEROLE is the default..TP\fBCREATEUSER\fR.TP\fBNOCREATEUSER\fRThese clauses are an obsolete, but still accepted, spelling ofSUPERUSER and NOSUPERUSER.Note that they are \fBnot\fR equivalent toCREATEROLE as one might naively expect!.TP\fBINHERIT\fR.TP\fBNOINHERIT\fRThese clauses determine whether a role ``inherits'' theprivileges of roles it is a member of.A role with the INHERIT attribute can automaticallyuse whatever database privileges have been granted to all rolesit is directly or indirectly a member of.Without INHERIT, membership in another roleonly grants the ability to \fBSET ROLE\fR to that other role;the privileges of the other role are only available after havingdone so.If not specified,INHERIT is the default..TP\fBLOGIN\fR.TP\fBNOLOGIN\fRThese clauses determine whether a role is allowed to log in;that is, whether the role can be given as the initial sessionauthorization name during client connection. A role havingthe LOGIN attribute can be thought of as a user.Roles without this attribute are useful for managing databaseprivileges, but are not users in the usual sense of the word.If not specified,NOLOGIN is the default, except when\fBCREATE ROLE\fR is invoked through its alternate spelling\fBCREATE USER\fR..TP\fBCONNECTION LIMIT \fIconnlimit\fB\fRIf role can log in, this specifies how many concurrent connectionsthe role can make. -1 (the default) means no limit..TP\fBPASSWORD \fIpassword\fB\fRSets the role's password. (A password is only of use forroles having the LOGIN attribute, but youcan nonetheless define one for roles without it.) If you donot plan to use password authentication you can omit thisoption. If no password is specified, the password will be setto null and password authentication will always fail for thatuser. A null password can optionally be written explicitly asPASSWORD NULL..TP\fBENCRYPTED\fR.TP\fBUNENCRYPTED\fRThese key words control whether the password is storedencrypted in the system catalogs. (If neither is specified,the default behavior is determined by the configurationparameter password_encryption.) If thepresented password string is already in MD5-encrypted format,then it is stored encrypted as-is, regardless of whetherENCRYPTED or UNENCRYPTED is specified(since the system cannot decrypt the specified encryptedpassword string). This allows reloading of encryptedpasswords during dump/restore.Note that older clients may lack support for the MD5authentication mechanism that is needed to work with passwordsthat are stored encrypted..TP\fBVALID UNTIL '\fItimestamp\fB'\fRThe VALID UNTIL clause sets a date andtime after which the role's password is no longer valid. Ifthis clause is omitted the password will be valid for all time..TP\fBIN ROLE \fIrolename\fB\fRThe IN ROLE clause lists one or more existingroles to which the new role will be immediately added as a newmember. (Note that there is no option to add the new role as anadministrator; use a separate \fBGRANT\fR command to do that.).TP\fBIN GROUP \fIrolename\fB\fRIN GROUP is an obsolete spelling ofIN ROLE..TP\fBROLE \fIrolename\fB\fRThe ROLE clause lists one or more existingroles which are automatically added as members of the new role.(This in effect makes the new role a ``group''.).TP\fBADMIN \fIrolename\fB\fRThe ADMIN clause is like ROLE,but the named roles are added to the new role WITH ADMINOPTION, giving them the right to grant membership in this roleto others..TP\fBUSER \fIrolename\fB\fRThe USER clause is an obsolete spelling ofthe ROLE clause..TP\fBSYSID \fIuid\fB\fRThe SYSID clause is ignored, but is acceptedfor backwards compatibility..SH "NOTES".PPUse ALTER ROLE [\fBalter_role\fR(7)] tochange the attributes of a role, and DROP ROLE [\fBdrop_role\fR(7)] to remove a role. All the attributesspecified by \fBCREATE ROLE\fR can be modified by later\fBALTER ROLE\fR commands..PPThe preferred way to add and remove members of roles that are beingused as groups is to useGRANT [\fBgrant\fR(7)] andREVOKE [\fBrevoke\fR(7)]..PPThe VALID UNTIL clause defines an expiration time for apassword only, not for the role \fIper se\fR. Inparticular, the expiration time is not enforced when logging in usinga non-password-based authentication method..PPThe INHERIT attribute governs inheritance of grantableprivileges (that is, access privileges for database objects and rolememberships). It does not apply to the special role attributes set by\fBCREATE ROLE\fR and \fBALTER ROLE\fR. For example, beinga member of a role with CREATEDB privilege does not immediatelygrant the ability to create databases, even if INHERIT is set;it would be necessary to become that role viaSET ROLE [\fBset_role\fR(7)] beforecreating a database..PPThe INHERIT attribute is the default for reasons of backwardscompatibility: in prior releases of PostgreSQL,users always had access to all privileges of groups they were members of.However, NOINHERIT provides a closer match to the semanticsspecified in the SQL standard..PPBe careful with the CREATEROLE privilege. There is no concept ofinheritance for the privileges of a CREATEROLE-role. Thatmeans that even if a role does not have a certain privilege but is allowedto create other roles, it can easily create another role with differentprivileges than its own (except for creating roles with superuserprivileges). For example, if the role ``user'' has theCREATEROLE privilege but not the CREATEDB privilege,nonetheless it can create a new role with the CREATEDBprivilege. Therefore, regard roles that have the CREATEROLEprivilege as almost-superuser-roles..PPPostgreSQL includes a program createuser [\fBcreateuser\fR(1)] that hasthe same functionality as \fBCREATE ROLE\fR (in fact,it calls this command) but can be run from the command shell..PPThe CONNECTION LIMIT option is only enforced approximately;if two new sessions start at about the same time when just oneconnection ``slot'' remains for the role, it is possible thatboth will fail. Also, the limit is never enforced for superusers..PPCaution must be exercised when specifying an unencrypted passwordwith this command. The password will be transmitted to the serverin cleartext, and it might also be logged in the client's commandhistory or the server log. The command createuser [\fBcreateuser\fR(1)], however, transmitsthe password encrypted. Also, psql [\fBpsql\fR(1)] contains a command\fB\\password\fR that can be used to safely change thepassword later..SH "EXAMPLES".PPCreate a role that can log in, but don't give it a password:.sp.nfCREATE ROLE jonathan LOGIN;.sp.fi.PPCreate a role with a password:.sp.nfCREATE USER davide WITH PASSWORD 'jw8s0F4';.sp.fi(\fBCREATE USER\fR is the same as \fBCREATE ROLE\fR exceptthat it implies LOGIN.).PPCreate a role with a password that is valid until the end of 2004.After one second has ticked in 2005, the password is no longervalid..sp.nfCREATE ROLE miriam WITH LOGIN PASSWORD 'jw8s0F4' VALID UNTIL '2005-01-01';.sp.fi.PPCreate a role that can create databases and manage roles:.sp.nfCREATE ROLE admin WITH CREATEDB CREATEROLE;.sp.fi.SH "COMPATIBILITY".PPThe \fBCREATE ROLE\fR statement is in the SQL standard,but the standard only requires the syntax.sp.nfCREATE ROLE \fIname\fR [ WITH ADMIN \fIrolename\fR ].sp.fiMultiple initial administrators, and all the other options of\fBCREATE ROLE\fR, arePostgreSQL extensions..PPThe SQL standard defines the concepts of users and roles, but itregards them as distinct concepts and leaves all commands definingusers to be specified by each database implementation. InPostgreSQL we have chosen to unifyusers and roles into a single kind of entity. Roles thereforehave many more optional attributes than they do in the standard..PPThe behavior specified by the SQL standard is most closely approximatedby giving users the NOINHERIT attribute, while roles aregiven the INHERIT attribute..SH "SEE ALSO"SET ROLE [\fBset_role\fR(7)], ALTER ROLE [\fBalter_role\fR(l)], DROP ROLE [\fBdrop_role\fR(l)], GRANT [\fBgrant\fR(l)], REVOKE [\fBrevoke\fR(l)], \fBcreateuser\fR(1)
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?