安裝:
sudo apt-get install postgresql
修改數(shù)據(jù)庫(kù)的管理員用戶(hù)密碼:
PostgreSQL數(shù)據(jù)默認(rèn)會(huì)創(chuàng)建一個(gè)叫postgres的數(shù)據(jù)庫(kù)用戶(hù)作為數(shù)據(jù)庫(kù)的管理員
sudo -u postgres psql? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 打開(kāi)客戶(hù)端工具(psql)
ALTER USER postgres WITH PASSWORD '
password';
退出PostgreSQL psql客戶(hù)端:
\q
修改ubuntu操作系統(tǒng)的postgres用戶(hù)的密碼(密碼要與數(shù)據(jù)庫(kù)用戶(hù)postgres的密碼相同)
sudo passwd -d postgres? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? passwd -d 清空指定用戶(hù)密碼
sudo -u postgres passwd ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 設(shè)置PostgreSQL系統(tǒng)用戶(hù)的密碼
登錄postgre SQL數(shù)據(jù)庫(kù):
psql -U postgres -h 127.0.0.1
查看數(shù)據(jù)庫(kù)用戶(hù):
\du
查看所以數(shù)據(jù)庫(kù)
\l
SHELL創(chuàng)建[超級(jí)](刪除)用戶(hù)
createuser [--superuser](dropuser)
username
SHELL創(chuàng)建(刪除)數(shù)據(jù)庫(kù)
createdb(dropdb)
dbname
登陸權(quán)限:
CREATE ROLE?
name?LOGIN; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? CREATE USERname默認(rèn)具有登陸權(quán)限
超級(jí)用戶(hù),擁有所有權(quán)限:
CREATE ROLE?
name?SUPERUSER
創(chuàng)建數(shù)據(jù)庫(kù)權(quán)限:
CREATE ROLE?
name?CREATEDB
創(chuàng)建、更改、刪除角色權(quán)限:
CREATE ROLE?
name?CREATEROLE
啟動(dòng)復(fù)制的權(quán)限:
CREATE ROLE?
name?REPLICATION LOGIN
口令:
只有在客戶(hù)認(rèn)證方法要求與數(shù)據(jù)庫(kù)建立連接必須使用口令的時(shí)候,口令才比較重要。
password和md5認(rèn)證方法使用口令。
數(shù)據(jù)庫(kù)口令與操作系統(tǒng)口令是無(wú)關(guān)的。?
CREATE ROLE
namePASSWORD “password”
修改權(quán)限:
一個(gè)角色的屬性可以在創(chuàng)建后用ALTER ROLE修改
重啟服務(wù)器
/etc/init.d/postgresql restart
重新加載配置文件
/etc/init.d/postgresql reload
在shell命令行下,創(chuàng)建數(shù)據(jù)庫(kù)exampledb,并指定所有者為dbuser
sudo -u postgres createdb -O dbuser exampled
登入數(shù)據(jù)庫(kù)
psql -U dbuser -d exampledb-h 127.0.0.1 -p 5432