可以的,CentOS 可以使用 yum 安装 PostgreSQL,但需要注意几点:
CentOS 默认仓库里就带有 PostgreSQL,但版本通常比较旧。
yum list postgresql*
yum install -y postgresql-server postgresql
安装后初始化(CentOS 7 示例):
postgresql-setup initdb
systemctl start postgresql
systemctl enable postgresql
⚠️ CentOS 7 自带一般是 PostgreSQL 9.2,CentOS 8 以后默认用
dnf,但也可用yum(兼容)
如果你想要新版本(12 / 13 / 14 / 15 / 16),建议用官方源:
# 以 PostgreSQL 15 为例(CentOS 7)
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 start postgresql-15
systemctl enable postgresql-15
yum 装如果你是 CentOS 几 + 想要哪个 PostgreSQL 版本,我可以给你精确命令。