# PostgreSQL 管理工具
## 目錄
[TOC]
## 圖形介面
### 使用 pgAdmin
1. 開啟 pgAdmin 應用程式
2. 點選 Servers 下拉選單

3. Databases 代表 server 上的資料庫

4. 點選資料庫 -> Schemas -> Tables 可看到該資料庫的 table

5. table -> 右鍵 -> View/Edit Data -> All Rows 可看到該 table 所有資料

6. 漏斗圖示可加入條件過濾資料

7. 也可針對資料編輯、刪除、存檔

## 文字介面 (命令列)
### 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>