版本
centos
[root@alpha ~]# cat /etc/centos-release
CentOS Linux release 7.8.2003 (Core)
pgsql
[root@alpha ~]# psql --version
psql (PostgreSQL) 10.12
步骤
安装
配置
切换用户
默认已经创建了postgres用户
[root@alpha ~]# su - postgres
Last login: Sat May 9 01:36:14 CST 2020 on pts/1
-bash-4.2$
修改密码
善用帮助文档
-bash-4.2$ psql
psql (10.12)
Type "help" for help.
postgres=# help
You are using psql, the command-line interface to PostgreSQL.
Type: \copyright for distribution terms
\h for help with SQL commands
\? for help with psql commands
\g or terminate with semicolon to execute query
\q to quit
postgres=# \?
postgres=# \password postgres
Enter new password:
Enter it again:
postgres-# \q
修改客户端认证配置文件
vi /var/lib/pgsql/10/data/pg_hba.conf
最后面加上下面这行
host all all 0.0.0.0/0 md5
修改pg配置文件
vi /var/lib/pgsql/10/data/postgresql.conf
# - Connection Settings -
listen_addresses = '*' # what IP address(es) to listen on;
# comma-separated list of addresses;
# defaults to 'localhost'; use '*' for all
# (change requires restart)
port = 5432 # (change requires restart)
重启pgsql
systemctl restart postgresql-10
防火墙设置
#开机启用防火墙
systemctl enable firewalld
#开启防火墙
systemctl start firewalld
#开放postgresql服务
firewall-cmd --add-service=postgresql --permanent
#添加端口
firewall-cmd --zone=public --add-port=5432/tcp --permanent
#重载防火墙
firewall-cmd --reload
#查看占用端口
firewall-cmd --list-ports