PostgreSQL Sever需要配置才可被用户远程链接
配置文件:
pg_hba.conf 控制访问安全,管理客户端访问PostgreSQL server的访问权限。
postgresql.conf 数据库参数文件,配置数据库相关参数。
pg_ident.conf 客户端访问server通过ident模式,会使用pg_ident.conf文件,模拟操作系统用户访问。
PG查看配置文件的位置
postgres=# select name, setting from pg_settings where category = 'File Locations';
name | setting
-------------------+---------------------------------
config_file | /opt/pgsql/data/postgresql.conf
data_directory | /opt/pgsql/data
external_pid_file |
hba_file | /opt/pgsql/data/pg_hba.conf
ident_file | /opt/pgsql/data/pg_ident.conf
(5 rows)
配置server可远程访问
1.配置pg_hba.conf
# "local" is for Unix domain socket connections only
local all all trust
# IPv4 local connections:
host all all 127.0.0.1/32 trust
host all all 0.0.0.0/0 md5
# IPv6 local connections:
host all all ::1/128 trust
md5使用密码登陆
2.配置监听postgresql.conf
#listen_addresses = 'localhost' # what IP address(es) to listen on;
listen_addresses = '*' # what IP address(es) to listen on;
3.为初始用户设定密码
alter user postgres with password 'ikdhfel';
4.配置文件都配置好后重启pg server测试远程链接
[postgres@postgresql data]$ pg_ctl restart -D /opt/pgsql/data
waiting for server to shut down.... done
server stopped
waiting for server to start....2018-12-10 16:40:29.828 CST [636] LOG: listening on IPv4 address "0.0.0.0", port 5432
2018-12-10 16:40:29.828 CST [636] LOG: listening on IPv6 address "::", port 5432
2018-12-10 16:40:29.833 CST [636] LOG: listening on Unix socket "/tmp/.s.PGSQL.5432"
2018-12-10 16:40:29.857 CST [637] LOG: database system was shut down at 2018-12-10 16:40:29 CST
2018-12-10 16:40:29.861 CST [636] LOG: database system is ready to accept connections
done
server started