ユーザ postgres の追加
$ su
# mkdir /usr/local/pgsql
# chown postgres:postgres /usr/local/pgsql
# useradd -d /usr/local/pgsql postgres
# usermod -d /usr/local/pgsql postgres … 既にユーザ postgres がある場合はこちら
# exit
※インストーラのデフォルトはユーザ postgres のホームディレクトリが
/usr/local/pgsql であることを前提としているので必ず指定します
(インストーラのデフォルトを使用しないなら不要です)
PostgreSQL 7.1.1 のインストール
$ tar zxf postgresql-7.1.1-patched-20010508.tar.gz
$ su
# chown -R postgres:postgres postgresql-7.1.1
# su postgres ユーザだけの変更なので、自分のディレクトリに他人が移動できるようにしておきます (chmod o+x ~)
postgres-7.1.1$ cd postgresql-7.1.1
postgres-7.1.1$ ./configure --enable-multibyte=EUC_JP
postgres-7.1.1$ make
postgres-7.1.1$ make check
All 76 tests Passed. と表示されること。(いくつかエラーがあっても良い)
postgres-7.1.1$ make install
postgres-7.1.1$ exit
# su - postgres
~postgres$ cd
~postgres$ cat >> .bash_profile
PATH=/usr/local/pgsql/bin:$PATH
PG=/usr/local/pgsql
export PGLIB=$PG/lib
export PGDATA=$PG/data
export MANPATH=$PG/man:$MANPATH
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$PGLIB
^D
~postgres$ . .bash_profile
~postgres$ initdb …… 環境変数 PGDATA のディレクトリにDBクラスタを作成
~postgres$ exit
init スクリプトを設置
# cp -p postgresql-7.1.1/contrib/start-scripts/linux /etc/rc.d/init.d/postgres
# cat >> /etc/rc.d/init.d/postgres …… スクリプトへのリンクを chkconfig で行うための設定を追加
# chkconfig: 345 98 2 …… K02 K02 S98 S98 S98 K02 で設定
# description: PostgreSQL 7.1.1 ※注意:コメントとして追加します
# processname: postmaster コメントにしないと起動時に実行されてしまいます
^D
# chmod 754 /etc/rc.d/init.d/postgres
# /sbin/chkconfig --add postgres
# /sbin/chkconfig --list postgres … 確認する
DBI 1.15 のインストール
$ tar zxf DBI-1.15.tar.gz
$ cd DBI-1.15
$ perl Makefile.PL
$ make
$ make test
$ su
# make install
# exit
DBD::Pg 0.99 のインストール
$ tar zxf DBD-Pg-0.99.tar.gz
$ cd DBD-Pg-0.99
$ export POSTGRES_LIB=/usr/local/pgsql/lib
$ export POSTGRES_INCLUCE='../postgresql-7.1.1/src/include -I../postgresql-7.1.1/src/interfaces/libpq'
$ perl Makefile.PL
$ make
$ su
# su - postgres
~postgres$ pg_ctl -w start
~postgres$ exit
# exit
$ export PGUSER=postgres
$ make test
$ su
# make install
# exit
Tie::DBI 0.91 のインストール
・Tie::DBI の 'make test' で使用する ID と DB を作成する
※ GRANT の手間を省くため、DB 名はユーザ ID と一致させる
※設定の途中で pg_hba.conf を編集しますが、postmaster の再起動は不要です。
$ su
# su - postgres
~postgres$ createuser testuser … テスト用ID
Shall the new user be allowed to create databases? (y/n) y
Shall the new user be allowed to create more new users? (y/n) n
~postgres$ createdb testuser … テスト用DB
~postgres$ cat >> data/pg_hba.conf
local testuser trust … 誰でもアクセスできるようにする
^D (GRANT しなければアクセスは出来ない)
~postgres$ exit
# exit
$ tar zxf Tie-DBI-0.91.tar.gz
$ cd Tie-DBI-0.91
$ perl Makefile.PL
$ make
$ make test DRIVER=Pg DB=dbname=testuser USER=testuser
$ su
# make install
# exit
・さっき作成したテスト用の ID と DB を削除する
$ su
# su - postgres
~postgres$ dropuser testuser
~postgres$ dropdb testuser
~postgres$ vi data/pg_hba.conf 追加した行を削除する
~postgres$ exit
# exit
postgresql 7.3.2 のパスワード
バージョン 7.3 から、パスワードの扱いが変りました。
以前は、pg_passwd コマンドでパスワードファイルを作成していましたが、
pg_hba.conf に
host all all 192.168.1.10 255.255.255.255 password
と記述してもパスワードファイルを参照することはありません。
(そもそも pg_passwd コマンドが存在しません)
上記の様に設定した場合はパスワードを設定するために psql コマンドで
DataBase=# alter user postgres-userid with password 'password' ;
※パスワードを設定できるユーザ (例: postgres) で実行します。
を実行します。
この操作により、postgresql のシステムデータベースに postgres-userid と password のペアが格納されます。