在 CentOS 上可以安装 多个版本的 PostgreSQL,具体取决于你使用的 CentOS 版本以及是否使用官方仓库。
以 PostgreSQL 15(CentOS 7) 为例:
# 安装 repo
yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
# 安装
yum install -y postgresql15-server postgresql15
# 初始化
/usr/pgsql-15/bin/postgresql-15-setup initdb
# 启动
systemctl enable postgresql-15
systemctl start postgresql-15
yum list available postgresql*
通常只有:
⚠️ 不推荐用系统自带版本(版本旧、升级麻烦)
| 场景 | 推荐版本 |
|---|---|
| 老系统 / 稳定优先 | PostgreSQL 13 |
| 新项目 | PostgreSQL 15 / 16 |
| 兼容旧应用 | 10 / 11 |
| CentOS 7 | ≤ 15 |
我可以给你 最合适的版本 + 完整安装命令。