PostgreSQL 選擇資料庫

PostgreSQL 選擇資料庫

上一章節我們講了如何建立資料庫,接下來我們來討論如何去選擇我們建立的資料庫。

資料庫的命令視窗

PostgreSQL 命令視窗中,我們可以命令提示符後面輸入 SQL 語句:

postgres=#

使用 \l 用於檢視已經存在的資料庫:

postgres=# \l
                             List of databases
   Name    |  Owner   | Encoding | Collate | Ctype |   Access privileges   
-----------+----------+----------+---------+-------+-----------------------
 postgres  | postgres | UTF8     | C       | C     | 
 itread01db  | postgres | UTF8     | C       | C     | 
 template0 | postgres | UTF8     | C       | C     | =c/postgres          +
           |          |          |         |       | postgres=CTc/postgres
 template1 | postgres | UTF8     | C       | C     | =c/postgres          +
           |          |          |         |       | postgres=CTc/postgres
(4 rows)

接下來我們可以使用 \c + 資料庫名 來進入資料庫:

postgres=# \c itread01db
You are now connected to database "itread01db" as user "postgres".
itread01db=# 

系統命令列視窗

在系統的命令列檢視,我麼可以在連線資料庫後面新增資料庫名來選擇資料庫:

$ psql -h localhost -p 5432 -U postgress itread01db
Password for user postgress: ****
psql (11.3)
Type "help" for help.
You are now connected to database "itread01db" as user "postgres".
itread01db=# 

pgAdmin 工具

pgAdmin 工具更簡單了,直接點選資料庫選擇就好了,還可以檢視一些資料庫額外的資訊: