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
這時相當于系統用戶postgres以同名數據庫用戶的身份,登錄數據庫,這是不用輸入密碼的。如果一切正常,系統提示符會變為"postgres=#",表示這時已經進入了數據庫控制臺。以下的命令都在控制臺內完成。
創建數據庫用戶reachnett(剛才創建的是Linux系統用戶),并設置密碼。
CREATE USER reachnett WITH PASSWORD 'password';
創建用戶數據庫,這里為webtoprint,并指定所有者為reachnett。
CREATE DATABASE webtoprint OWNER reachnett;
將webtoprint數據庫的所有權限都賦予reachnett,否則reachnett只能登錄控制臺,沒有任何數據庫操作權限。
GRANT ALL PRIVILEGES ON DATABASE webtoprint to reachnett;
最后,使用\q命令退出控制臺(也可以直接按ctrl+D)。
\q
Use pgAdmin3 to connect to webtoprint database
pgAdmin3 Screenshot