PostgreSQL 預設情況下在所有 Ubuntu 版本中都可用。但是,Ubuntu 會“快照”特定版本的 PostgreSQL,該版本將在該 Ubuntu 版本的整個生命週期內得到支援。PostgreSQL 專案維護著一個包含所有支援的 PostgreSQL 版本的 Apt 倉庫。
Ubuntu 預設包含 PostgreSQL。要在 Ubuntu 上安裝 PostgreSQL,請使用 apt(或其他 apt 驅動的)命令
apt install postgresql
如果您的 Ubuntu 版本中包含的版本不是您想要的,您可以使用 PostgreSQL Apt 倉庫。該倉庫將與您正常的系統和補丁管理整合,並在 PostgreSQL 的所有支援的 生命週期 內提供所有支援的 PostgreSQL 版本的自動更新。
PostgreSQL Apt 倉庫支援以下 Ubuntu 的當前版本
支援以下架構
自動化倉庫配置
sudo apt install -y postgresql-common sudo /usr/share/postgresql-common/pgdg/apt.postgresql.org.sh
要手動配置 Apt 倉庫,請遵循以下步驟
# Import the repository signing key: sudo apt install curl ca-certificates sudo install -d /usr/share/postgresql-common/pgdg sudo curl -o /usr/share/postgresql-common/pgdg/apt.postgresql.org.asc --fail https://postgres.tw/media/keys/ACCC4CF8.asc # Create the repository configuration file: . /etc/os-release sudo sh -c "echo 'deb [signed-by=/usr/share/postgresql-common/pgdg/apt.postgresql.org.asc] https://apt.postgresql.org/pub/repos/apt $VERSION_CODENAME-pgdg main' > /etc/apt/sources.list.d/pgdg.list" # Update the package lists: sudo apt update
sudo apt install postgresql-18
有關 apt 倉庫的更多資訊,包括常見問題的解答,請參閱 PostgreSQL Apt 倉庫 wiki 頁面。
該倉庫包含許多不同的軟體包,包括第三方外掛。最常用和最重要的軟體包是 (根據需要替換版本號)
| postgresql-client-18 | 客戶端庫和客戶端二進位制檔案 |
|---|---|
| postgresql-18 | 核心資料庫伺服器 |
| postgresql-doc-18 | 文件 |
| libpq-dev | 用於 C 語言前端開發的庫和標頭檔案 |
| postgresql-server-dev-18 | 用於 C 語言後端開發的庫和標頭檔案 |