<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                # CREATE ROLE ## Name CREATE ROLE?--?定義一個新的數據庫角色 ## Synopsis ``` CREATE ROLE _name_ [ [ WITH ] _option_ [ ... ] ] where `_option_` can be: SUPERUSER | NOSUPERUSER | CREATEDB | NOCREATEDB | CREATEROLE | NOCREATEROLE | CREATEUSER | NOCREATEUSER | INHERIT | NOINHERIT | LOGIN | NOLOGIN | REPLICATION | NOREPLICATION | CONNECTION LIMIT _connlimit_ | [ ENCRYPTED | UNENCRYPTED ] PASSWORD '_password_' | VALID UNTIL '_timestamp_' | IN ROLE _role_name_ [, ...] | IN GROUP _role_name_ [, ...] | ROLE _role_name_ [, ...] | ADMIN _role_name_ [, ...] | USER _role_name_ [, ...] | SYSID _uid_ ``` ## Description `CREATE ROLE` 命令用于為PostgreSQL數據庫集群增加新的角色。 角色是擁有數據庫對象和數據庫權限的實體。一個角色可以依據其被使用的情況,被看做一個用戶"user"或者一個組 "group"。 參考[Chapter 20](#calibre_link-13)和[Chapter 19](#calibre_link-14)這兩個文檔,去獲取有關用戶和認證管理的相關信息。 你必須要有`CREATEROLE`權限,或者你是一個超級用戶,你才能使用 `CREATE ROLE`命令。 注意,角色是定義在數據庫集群級別的,所以在集群中的所有數據庫中都是有效的。 ## 參數 `_name_` 新角色的名稱。 `SUPERUSER``NOSUPERUSER` 這兩個條件決定一個新的角色是否為一個超級用戶("superuser"),超級用戶可以超越數據庫內的所有訪問限制。 超級用戶狀態是危險的,應該在真正需要的情況下才被使用。你自己必須是一個超級用戶,才能創建一個新的超級用戶。如果沒有指定 這個條件,缺省是 `NOSUPERUSER`。 `CREATEDB` `NOCREATEDB` 這兩個條件定義用戶創建數據庫的權限。如果被指定為`CREATEDB`,則該用戶被賦予創建數據庫的權限。 被指定為`NOCREATEDB` 將沒有創建數據庫的權限。如果沒有指定這個條件,缺省是`NOCREATEDB` 。 `CREATEROLE` `NOCREATEROLE` 這兩個條件決定一個角色是否被允許創建新角色(即,執行`CREATE ROLE`命令的權限)。 一個角色如果被賦予`CREATEROLE`權限,則同時也具有了修改或刪除其他角色的權限。如果沒有指定這個條件, 則缺省是 `NOCREATEROLE`。 `CREATEUSER` `NOCREATEUSER` 這兩個條件是過時的,不過現在仍被數據庫接受,他們和條件`SUPERUSER` `NOSUPERUSER`是等效的。 注意,他們和 `CREATEROLE` `NOCREATEROLE`并無關系。 `INHERIT` `NOINHERIT` These clauses determine whether a role "inherits" the privileges of roles it is a member of. A role with the `INHERIT` attribute can automatically use whatever database privileges have been granted to all roles it is directly or indirectly a member of. Without `INHERIT`, membership in another role only grants the ability to `SET ROLE` to that other role; the privileges of the other role are only available after having done so. If not specified, `INHERIT` is the default. `LOGIN` `NOLOGIN` These clauses determine whether a role is allowed to log in; that is, whether the role can be given as the initial session authorization name during client connection. A role having the `LOGIN` attribute can be thought of as a user. Roles without this attribute are useful for managing database privileges, but are not users in the usual sense of the word. If not specified, `NOLOGIN` is the default, except when `CREATE ROLE` is invoked through its alternative spelling [CREATE USER](#calibre_link-15). 這兩個參數決定一個角色是否有登進數據庫的權限;一個擁有`LOGIN`屬性的角色(role),可以被視為一個用戶(user)。 `REPLICATION` `NOREPLICATION` These clauses determine whether a role is allowed to initiate streaming replication or put the system in and out of backup mode. A role having the `REPLICATION` attribute is a very highly privileged role, and should only be used on roles actually used for replication. If not specified, `NOREPLICATION` is the default. `CONNECTION LIMIT` `_connlimit_` If role can log in, this specifies how many concurrent connections the role can make. -1 (the default) means no limit. `PASSWORD` `_password_` Sets the role's password. (A password is only of use for roles having the `LOGIN` attribute, but you can nonetheless define one for roles without it.) If you do not plan to use password authentication you can omit this option. If no password is specified, the password will be set to null and password authentication will always fail for that user. A null password can optionally be written explicitly as `PASSWORD NULL`. `ENCRYPTED` `UNENCRYPTED` These key words control whether the password is stored encrypted in the system catalogs. (If neither is specified, the default behavior is determined by the configuration parameter [password_encryption](#calibre_link-16).) If the presented password string is already in MD5-encrypted format, then it is stored encrypted as-is, regardless of whether `ENCRYPTED` or `UNENCRYPTED` is specified (since the system cannot decrypt the specified encrypted password string). This allows reloading of encrypted passwords during dump/restore. Note that older clients might lack support for the MD5 authentication mechanism that is needed to work with passwords that are stored encrypted. `VALID UNTIL` '`_timestamp_`' The `VALID UNTIL` clause sets a date and time after which the role's password is no longer valid. If this clause is omitted the password will be valid for all time. `IN ROLE` `_role_name_` The `IN ROLE` clause lists one or more existing roles to which the new role will be immediately added as a new member. (Note that there is no option to add the new role as an administrator; use a separate `GRANT` command to do that.) `IN GROUP` `_role_name_` `IN GROUP` is an obsolete spelling of `IN ROLE`. `ROLE` `_role_name_` The `ROLE` clause lists one or more existing roles which are automatically added as members of the new role. (This in effect makes the new role a "group".) `ADMIN` `_role_name_` The `ADMIN` clause is like `ROLE`, but the named roles are added to the new role `WITH ADMIN OPTION`, giving them the right to grant membership in this role to others. `USER` `_role_name_` The `USER` clause is an obsolete spelling of the `ROLE` clause. `SYSID` `_uid_` The `SYSID` clause is ignored, but is accepted for backwards compatibility. ## Notes Use [ALTER ROLE](#calibre_link-17) to change the attributes of a role, and [DROP ROLE](#calibre_link-18) to remove a role. All the attributes specified by `CREATE ROLE` can be modified by later `ALTER ROLE` commands. The preferred way to add and remove members of roles that are being used as groups is to use [GRANT](#calibre_link-19) and [REVOKE](#calibre_link-20). The `VALID UNTIL` clause defines an expiration time for a password only, not for the role _per se_. In particular, the expiration time is not enforced when logging in using a non-password-based authentication method. The `INHERIT` attribute governs inheritance of grantable privileges (that is, access privileges for database objects and role memberships). It does not apply to the special role attributes set by `CREATE ROLE` and `ALTER ROLE`. For example, being a member of a role with `CREATEDB` privilege does not immediately grant the ability to create databases, even if `INHERIT` is set; it would be necessary to become that role via [SET ROLE](#calibre_link-21) before creating a database. The `INHERIT` attribute is the default for reasons of backwards compatibility: 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 semantics specified in the SQL standard. Be careful with the `CREATEROLE` privilege. There is no concept of inheritance for the privileges of a `CREATEROLE`-role. That means that even if a role does not have a certain privilege but is allowed to create other roles, it can easily create another role with different privileges than its own (except for creating roles with superuser privileges). For example, if the role "user" has the `CREATEROLE` privilege but not the `CREATEDB` privilege, nonetheless it can create a new role with the `CREATEDB` privilege. Therefore, regard roles that have the `CREATEROLE` privilege as almost-superuser-roles. PostgreSQL includes a program [createuser](#calibre_link-22) that has the same functionality as `CREATE ROLE` (in fact, it calls this command) but can be run from the command shell. The `CONNECTION LIMIT` option is only enforced approximately; if two new sessions start at about the same time when just one connection "slot" remains for the role, it is possible that both will fail. Also, the limit is never enforced for superusers. 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. The command [createuser](#calibre_link-22), however, transmits the password encrypted. Also, [psql](#calibre_link-23) contains a command `\password` that can be used to safely change the password later. ## Examples Create a role that can log in, but don't give it a password: ``` CREATE ROLE jonathan LOGIN; ``` Create a role with a password: ``` CREATE USER davide WITH PASSWORD 'jw8s0F4'; ``` (`CREATE USER` is the same as `CREATE ROLE` except that it implies `LOGIN`.) Create a role with a password that is valid until the end of 2004. After one second has ticked in 2005, the password is no longer valid. ``` CREATE ROLE miriam WITH LOGIN PASSWORD 'jw8s0F4' VALID UNTIL '2005-01-01'; ``` Create a role that can create databases and manage roles: ``` CREATE ROLE admin WITH CREATEDB CREATEROLE; ``` ## Compatibility The `CREATE ROLE` statement is in the SQL standard, but the standard only requires the syntax ``` CREATE ROLE _name_ [ WITH ADMIN _role_name_ ] ``` Multiple initial administrators, and all the other options of `CREATE ROLE`, are PostgreSQL extensions. The SQL standard defines the concepts of users and roles, but it regards them as distinct concepts and leaves all commands defining users to be specified by each database implementation. In PostgreSQL we have chosen to unify users and roles into a single kind of entity. Roles therefore have many more optional attributes than they do in the standard. The behavior specified by the SQL standard is most closely approximated by giving users the `NOINHERIT` attribute, while roles are given the `INHERIT` attribute. ## See Also [SET ROLE](#calibre_link-21), [ALTER ROLE](#calibre_link-17), [DROP ROLE](#calibre_link-18), [GRANT](#calibre_link-19), [REVOKE](#calibre_link-20), [createuser](#calibre_link-22)
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看