1.安裝postgresql
sudo apt-get install postgresql
2.修改postgresql數據庫默認用戶postgres密碼
sudo -u postgres psql
ALTER USER postgres WITH PASSWORD 'postgres';(一定要加分號)
\q 退出
3.修改linux用戶postgres密碼
- 切換到root,刪除postgresql用戶密碼
sudo passwd -d postgres
- 設置postgresql用戶密碼
sudo -u postgres passwd
輸出密碼
確認密碼
4.配置實現遠程登錄
- 修改監聽任何地址
vim /etc/postgresql/9.1/main/postgresql.conf
修改 #listen_addresses = ‘localhost’改爲 listen_addresses = ‘*’
- 啓用密碼驗證
/#password_encryption = on改爲password_encryption = on
- 可訪問的IP段
vim /etc/postgresql/9.1/main/pg_hba.conf,並在文檔末尾加上以下內容
# to allow your client visiting postgresql server
host all all 0.0.0.0 0.0.0.0 md5
- 重啓數據庫
/etc/init.d/postgresql restart
5.管理數據庫和用戶
- 登錄數據庫
psql -U postgres -h 127.0.0.1
- 創建新用戶zhaofeng,但不給建數據庫權限
create user “zhaofeng” with password ‘123456’ nocreatedb;
- 建立數據庫,並指定所有者
create database “testdb” with owner=”zhaofeng”;
6.安裝客戶端pgAdmin3
apt-get install -y pgadmin3