↑↓ 选择 ↵ 打开 ⌫ 改范围 完整检索页

pgsql.cc 提供对 postgresql.org 官网内容的中文翻译,由 Pigsty 团队维护。

Linux 下载(Ubuntu)

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

发行版自带

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

apt install postgresql

PostgreSQL Apt 仓库

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

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

  • stonking(26.10,非长期支持版)
  • resolute(26.04,长期支持版)
  • noble(24.04,长期支持版)
  • jammy(22.04,长期支持版)

支持以下架构:

  • 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;下面示例中请将 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 仓库维基页面。

软件包

该仓库包含许多不同的软件包,包括第三方扩展。最常见和最重要的软件包如下(请根据需要替换版本号):

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