CREATE USER 中文man頁(yè)面
NAME
CREATE USER - 創(chuàng)建一個(gè)新的數(shù)據(jù)庫(kù)用戶(hù)帳戶(hù)
SYNOPSIS
CREATE USER name [ [ WITH ] option [ ... ] ] where option can be: SYSID uid | [ ENCRYPTED | UNENCRYPTED ] PASSWORD 'password' | CREATEDB | NOCREATEDB | CREATEUSER | NOCREATEUSER | IN GROUP groupname [, ...] | VALID UNTIL 'abstime'
DESCRIPTION 描述
CREATE USER 向一個(gè) PostgreSQL 數(shù)據(jù)庫(kù)集群增加一個(gè)新用戶(hù)。 參考 Chapter 17 ``Database Users and Privileges'' 和 Chapter 19 ``Client Authentication'' 獲取關(guān)于管理用戶(hù)和認(rèn)證的信息。 要執(zhí)行這條命令,你必須是一個(gè)數(shù)據(jù)庫(kù)超級(jí)用戶(hù)。
PARAMETERS 參數(shù)
- name
用戶(hù)名- uid
- SYSID 子句可以用于選擇正在被創(chuàng)建的用戶(hù)的 PostgreSQL 用戶(hù)標(biāo)識(shí)。 通常這是不必要的,但是如果你想恢復(fù)一個(gè)孤兒對(duì)象的所有者,也許這個(gè)很有用。
如果沒(méi)有聲明這個(gè),缺省使用已分配的***用戶(hù)標(biāo)識(shí)加一(最小是 100)。 - password
設(shè)置用戶(hù)的口令,如果你不準(zhǔn)備使用口令認(rèn)證, 那么你可以省略這個(gè)選項(xiàng),但如果你想切換到一個(gè)口令認(rèn)證的服務(wù)器,那么該用戶(hù)將不能聯(lián)接。 此口令可以稍后再次設(shè)置或者修改,使用 ALTER USER [alter_user(7)]。- ENCRYPTED
- UNENCRYPTED
- 控制口令在數(shù)據(jù)庫(kù)中是否以加密形式存儲(chǔ)在系統(tǒng)表中。 (如果兩個(gè)都沒(méi)有設(shè)置,那么缺省的特性是由配置參數(shù) password_encryption 決定的。) 如果提供的字串已經(jīng)是 MD5 加密的格式,那么就照原樣存儲(chǔ), 不管聲明的是 ENCRYPTED 還是 UNENCRYPTED。 這樣就允許在轉(zhuǎn)儲(chǔ)/恢復(fù)的過(guò)程中重載加密后的口令。
請(qǐng)注意老的客戶(hù)端可能缺少 MD5 認(rèn)證機(jī)制,我們需要這個(gè)認(rèn)證機(jī)制處理存儲(chǔ)為密文的口令。 - CREATEDB
- NOCREATEDB
- 這個(gè)子句定義用戶(hù)的創(chuàng)建數(shù)據(jù)庫(kù)權(quán)限。 如果聲明了CREATEDB, 被定義的用戶(hù)將允許創(chuàng)建其自己的數(shù)據(jù)庫(kù)。 而使用NOCREATEDB將否決該用戶(hù)的創(chuàng)建數(shù)據(jù)庫(kù)的能力。 如果忽略本子句,缺省是NOCREATEDB。
- CREATEUSER
- NOCREATEUSER
該子句決定一個(gè)用戶(hù)是否能創(chuàng)建一個(gè)新的用戶(hù)。 這個(gè)選項(xiàng)同樣把此用戶(hù)變成數(shù)據(jù)庫(kù)超級(jí)用戶(hù),可以跨越所有訪問(wèn)限制。省略這個(gè)參數(shù)將置用戶(hù)的這個(gè)屬性為 NOCREATEUSER。- groupname
一個(gè)組名稱(chēng),把這個(gè)用戶(hù)設(shè)為該組成員。 你可以列出多個(gè)組名字。- abstime
- VALID UNTIL (有效期)子句設(shè)置一個(gè)絕對(duì)時(shí)間, 過(guò)了該時(shí)間后用戶(hù)的口令將不再有效。 如果省略這個(gè)子句,登陸將總是有效的。
NOTES 注意
使用 ALTER USER [alter_user(7)] 修改用戶(hù)的口令和權(quán)限,DROP USER [drop_user(7)] 刪除一個(gè)用戶(hù)。 使用 ALTER GROUP [alter_group(l)] 從組中增加或刪除用戶(hù)。
PostgreSQL 里有一個(gè)程序 createuser [createuser(1)] 與CREATE USER 有相同的功能(實(shí)際上,它調(diào)用這條命令), 但是可以在命令行上運(yùn)行。
EXAMPLES 例子
創(chuàng)建一個(gè)沒(méi)有口令的用戶(hù):
CREATE USER jonathan;
創(chuàng)建一個(gè)有口令的用戶(hù):
CREATE USER davide WITH PASSWORD 'jw8s0F4';
創(chuàng)建一個(gè)有口令的用戶(hù),其帳號(hào)在 2004 年底失效。 注意當(dāng) 2005 年走過(guò)一秒后,該帳號(hào)將不再有效:
CREATE USER miriam WITH PASSWORD 'jw8s0F4' VALID UNTIL '2005-01-01';
創(chuàng)建一個(gè)擁有創(chuàng)建數(shù)據(jù)庫(kù)權(quán)限的用戶(hù):
CREATE USER manuel WITH PASSWORD 'jw8s0F4' CREATEDB;
COMPATIBILITY 兼容性
CREATE USER 語(yǔ)句是 PostgreSQL 擴(kuò)展。 SQL 標(biāo)準(zhǔn)把用戶(hù)的定義交給具體實(shí)現(xiàn)處理。
SEE ALSO 參見(jiàn)
ALTER USER [alter_user(7)], DROP USER [drop_user(l)], createuser(1)
#p#
NAME
CREATE USER - define a new database user account
SYNOPSIS
CREATE USER name [ [ WITH ] option [ ... ] ] where option can be: SYSID uid | [ ENCRYPTED | UNENCRYPTED ] PASSWORD 'password' | CREATEDB | NOCREATEDB | CREATEUSER | NOCREATEUSER | IN GROUP groupname [, ...] | VALID UNTIL 'abstime'
DESCRIPTION
CREATE USER adds a new user to a PostgreSQL database cluster. Refer to the chapters called ``Database Users and Privileges'' and ``Client Authentication'' in the documentation for information about managing users and authentication. You must be a database superuser to use this command.
PARAMETERS
- name
- The name of the user.
- uid
- The SYSID clause can be used to choose the PostgreSQL user ID of the user that is being created. This is not normally not necessary, but may be useful if you need to recreate the owner of an orphaned object.
If this is not specified, the highest assigned user ID plus one (with a minimum of 100) will be used as default.
- password
- Sets the user's password. If you do not plan to use password authentication you can omit this option, but then the user won't be able to connect if you decide to switch to password authentication. The password can be set or changed later, using ALTER USER [alter_user(7)].
- 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.) 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 may lack support for the MD5 authentication mechanism that is needed to work with passwords that are stored encrypted.
- CREATEDB
- NOCREATEDB
- These clauses define a user's ability to create databases. If CREATEDB is specified, the user being defined will be allowed to create his own databases. Using NOCREATEDB will deny a user the ability to create databases. If this clause is omitted, NOCREATEDB is used by default.
- CREATEUSER
- NOCREATEUSER
- These clauses determine whether a user will be permitted to create new users himself. This option will also make the user a superuser who can override all access restrictions. Omitting this clause will set the user's value of this attribute to be NOCREATEUSER.
- groupname
- A name of a group into which to insert the user as a new member. Multiple group names may be listed.
- abstime
- The VALID UNTIL clause sets an absolute time after which the user's password is no longer valid. If this clause is omitted the login will be valid for all time.
NOTES
Use ALTER USER [alter_user(7)] to change the attributes of a user, and DROP USER [drop_user(7)] to remove a user. Use ALTER GROUP [alter_group(l)] to add the user to groups or remove the user from groups.
PostgreSQL includes a program createuser [createuser(1)] that has the same functionality as CREATE USER (in fact, it calls this command) but can be run from the command shell.
EXAMPLES
Create a user with no password:
CREATE USER jonathan;
Create a user with a password:
CREATE USER davide WITH PASSWORD 'jw8s0F4';
Create a user 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 USER miriam WITH PASSWORD 'jw8s0F4' VALID UNTIL '2005-01-01';
Create an account where the user can create databases:
CREATE USER manuel WITH PASSWORD 'jw8s0F4' CREATEDB;
COMPATIBILITY
The CREATE USER statement is a PostgreSQL extension. The SQL standard leaves the definition of users to the implementation.
SEE ALSO
ALTER USER [alter_user(7)], DROP USER [drop_user(l)], createuser(1)