官方文檔: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