2015年1月5日 星期一

Debian 下的 PostgreSQL

開始建公司網頁。決定採用 Yahoo 的 Isomorphic React 作為前後端的架構。資料庫則使用剛出來的 PostgreSQL 9.4。

我使用 Debian 7,閱讀 /usr/share/doc/postgresql-9.4/README.Debian.gz 讓我很快能建立一個 role 及一個 database。但是建立出來的 role 沒有自己的 password。因此還是乖乖地閱讀 PostgreSQL 文件,並上網查資料。以下是簡單的報告。

首先先依 README.Debian 建立 role 和 database:
$sudo -u postgres bash
$createuser -DRS joe
$createdb -O joe joework
當執行 psql 時,
$psql -U joe -W joework
因為沒有 joe 的 password,所以無法進入。 因為 createuser 時未給 password。
重新來過:
$dropdb joework
$dropuser joe
$createuser -DPRS joe
$createdb -O joe joework
當執行 psql 時,
$psql -U joe -W joework
psql: FATAL:  Peer authentication failed for user "joe"
修改 /etc/postgresql/9.4/main/pg_hba.conf 中的 Authentication method:
# "local" is for Unix domain socket connections only
#local   all             all                                     peer
local   all             all                                     md5
重新啟動 postgresql,因為我未使用 systemd,因此執行:
$sudo service postgresql restart
再次執行 psql,
$psql -U joe -W joework
成功。

沒有留言:

張貼留言