--- title: PostgreSQL 學習筆記 tags: Note, DB, PostgreSQL --- # PostgreSQL 學習筆記 由於工作上要用的關係,開始學習Postgres。 ###### tags: `DB`, `PostgreSQL` :::spoiler **Learning Resource** - [PostgreSQL正體中文使用手冊](https://docs.postgresql.tw/v/11/) ::: ## 簡介 PostgreSQL 為開源的物件關聯式資料庫管理系統,大多都直接叫他為postgres(唸法:post-gress)。 Postgres採用主從式架構(client/server),會在進行下列操作時保持連線: - 伺服器的執行緒,負責管理資料庫的檔案、受理用戶端的連線要求、執行相對應的資料庫動作。這樣的資料庫伺服端程式稱之為「postgres」。 - 用戶端的程式用來發起資料庫操作的行為,其設計的形態很廣泛:可能是文字介面的工具、圖型介面的程式、將資料庫內容顯示成網頁的網際網路伺服器、甚或是專用的資料庫管理工具。有一些用戶端程式是由PostgreSQL官方所提供,大部份由第三方的其他使用者所開發。 操作方法: - `psql` 就是Postgres的互動式終端,可以輸入、編輯、執行SQL指令 - 既有的圖形化介面:pgAdmin, 支援ODBC或JDBC的軟體 - 自行撰寫程式 ## 基本指令 - 建立資料庫 ```bash createdb db_name ``` - 移除資料庫 ```bash dropdb db_name ``` - 透過終端操作資料庫 ```bash psql db_name ``` 進入終端後,畫面會顯示 ``` db_name=# ``` 就可以輸入下列指令 - 顯示postgres版本 ```bash SELECT version(); ``` - 取得postgres支援的SQL語法 ```bash \h ``` - 離開psql ```bash \q ``` - 顯示table資訊 ```bash \d <table-name> ``` ## 資料庫備份 匯出資料庫schema ``` pg_dump --schema-only databasename > filename.sql ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up