1.打開配置文件路徑
# 參考路徑
/var/lib/pgsql/9.6/data
2.修改pg_hba.conf
# "local" is for Unix domain socket connections only
local all all peer
# IPv4 local connections:
host all all 127.0.0.1/32 md5
# 此處新增->所有ip可訪問
host all all 0.0.0.0/0 md5
3.修改postgresql.conf
# - Connection Settings -
# 監聽所有地址發出的請求
# 默認只監聽本地,取消下方注釋,並將localhost改為*
listen_addresses = '*' # what IP address(es) to listen on;
4.重啟服務
sudo systemctl restart postgresql-9.6
5.擴展
PostgreSQL會創建一個默認的沒有密碼的linux用戶postgres
修改postgresql默認用戶postgres的密碼
# 1.postgres用戶登錄psql
# 登錄postgres用戶
sudo -i -u postgres
# 打開psql
psql
# 簡化:sudo -u postgres psql
# 2.修改數據庫用戶postgres的密碼
ALTER USER postgres WITH PASSWORD 'mypassword';
# 3.退出數據庫
\q
修改linux用戶postgres的密碼(擴展)
# 查看當前用戶
whoami
# 1.刪除linux下用戶postgres的密碼
sudo passwd -d postgres
# 2.設置用戶postgres的密碼
sudo -u postgres passwd
# 3.按提示輸入密碼
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully