# PostgreSQL 管理工具 ## 目錄 [TOC] ## 圖形介面 ### 使用 pgAdmin 1. 開啟 pgAdmin 應用程式 2. 點選 Servers 下拉選單 ![](https://i.imgur.com/IWpdTgD.png) 3. Databases 代表 server 上的資料庫 ![](https://i.imgur.com/nVk9cgI.png) 4. 點選資料庫 -> Schemas -> Tables 可看到該資料庫的 table ![](https://i.imgur.com/HratNbm.png) 5. table -> 右鍵 -> View/Edit Data -> All Rows 可看到該 table 所有資料 ![](https://i.imgur.com/l5EUeyL.png) 6. 漏斗圖示可加入條件過濾資料 ![](https://i.imgur.com/8nZIBFx.png) 7. 也可針對資料編輯、刪除、存檔 ![](https://i.imgur.com/mHXbBH9.png) ## 文字介面 (命令列) ### SSH 登入 ```=shell ssh user@datacenter.ip.address ``` ### 切換 postgres 帳號 ```=shell sudo su - postgres ``` ### 開啟 psql 命令模式 ```=shell psql ``` ### 指令說明 連線至 database 後可使用 SQL 相關語法,e.g. <code>SELECT * FROM table;</code>,需加分號作為結尾 <code>\l</code> 列出所有 database <code>\c SpindleTest</code> 連線至 SpindleTest database <code>\d</code> 列出該 database 所有 table <code>\d tablename</code> 列出該 database 所有 table ## 修改設定 ### 設定允許連線 IP & 最大連線數量 1. 修改 <code>/etc/postgresql/13/main/postgresql.conf</code> 設定 找到以下內容,並修改 : ```gherkin= # - Connection Settings - #listen_addresses = 'localhost' listen_addresses = '*' ``` 最大連線數量 : ```gherkin= # - Connection Settings - max_connections = 100 ``` 2. 修改 <code>/etc/postgresql/13/main/pg_hba.conf</code> 設定 找到以下內容,並加入允許連線 IP : ```gherkin= # IPv4 local connections: host all all 127.0.0.1/32 md5 ``` 3. 修改完需重啟 postgresql 服務 <code>sudo systemctl restart postgresql</code>