Create PostgreSQL database and User Account

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
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容