所有 Ubuntu 版本默认都提供 PostgreSQL。但是,Ubuntu 会“快照”一个特定版本的 PostgreSQL,并在该 Ubuntu 版本的整个生命周期内提供支持。 PostgreSQL 项目维护了一个 Apt 仓库,提供所有受支持的 PostgreSQL 版本。
Ubuntu 默认包含 PostgreSQL。要在 Ubuntu 上安装 PostgreSQL,请使用 apt(或其他 apt 驱动的)命令:
apt install postgresql
如果您的 Ubuntu 版本中包含的 PostgreSQL 版本不是您想要的,可以使用 PostgreSQL Apt Repository。该仓库将与您的常规系统和补丁管理集成,并在 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://www.postgresql.org/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 Repository wiki 页面。
该仓库包含许多不同的软件包,包括第三方扩展。最常见和最重要的软件包如下(请根据需要替换版本号):
| postgresql-client-18 | 客户端库和客户端程序 |
|---|---|
| postgresql-18 | 核心数据库服务器 |
| postgresql-doc-18 | 文档 |
| libpq-dev | C 语言前端开发库和头文件 |
| postgresql-server-dev-18 | C 语言后端开发库和头文件 |