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. 用管理員用戶建庫和創(chuàng)建普通用戶
# 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作為數(shù)據(jù)庫管理員,建庫如果不指定owner匈勋,那么默認(rèn)是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用某個用戶登錄,默認(rèn)登錄同名數(shù)據(jù)庫洽洁,如果用戶名和數(shù)據(jù)庫不同痘系,需要特別指定,否則會報找不到庫饿自!
4.參考
PostgreSQL 設(shè)置允許訪問IP
https://blog.csdn.net/wlchn/article/details/78915813
postgresql數(shù)據(jù)庫用戶名密碼驗證失敗
https://blog.csdn.net/pg_hgdb/article/details/78805463
PostgreSQL的訪問控制(pg_hba.conf)
https://my.oschina.net/liuyuanyuangogo/blog/497239
Postgresql 遠(yuǎn)程連接配置
https://www.cnblogs.com/3Tai/p/4935303.html
PostgreSQL遠(yuǎn)程連接配置管理/賬號密碼分配
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