1. Install PostgreSQL on CentOS 8
yum install postgresql-server postgresql-contrib
2. 初始化数据库
postgresql-setup initdb
3. 启动 DB
systemctl start postgresql
4. (Optional) Enable PostgreSQL
systemctl enable postgresql
5. 设置远程访问
su postgres
psql
# 查看配置文件位置
postgres=# show config_file;
config_file
-------------------------------------
/var/lib/pgsql/data/postgresql.conf
(1 row)
postgres=# show hba_file;
hba_file
---------------------------------
/var/lib/pgsql/data/pg_hba.conf
(1 row)
添加配置
# vi /var/lib/pgsql/data/postgresql.conf
listen_addresses = '*'
# /var/lib/pgsql/data/pg_hba.conf
host all all 0.0.0.0/0 md5
host all all ::/0 md5
6. 重启数据库
systemctl restart postgresql
7. 开放防火墙
firewall-cmd --zone=public --add-port=5432/tcp --permanent
firewall-cmd --reload
网友评论