先更新源,再执行安装和初始化等指令
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
验证5432端口是否打开了(后续需要修改端口)
ss -ntl|grep 5432
LISTEN 0 128 127.0.0.1:5432 *:*
LISTEN 0 128 [::1]:5432 [::]:*
切换到postgres用户 查看数据库版本
su - postgres
psql (12.15)