官方文档:https://www.postgresql.org/download/linux/redhat/
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 postgresql12-server
sudo /usr/pgsql-12/bin/postgresql-12-setup initdb
sudo systemctl enable postgresql-12
sudo systemctl start postgresql-12
按照官方文档操作执行如下命令:
sudo yum install -y postgresql12-server
提示找不到,此时需要进行如下操作:
# 查找repo文件,复制pgdg-redhat-all.repo这个文件名
ls -l /etc/yum.repos.d/
# 编辑这个配置文件,将刚刚复制的文件名添加进去
vim /etc/yum/pluginconf.d/releasever_adapter.conf
继续执行:sudo yum install -y postgresql12-server
出现错误:Error: Failed to download metadata for repo 'pgdg-common': repomd.xml GPG signature verification error: Bad GPG signature
此时只需要修改安装命令即可:
sudo yum install -y --nogpgcheck postgresql12-server