Ubuntu的默認存儲庫包含Postgres包,所以咱們可使用apt
包裝系統輕鬆安裝這些包。sql
sudo apt-get update
sudo apt-get install postgresql postgresql-contrib
默認狀況下,Postgres使用稱爲「角色」的概念來處理身份驗證和受權。這些在某些方面相似於普通的Unix風格的帳戶,可是Postgres並無區分用戶和組,而是傾向於更靈活的術語「角色」。shell
安裝Postgres後,設置爲使用ident身份驗證,這意味着它將Postgres角色與匹配的Unix / Linux系統賬戶相關聯。若是Postgres中存在一個角色,則具備相同名稱的Unix / Linux用戶名將可以以該角色登陸。數據庫
有幾種方式可使用此賬戶訪問Postgres。安全
安裝過程建立了一個postgres
與默認Postgres角色關聯的用戶賬戶。爲了使用Postgres,咱們能夠登陸到該賬戶。bash
輸入如下內容切換到postgres
服務器上的賬戶:服務器
sudo -i -u postgres
您如今能夠經過鍵入如下命令當即訪問Postgres提示符:ide
psql
您將當即登陸並可以與數據庫管理系統交互。post
輸入如下命令退出PostgreSQL提示符:spa
\q
您如今應該回到postgres
Linux命令提示符。postgresql
sudo -u postgres psql
這會將你直接登陸到Postgres中,而不須要中間的bash
shell。
一樣,您能夠鍵入如下命令退出交互式Postgres會話:
\q
修改Postgres用戶密碼:
postgres=# \password Enter new password: Enter it again: postgres=#
遠程鏈接postgres數據庫的過程當中可能會出現下面這個問題
Unable to connect to server:
FATAL: no pg_hba.conf entry for host "xxx.xxx.xxx.xxx", user "postgres", database "thingsboard", SSL off
PostgreSQL數據庫爲了安全,它不會監聽除本地之外的全部鏈接請求,當用戶經過JDBC訪問是,會報一些以下的異常:
org.postgresql.util.PSQLException: FATAL: no pg_hba.conf entry for host
要解決這個問題,只須要在PostgreSQL數據庫的安裝目錄下找到/data/pg_hba.conf
在其中加上請求鏈接的機器IP來容許相應IP的用戶訪問數據庫