设置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添加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查找版本号
apt-cache madison postgresql-15 | grep 15.6
apt-cache madison postgresql-client-15 | grep 15.6 输出示例
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安装
sudo apt install -y \
postgresql-15=15.6-1.pgdg22.04+1 \
postgresql-client-15=15.6-1.pgdg22.04+1替换=后面的 15.6-1.pgdg22.04+1 为上一步输出的版本号
查询安装的版本
dpkg -l | egrep 'postgresql-(15|client-15|contrib-15)|postgresql-(client-)?common' | awk '{print $2, $3}'psql --version