1. 配置文件
# cat /var/lib/pgsql/9.5/data/pg_hba.conf

# cat /var/lib/pgsql/9.5/data/postgresql.conf

# systemctl restart postgresql-9.5.service
# ss -tan | grep 5432

2. 用管理员用户建库和创建普通用户
# psql -h 192.168.1.106 -p 5432 -U postgres
postgres=# create user test01_user with password 'Test01@123';
postgres=# create database test01 owner test01_user;
postgres=# grant all privileges on database test01 to test01_user;

# psql -h 192.168.1.106 -p 5432 -U postgres -d postgres
postgres=# create user test02_user with password 'Test02@123';
postgres=# create database test02;
postgres=# grant all privileges on database test02 to test02_user;

可以看出,postgres作为数据库管理员,建库如果不指定owner,那么默认是postgres
3. 测试连接
# psql -h 192.168.1.106 -p 5432 -U test01_user
# psql -h 192.168.1.106 -p 5432 -U test01_user -d test01

# psql -h 192.168.1.106 -p 5432 -U test02_user -d test02

# psql -h 192.168.1.106 -p 5432 -U postgres -d test01
# psql -h 192.168.1.106 -p 5432 -U postgres -d test02

可以看出,postgres用某个用户登录,默认登录同名数据库,如果用户名和数据库不同,需要特别指定,否则会报找不到库!
4.参考
PostgreSQL 设置允许访问IP
https://blog.csdn.net/wlchn/article/details/78915813
postgresql数据库用户名密码验证失败
https://blog.csdn.net/pg_hgdb/article/details/78805463
PostgreSQL的访问控制(pg_hba.conf)
https://my.oschina.net/liuyuanyuangogo/blog/497239
Postgresql 远程连接配置
https://www.cnblogs.com/3Tai/p/4935303.html
PostgreSQL远程连接配置管理/账号密码分配
https://yq.aliyun.com/articles/599287
Postgres password authentication fails
https://stackoverflow.com/questions/14564644/postgres-password-authentication-fails?rq=1
https://stackoverflow.com/questions/18664074/getting-error-peer-authentication-failed-for-user-postgres-when-trying-to-ge/26735105#26735105