PG

安装postgresql数据库

已邀请:

方法 2:配置 PostgreSQL 官方 YUM 仓库
如果你需要特定版本的 PostgreSQL 或需要从 PostgreSQL 的官方仓库安装,可以按照以下步骤配置官方 YUM 仓库:

下载 PostgreSQL 的 YUM 仓库配置文件:


访问 PostgreSQL YUM Repositories 页面,选择适合你的系统的版本和架构的配置文件。例如,对于 PostgreSQL 13 和 CentOS 7 x86_64,你可以下载 pgdg-redhat-repo-latest.noarch.rpm。


安装下载的 YUM 仓库配置文件:


sudo yum localinstall https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm


确保 URL 与你下载的仓库文件相匹配,并且根据你的 CentOS/RHEL 版本和架构进行调整。


安装 PostgreSQL:


sudo yum install postgresql13-server postgresql13


同样,将 postgresql13 替换为你想要的版本号。


初始化数据库(对于首次安装):


sudo /usr/pgsql-13/bin/postgresql-13-setup initdb


将 13 替换为你的 PostgreSQL 主版本号。


启动 PostgreSQL 服务:


sudo systemctl start postgresql-13
sudo systemctl enable postgresql-13

将 13 替换为你的 PostgreSQL 主版本号。


注意:
确保在操作前检查你的 CentOS/RHEL 版本和架构,以选择正确的仓库配置文件和包。

如果系统提示 GPG 密钥问题,可以尝试添加 PostgreSQL 的 GPG 密钥(通常在安装仓库文件时会自动处理)。如果需要手动添加,可以使用如下命令:


sudo rpm —import https://download.postgresql.org/pub/repos/yum/RPM-GPG-KEY-PGDG


通过以上任一方法,你都可以成功地在 CentOS 或 RHEL 系统上安装 PostgreSQL。

要回复问题请先登录注册