FreeBSD (ports) で PostgreSQL を、とりあえず動くようにする

ports から PostgreSQL をインストールする

root# cd /usr/ports/databases/postgresql83-server/
root# make clean
root# make
root# make install
root# make clean

ホームディレクトリを変更する

ホームディレクトリを作る
root# mkdir /home/pgsql
root# chmod 755 /home/pgsql
root# chown pgsql:pgsql /home/pgsql
ホームディレクトリを登録する
  • vipw を使って、ホームディレクトリが /home/pgsql になるよう /etc/passwd を修正する

データベースを初期化する

  • /etc/rc.conf に次の行を追加する
postgresql_enable="YES"
postgresql_initdb_flags="--encoding=EUC_JP --lc-collate=C"
  • データベースの初期化を実行する
root# /usr/local/etc/rc.d/postgresql initdb

データベースサーバを起動する

root# /usr/local/etc/rc.d/postgresql start
  • この時点でコマンドを入れてみて、次のようにエラーになれば動いている
root# psql -l
psql: FATAL:  role "root" does not exist

ユーザを登録する

  • su - pgsql してからユーザ katsu を追加
pgsql% createuser katsu
Shall the new role be a superuser? (y/n) n
Shall the new role be allowed to create databases? (y/n) y
Shall the new role be allowed to create more new roles? (y/n) y