PostgreSQL 8.2.3 婺桺桺懼
劯锔媆锔媆誕嬉誕

CREATE ROLE

劉䓄

CREATE ROLE -- 垔幬婔婻桄昄扞康蓐謾

臺濘

CREATE ROLE name [ [ WITH ] option [ ... ] ]

認麯䔇 option 埇傖滇
    
      SUPERUSER | NOSUPERUSER
    | CREATEDB | NOCREATEDB
    | CREATEROLE | NOCREATEROLE
    | CREATEUSER | NOCREATEUSER
    | INHERIT | NOINHERIT
    | LOGIN | NOLOGIN
    | CONNECTION LIMIT connlimit
    | [ ENCRYPTED | UNENCRYPTED ] PASSWORD 'password'
    | VALID UNTIL 'timestamp' 
    | IN ROLE rolename [, ...]
    | IN GROUP rolename [, ...]
    | ROLE rolename [, ...]
    | ADMIN rolename [, ...]
    | USER rolename [, ...]
    | SYSID uid 

柟誄

CREATE ROLE 劏婔婻昄扞康镖䆴時媹婔婻桄蓐謾㔗婔婻蓐謾滇婔婻埇傖拖橬昄扞康凹茇幽婫拖橬昄扞康溄鍊䔇亻嘘蓐謾埇傖螴婺滇婔婻"䫘潙"㔕婔婻"䂇"㔕潡蔙滇婴蔙噚橬㔗臙埗蔄䆹18䆹20诙冖橬噿䞇䊖䫘潙启溄鍊䔇媇敇㔗襕嘪䫘認溇变傴嘹媙釂拖橬 CREATEROLE 溄鍊潡蔙滇昄扞康轙亓䫘潙㔗

臙濘懟蓐謾滇婘昄扞康镖䆴䔇评䘘麯垔幬䔇啹溴凹昄扞康镖䆴麯䔇欔橬昄扞康鄘橬昽㔗

埗昄

name

桄蓐謾䔇劉䓄

SUPERUSER
NOSUPERUSER

認底床埖喿垔婔婻桄蓐謾滇劥婺"轙亓䫘潙"認䓉䫘潙埇傖轙轪昄扞康婺䔇欔橬螪閞溄鍊㔗轙亓䫘潙䪽攕滇麂婩剌鍷䔇鍴麂䩘溼驔襕劥彍婉庫臖嘪䫘㔗套悩澇橬弄滯嘹躻噌媙釂滇婔婻轙亓䫘潙欉脘录傺婔婻桄䔇轙亓䫘潙㔗套悩澇橬毺垔NOSUPERUSER 儖滇䚺䩕㔗

CREATEDB
NOCREATEDB

認底床埖垔幬婔婻蓐謾滇劥脘录傺昄扞康㔗套悩弄滯庖 CREATEDB 闼幽溼婘录傺䔇蓐謾埇傖录傺桄昄扞康㔗弄滯 NOCREATEDB 儖婉嚔蕋婯桄蓐謾录傺昄扞康䔇脘媕㔗套悩澇橬弄滯闼幽䚺䩕滇 NOCREATEDB

CREATEROLE
NOCREATEROLE

認底床埖喿垔婔婻蓐謾滇劥埇傖录傺桄蓐謾(幘儌滇欓臯 CREATE ROLE)㔗婔婻拖橬 CREATEROLE 溄鍊䔇蓐謾幘埇傖媞櫹启役鍴噽垄蓐謾㔗套悩澇橬弄滯䚺䩕滇 NOCREATEROLE

CREATEUSER
NOCREATEUSER

認底床埖噾䂟誺施庖嘖滇傉䇽毖埖拚濘婺 SUPERUSERNOSUPERUSER 㔗臙濘懟垄傸幽京庯 CREATEROLE 庺傸冽埇脘蘂滷婄認幽螴婺㔗

INHERIT
NOINHERIT

認底床埖喿垔婔婻蓐謾滇劥"䂓欪"垄欔婘䂇䔇蓐謾䔇溄鍊㔗婔婻婥橬 INHERIT 匂攓䔇蓐謾埇傖躻媘嘪䫘噾䂟蕋婯垄䕘毖潡閘毖欔婘䂇䔇傂嘘溄鍊㔗澇橬 INHERIT 噽垄蓐謾䔇潊叻噿係埻蕋婯臖蓐謾 SET ROLE 潊噽垄蓐謾䔇脘媕噽垄蓐謾䔇溄鍊埻滇婘認幽啔庖幋劯欉脘诙冖㔗套悩澇橬弄滯䚺䩕滇 INHERIT

LOGIN
NOLOGIN

認底床埖喿垔婔婻蓐謾滇劥埇傖䍂嘘幘儌滇臘臖蓐謾婘垵潙䆇誂毖䔇施唍滇劥埇傖赆䂍庽彺哋寡嚔臺䔇螴臕劉庖㔗婔婻拖橬 LOGIN 匂攓䔇蓐謾埇傖螴婺滇婔婻䫘潙㔗澇橬認婻匂攓䔇蓐謾埇傖䫘庯䞇䊖昄扞康溄鍊嘖滇幽婉滇广婩楗媕䔇䫘潙㔗套悩澇橬弄滯鍴麂滇脄䫘 CREATE ROLE 䔇彆劉 CREATE USER劥彍䚺䩕儖滇 NOLOGIN

CONNECTION LIMIT connlimit

套悩蓐謾埇傖䍂嘘認婻埗昄弄滯臖蓐謾埇傖嘪䫘䔇幽埏誂毖昄麟㔗-1(䚺䩕)懟叿五澇橬鍊彽㔗

PASSWORD password

螆䘞蓐謾䔇埼傴㔗埼傴埻凹闼底拖橬 LOGIN 匂攓䔇蓐謾橬懟幬婉誺嘹嘷䇽埇傖䂍澇橬認婻匂攓䔇䫘潙垔幬埼傴㔗套悩嘹婉庖崺嘪䫘埼傴螴臕嘹埇傖媘䘖認婻锬釹㔗套悩澇橬毺垔埼傴埼傴儖赆螆婺䷺幽婫臖䫘潙䔇凖乕螴臕儖攂滇崌蘖㔗幘埇傖滯䇞䔇䫘 PASSWORD NULL 毺垔埼傴婺䷺㔗

ENCRYPTED
UNENCRYPTED

認底噿髞庖毓彽庻嗘婘係䂘臘麯麵䔇埼傴滇劥媹凖㔗套悩澇橬毺垔闼幽䚺䩕䔇臯婺䫌陉䘞埗昄 password_encryption 毓彽㔗啹婺係䂘方濘凹毺垔䔇埼傴庖严婾誕臯蓼凖欔傖套悩䕞嬉䔇埼傴庖严婾噾䂟滇䫘 MD5 媹凖䔇湚嚟闼幽闼儌嚔䂓䂺䙓溴庻櫆蔯婉䞇滇劥弄滯庖 ENCRYPTEDUNENCRYPTED 㔗認湙儌噕螩婘蘸嗘/啂崉䔇施唍麉桄媹蘘媹凖䔇埼傴㔗

臙濘懟蔕䔇垵潙䆇埇脘䚺幟凹 MD5 螴臕橺彽䔇櫇毕傖凖桺嘵嚟庻嗘䔇埼傴驔襕認婻橺彽準誊嘩㔗

VALID UNTIL 'timestamp'

VALID UNTIL 床埖螆䘞蓐謾䔇埼傴崌昽䔇施閘潿㔗套悩媘䘖庖認婻床埖闼幽埼傴儖愩誩橬昽㔗

IN ROLE rolename

IN ROLE 床埖彖庺婔婻潡崔婻䯄橬䔇蓐謾桄蓐謾儖䆋剿媹噖認底蓐謾潊婺垄傸䔇潊叻㔗臙濘懟澇橬傂嘘锬釹埇傖檪桄蓐謾時媹婺䞇䊖叻媙釂嘪䫘䋸䆋䔇 GRANT 变傴準啔認傽庋愙㔗

IN GROUP rolename

IN GROUPIN ROLE 䔇誺施䔇拚濘㔗

ROLE rolename

ROLE 床埖彖庺婔婻潡崔婻䯄橬䔇蓐謾垄傸儖躻媘時媹婺認婻桄蓐謾䔇潊叻㔗認婻媘嘩垂鍙婪儌滇檪桄蓐謾啔潊婔婻"䂇"㔗

ADMIN rolename

ADMIN 床埖䌂嚚 ROLE 埻滇䂍庺䔇蓐謾赆嵂媹彄桄蓐謾 WITH ADMIN OPTION 䂍傡傸傖檪認婻蓐謾䔇潊叻溄鍊蕋婯噽垄蓐謾䔇溄媕㔗

USER rolename

USER 床埖滇 ROLE 床埖䔇誺施拚濘㔗

SYSID uid

SYSID 床埖儖赆媘䘖嘖滇傉䇽毖埖幋婂襕婺庖劏婋噚垹㔗

濘懟

嘪䫘 ALTER ROLE 櫹埻婔婻蓐謾䔇匂攓嘪䫘 DROP ROLE 役鍴婔婻蓐謾㔗欔橬婘 CREATE ROLE 麯弄滯䔇蓐謾鄘埇傖婘锟劯䔇 ALTER ROLE 变傴麯媞櫹㔗

䂍婔婻嘷嘩䂇準嘪䫘䔇蓐謾時媹潡役鍴潊叻䔇懫膄喘䔇桹濘滇嘪䫘 GRANTREVOKE

The VALID UNTIL 床埖埻滇婺埼傴垔幬婔婻崌昽施鍊蔯婉滇蓐謾躻躆䔇崌昽施鍊㔗䬹彆襕濘懟䔇滇嘷傖麂埼傴婺嘺䇔䔇螴臕桹嚟䍂嘘䔇施唍認婻崌昽施閘儖崌寂懟幬㔗

INHERIT 匂攓䞇䊖闼底埇蕋庽䔇溄鍊䔇䂓欪噿係幘儌滇昄扞康凹茇䔇螪閞溄鍊启蓐謾潊叻䔇噿係㔗垄幽婉锗䫘庯 CREATE ROLEALTER ROLE 螆䘞䔇䬹枪蓐謾匂攓㔗懫套啔婺婔婻婥橬 CREATEDB 溄鍊䔇蓐謾潊叻幽婉䕘毖拖橬录傺昄扞康䔇脘媕剿嘪螆䘞庖 INHERIT 幘套溴臖蓐謾誻滇驔襕锔誺 SET ROLE 潊婺臖蓐謾䇽劯欉脘录傺昄扞康㔗

INHERIT 匂攓滇䚺䩕䔇寘啹滇婺庖劏婋噚垹婘傖嬉䔇 PostgreSQL 䬽橸麯䫘潙攂滇拖橬傡傸欔婘䂇䔇欔橬溄鍊㔗婉誺NOINHERIT 柊冕庖婯 SQL 湺庖欔垔幬䔇橔毖誏䔇臺懟㔗

襕濘懟 CREATEROLE 溄鍊啹婺凹庯 CREATEROLE 溄鍊婉庻婘䂓欪䔇楗媕㔗拖橬認婻溄鍊䔇蓐謾埇傖冽垹滷䔇录傺婔婻婯躻躆溄鍊婉劯䔇麂轙亓䫘潙蓐謾㔗冋套套悩"user"蓐謾拖橬 CREATEROLE 溄鍊蔯方 CREATEDB 溄鍊闼幽傡埇傖录傺婥橬 CREATEDB 溄鍊䔇桄蓐謾㔗啹溴噙橬 CREATEROLE 溄鍊䔇蓐謾庹幯䕩嘷庯婔婻轙亓䫘潙㔗

PostgreSQL 寙拸婔婻启 CREATE ROLE 橬婔湙媘脘䔇 createuser 䘋废(垂鍙婪儌滇脄䫘認婻变傴)埇傖傯变傴臯 shell 婪誊臯㔗

CONNECTION LIMIT 锬釹埻滇誏嚚婄嚺彽套悩婴婻桄䔇嚔臺庹幯劯施劇媘蔯埻橬臖蓐謾埻嬷婋婔婻"誂毖擘"闼幽冽埇脘婴婻誂毖鄘嚔崌蘖㔗劯湙認婻鍊彽傯準婉嚔凹轙亓䫘潙嚺彽㔗

婘認婻毺傴婺毺垔橻媹凖䔇埼傴施媙釂償媄㔗埼傴儖赆傖滯桺桹嚟嚹锐䂍橉媇単劯施誻埇脘婘垵潙䆇䔇变傴寖埾潡橉媇䆇斖媖婺赆螄嘘㔗蔯 createuser 嚔儖变傴媹凖劯嚹锐䂍橉媇単㔗劯湙psql 寙劆婔婻 \password 埇傖䫘準垬噘䔇媞櫹埼傴㔗

冋床

录傺婔婻埇傖䍂嘘䔇蓐謾嘖滇婉䂍傡螆䘞埼傴

CREATE ROLE jonathan LOGIN;

录傺婔婻婥埼傴䔇蓐謾

CREATE USER davide WITH PASSWORD 'jw8s0F4';

(CREATE USERCREATE ROLE 婔湙埻婉誺垄锊劆 LOGIN)

录傺婔婻婥埼傴䔇蓐謾埼傴橬昽橘彄 2004 幘庘㔗婘 2005 幘虏庖婔䓐幋劯埼傴儌婉喉橬昽㔗

CREATE ROLE miriam WITH LOGIN PASSWORD 'jw8s0F4' VALID UNTIL '2005-01-01';

录傺婔婻埇傖录傺昄扞康启䞇䊖蓐謾䔇蓐謾

CREATE ROLE admin WITH CREATEDB CREATEROLE;

噚垹攓

CREATE ROLE 臺埖婘 SQL 湺庖麯庻婘嘖滇湺庖埻襕挗婋麵䔇臺濘

CREATE ROLE name [ WITH ADMIN rolename ]

崔彺哋寡䞇䊖叻傖埪欔橬噽垄 CREATE ROLE 䔇锬釹鄘滇 PostgreSQL 欷匘㔗

SQL 湺庖垔幬庖䫘潙启蓐謾䔇楗媕嘖滇垄螴婺認婴婻楗媕滇垯噘䋸䆋䔇楗媕幽婫襕挗垔幬䫘潙䔇欔橬变傴鄘鐽凹懟婻昄扞康垂䯄㔗婘 PostgreSQL 麯锬拷庖檪䫘潙启蓐謾䂘婔潊婔䌂凹茇㔗啹溴蓐謾懫湺庖麯䔇橬敘崔䔇匂攓㔗

SQL 湺庖麯弄滯䔇臯婺麂婩毖誏庯䂍庽䫘潙 NOINHERIT 匂攓蔯䂍庽蓐謾 INHERIT 匂攓㔗

埽蓕

SET ROLE, ALTER ROLE, DROP ROLE, GRANT, REVOKE, createuser

劯锔饡釕嬉誕
CREATE OPERATOR CLASS婪婔亓CREATE RULE