Linux 下载(Debian)

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

发行版自带

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

apt install postgresql

PostgreSQL Apt Repository

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

PostgreSQL Apt Repository 支持以下 Debian 版本:

  • trixie (13.x)
  • bookworm (12.x)
  • bullseye (11.x)
  • forky (testing)
  • sid (unstable)

支持以下架构:

  • amd64
  • arm64
  • ppc64el

自动仓库配置

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;下面示例中请将 trixie 替换为您实际使用的发行版代号。文件内容如下:

Types: deb deb-src
URIs: https://apt.postgresql.org/pub/repos/apt
Suites: trixie-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