參考
https://www.postgresql.org/download/linux/debian/
安裝
文檔中說了postgresql已經存在於debian的源中,直接通過
apt-get install postgresql-11
就可以安裝
配置
安裝完成后,postgresql,默認只能本地訪問,需要修改配置
編輯/etc/postgresql/11/main/pg_hba.conf
把
# IPv4 local connections:
host all all 127.0.0.1/32 md5
修改成
host all all 0.0.0.0/0 md5
這個文檔上面有介紹,0.0.0.0/0表示允許所有ip
編輯/etc/postgresql/11/main/postgresql.conf
把
#------------------------------------------------------------------------------
# CONNECTIONS AND AUTHENTICATION
#------------------------------------------------------------------------------
# - Connection Settings -
# listen_addresses = 'localhost' # what IP address(es) to listen on;
# comma-separated list of addresses;
# defaults to 'localhost'; use '*' for all
# (change requires restart)
修改為
listen_addresses = '*'
把注釋去掉,改localhost為星號。文檔已經說了,默認是監聽本地,如果需要監聽其他連接,改成星號(*),表示監聽所有,需要重啟服務或系統
增加數據庫密碼
postgresql安裝的時候沒有要求輸入密碼,默認是空密碼
#進入postgres默認用戶 sudo su - postgres #進入數據庫 psql #修改密碼 \password postgres
這樣就可以正常訪問postgresql數據庫了