温馨提示×

centos能跑postgresql吗

小樊
40
2026-09-06 12:23:49
栏目: 云计算

可以的,CentOS 完全可以运行 PostgreSQL。

1. 支持情况

  • PostgreSQL 官方明确支持 RHEL / CentOS / Rocky / AlmaLinux 等发行版
  • CentOS 7、CentOS 8(及 Stream)都能安装
  • 常见版本:PostgreSQL 12 / 13 / 14 / 15 / 16 都支持

2. 安装方式(常见两种)

方式一:使用 PostgreSQL 官方 YUM 源(推荐)

# CentOS 7 示例(安装 PG15)
sudo yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
sudo yum install -y postgresql15-server postgresql15
sudo /usr/pgsql-15/bin/postgresql-15-setup initdb
sudo systemctl enable postgresql-15
sudo systemctl start postgresql-15

方式二:使用系统自带源(版本可能较旧)

sudo yum install -y postgresql-server
postgresql-setup initdb
systemctl start postgresql

3. 注意事项

  • CentOS 8 已停止维护,建议新项目用:
    • Rocky Linux
    • AlmaLinux
    • CentOS Stream
  • 防火墙需放行 5432 端口(如需要远程访问)
  • 默认只允许本地 postgres 用户连接,远程访问需修改:
    • postgresql.conf
    • pg_hba.conf

4. 简单验证

su - postgres
psql
SELECT version();

如果你告诉我 CentOS 具体版本(7 / 8 / Stream)想装的 PG 版本,我可以给你一套精确的安装命令。

0