1. 程式人生 > 實用技巧 >PostgreSQL 選擇資料庫

PostgreSQL 選擇資料庫

資料庫的命令視窗

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

postgres=#

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

postgres=# \l
                             List of databases
   Name    |  Owner   | Encoding | Collate | Ctype |   Access privileges   
-----------+----------+----------+---------+-------+-----------------------
 postgres  | postgres | UTF8     | C       | C     | 
 runoobdb  | 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 runoobdb
You are now connected to database "runoobdb" as user "postgres".
runoobdb=# 

系統命令列視窗

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

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

pgAdmin 工具

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