1.安装(CentOS 7)

#拉取rp包,并install
yum install https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
#install pg服务
yum install postgresql12-server
#初始化db
/usr/pgsql-12/bin/postgresql-12-setup initdb
#启动服务
systemctl enable postgresql-12
systemctl start postgresql-12

2.允许远程访问

#进入/var/lib/pgsql/12/data
1.修改postgresql.conf
取消#listen_addresses = 'localhost'注释
修改为listen_addresses = '*'

2.修改pg_hba.conf
# IPv4 local connections:
host     all     all                 127.0.0.1/32              trust #本地信任访问,密码可有可无
host     all     all                 192.168.1.0(内网网段)/24              md5 #内网可访问,密码md5加密,24是允许网段192.168.1.0的所有主机可访问
host     all     all                 0.0.0.0/0                 md5 #允许外网访问,,密码md5加密

3.其他

3.1 关于postgresql yum安装,目录迁移问题

参考:postgresql目录迁移问题(无需卸载重装)