Linux 下载(Ubuntu)

所有 Ubuntu 版本默认都提供 PostgreSQL。但是,Ubuntu 会“快照”一个特定版本的 PostgreSQL,并在该 Ubuntu 版本的整个生命周期内提供支持。 PostgreSQL 项目维护了一个 Apt 仓库,提供所有受支持的 PostgreSQL 版本。

发行版自带

Ubuntu 默认包含 PostgreSQL。要在 Ubuntu 上安装 PostgreSQL,请使用 apt(或其他 apt 驱动的)命令:

apt install postgresql

PostgreSQL Apt Repository

如果您的 Ubuntu 版本中包含的 PostgreSQL 版本不是您想要的,可以使用 PostgreSQL Apt Repository。该仓库将与您的常规系统和补丁管理集成,并在 PostgreSQL 的整个支持生命周期内为所有受支持的 PostgreSQL 版本提供自动更新。

PostgreSQL Apt 仓库支持以下 Ubuntu 当前版本:

  • resolute (26.04, LTS)
  • questing (25.10,非 LTS)
  • noble (24.04, LTS)
  • jammy (22.04, LTS)

支持以下架构:

  • amd64
  • arm64(仅限 LTS 版本)
  • ppc64el(仅限 LTS 版本)

自动仓库配置

sudo apt install -y postgresql-common
sudo /usr/share/postgresql-common/pgdg/apt.postgresql.org.sh

手工仓库配置

导入仓库签名公钥

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

创建 /etc/apt/sources.list.d/pgdg.sources。发行版名称格式为 codename-pgdg;下面示例中请将 resolute 替换为您实际使用的发行版代号。文件内容如下:

Types: deb deb-src
URIs: https://apt.postgresql.org/pub/repos/apt
Suites: resolute-pgdg
Architectures: amd64
Components: main
Signed-By: /usr/share/postgresql-common/pgdg/apt.postgresql.org.asc
安装 PostgreSQL:(将 "18" 替换为您想要的版本)
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 语言后端开发库和头文件

PostgreSQL Apt 仓库中国镜像

如果您位于中国大陆,可以优先使用 阿里云 PostgreSQL APT 镜像
您也可以使用 pig 命令行工具来添加 PGDG APT 仓库,它会自动根据所在区域选择合适的镜像。

curl https://repo.pigsty.cc/pig | bash
pig repo add pgdg