安裝環境:
Ubuntu 64bit
PostgreSQL 9.0
1. 安裝PostgreSQL
輸入如下命令
sudo apt-get install postgresql
系統會提示安裝所需磁碟空間,輸入"y",安裝程式會自動完成。 安裝完畢後,系統會建立一個資料庫超級使用者“postgres”, 密碼為空白。這個使用者既是不可登入的作業系統使用者,也是資料庫使用者。
2. 修改ubuntu使用者postgres的密碼
輸入如下命令
sudo passwd postgres
3. 修改資料庫超級使用者postgres的密碼
1) 切換到ubuntu下postgres使用者
sudo su postgres
2) 登入postgres資料庫
psql postgres
這樣你會看到postgres提示資訊如下:
psql (9.0.0)
Type "help" for help.
並出現postgres的命令列提示符號:
postgres=#
3) 輸入如下命令
ALTER USER postgres with PASSWORD 'password'
鍵入“\q”返回到ubuntu命令列。
4. 添加自己定義的使用者和資料庫,在資料庫中任何命令都可以是用 命令 --help 的形式 取得協助
如:createuser
1) 添加新使用者
createuser -drSP fedoraAdmin
這段參數的意思就是:使用者可以建立資料庫、使用者可以建立其他使用者、該使用者不是超級管理使用者、需要分配一個密碼給該帳號
按照提示輸入該使用者的密碼。
2) 建立一個屬於自訂使用者fedoraAdmin的資料庫
createdb -O fedoraAdmin mydb
通過如上設定,可以在Java中通過以下配置來串連PostgresSQL資料庫
user:fedoraAdmin
password: your password
url: jdbc:postgresql://localhost:5432/mydb
5. 安裝pgAdmin3
1) 鍵入如下命令安裝pgAdmin3
sudo apt-get install pgadmin3
2) 鍵入如下命令運行pgAdmin3
pgadmin3
你就會看到pgAdmin3的主介面如下所示:
添加相應的參數以建立一個到PostgreSql的串連:
6. 設定其它機器上對postgres的訪問
修改/etc/postgresql/9.0/main/pg_hba.conf:
host all all 0.0.0.0/0 md5 #0.0.0.0為位址區段,0為多少二進位位
例如:192.168.0.0/16代表192.168.0.1-192.168.255.254
修改/etc/postgresql/9.0/main/postgresql.conf
listen_address = '*'
重啟資料庫
sudo /etc/init.d/postgresql-9.0 restart