PostgreSQL建立資料庫


在PostgreSQL中,可以使用CREATE DATABASE命令建立資料庫。

語法:

CREATE DATABASE database_name;

這裡,database_name是指定要建立的資料庫的名稱。

PostgreSQL使用UI建立資料庫

在您的系統中安裝PostgreSQL後,開啟開始選單,然後單擊pgAdmin。會得到一個這樣的頁面:

開啟pgAdmin,第一次開啟可能需要你輸入密碼,結果如下 -

右鍵單擊PostgreSQL 9.6並將PostgreSQL連線到本地主機伺服器。

右鍵單擊資料庫(Databases),轉到新資料庫,將出現一個彈出框,如下圖所示 -

然後鍵入您要的資料庫名稱,這裡建立的資料庫名稱是:yiibai_db,如下圖所示 -

點選儲存(Save)就可以了。
建立新的資料庫(yiibai_db)如下圖所示 -

PostgreSQL使用查詢工具建立資料庫

開啟SQL Shell(psql),執行以下建立語句 -

create database testdb;

執行結果如下 -

檢視資料庫 -

postgres=# \l
                                                        資料庫列表
   名稱    |  擁有者  | 字元編碼 |            校對規則            |             Ctype              |       存取許可權
-----------+----------+----------+--------------------------------+--------------------------------+-----------------------
 postgres  | postgres | UTF8     | Chinese (Simplified)_China.936 | Chinese (Simplified)_China.936 |
 template0 | postgres | UTF8     | Chinese (Simplified)_China.936 | Chinese (Simplified)_China.936 | =c/postgres          +
           |          |          |                                |                                | postgres=CTc/postgres
 template1 | postgres | UTF8     | Chinese (Simplified)_China.936 | Chinese (Simplified)_China.936 | =c/postgres          +
           |          |          |                                |                                | postgres=CTc/postgres
 testdb    | postgres | UTF8     | Chinese (Simplified)_China.936 | Chinese (Simplified)_China.936 |
 yiibai_db | postgres | UTF8     | Chinese (Simplified)_China.936 | Chinese (Simplified)_China.936 |
(5 行記錄)


postgres=#

或者在 pgAdmin 的左側中檢視,結果如下 -