薇尔薇

Back

https://apt-archive.postgresql.org ↗

设置PGP KEY#

sudo mkdir -p /usr/share/keyrings

curl -fsSL https://www.postgresql.org/media/keys/ACCC4CF8.asc \
| sudo gpg --dearmor -o /usr/share/keyrings/postgresql-archive.gpg
sh

添加PGSQL源(旧版本)#

UBUNTU_CODENAME="$(lsb_release -cs)"

sudo tee /etc/apt/sources.list.d/pgdg-archive.sources > /dev/null <<EOF
Types: deb
URIs: https://apt-archive.postgresql.org/pub/repos/apt
Suites: ${UBUNTU_CODENAME}-pgdg-archive
Components: main
Signed-By: /usr/share/keyrings/postgresql-archive.gpg
EOF

sudo apt update
sh

查找版本号#

apt-cache madison postgresql-15 | grep 15.6
apt-cache madison postgresql-client-15 | grep 15.6 
sh

输出示例

root@playground /e/a/sources.list.d# apt-cache madison postgresql-15 | grep 15.6
postgresql-15 | 15.6-1.pgdg130+1 | https://apt-archive.postgresql.org/pub/repos/apt trixie-pgdg-archive/main amd64 Packages

root@playground /e/a/sources.list.d# apt-cache madison postgresql-client-15 | grep 15.6
postgresql-client-15 | 15.6-1.pgdg130+1 | https://apt-archive.postgresql.org/pub/repos/apt trixie-pgdg-archive/main amd64 Packages
sh

安装#

sudo apt install -y \
  postgresql-15=15.6-1.pgdg22.04+1 \
  postgresql-client-15=15.6-1.pgdg22.04+1
sh

替换=后面的 15.6-1.pgdg22.04+1 为上一步输出的版本号

查询安装的版本#

dpkg -l | egrep 'postgresql-(15|client-15|contrib-15)|postgresql-(client-)?common' | awk '{print $2, $3}'
sh
psql --version
sh
Debian不使用Docker安装指定版本的PostgreSQL
https://vio.vin/blog/debian-bu-shi-yong-docker-an-zhuang-zhi-ding-ban-ben-de-postgresql
Author violet
Published at 2026年1月25日