After you finish the PostgreSQL installation, it will create a database named "postgres" and a database user "postgres" automatically, and it also create a Linux system user named "postgres"。
We will use the user "postgres" to generate the other user and new database.
Create Database and user account using command line
Create a new Linux system user named "reachnett".
sudo adduser reachnett
Switch to user "postgres"
sudo su - postgres
login PostgreSQL console using psql command.
psql
這時(shí)相當(dāng)于系統(tǒng)用戶postgres以同名數(shù)據(jù)庫(kù)用戶的身份,登錄數(shù)據(jù)庫(kù),這是不用輸入密碼的。如果一切正常,系統(tǒng)提示符會(huì)變?yōu)?postgres=#",表示這時(shí)已經(jīng)進(jìn)入了數(shù)據(jù)庫(kù)控制臺(tái)。以下的命令都在控制臺(tái)內(nèi)完成。
創(chuàng)建數(shù)據(jù)庫(kù)用戶reachnett(剛才創(chuàng)建的是Linux系統(tǒng)用戶),并設(shè)置密碼。
CREATE USER reachnett WITH PASSWORD 'password';
創(chuàng)建用戶數(shù)據(jù)庫(kù),這里為webtoprint,并指定所有者為reachnett。
CREATE DATABASE webtoprint OWNER reachnett;
將webtoprint數(shù)據(jù)庫(kù)的所有權(quán)限都賦予reachnett,否則reachnett只能登錄控制臺(tái),沒(méi)有任何數(shù)據(jù)庫(kù)操作權(quán)限。
GRANT ALL PRIVILEGES ON DATABASE webtoprint to reachnett;
最后,使用\q命令退出控制臺(tái)(也可以直接按ctrl+D)。
\q
Use pgAdmin3 to connect to webtoprint database
pgAdmin3 Screenshot