PostgreSQL8.3のインストール
インストール
手元にある EC-CUBE(1.4.5) をローカルにインストールするため、PostgreSQL を apt-get でインストール。
% sudo apt-get install postgresql
インストールすると、postgres ユーザが作られる。ホームディレクトリは /var/lib/postgreseql。以下は、/etc/passwd より抜粋。
postgres:x:115:127:PostgreSQL administrator,,,:/var/lib/postgresql:/bin/bash
ユーザの作成
PostgreSQLをインストールしたので、ユーザを作成。
createuser --createdb --no-adduser --pwprompt ec_shop1 Enter password for new role: ← パスワードを入力 Enter it again: ← パスワードを入力 Shall the new role be allowed to create more new roles? (y/n) n
DBの作成
次に、データベースを作成しようとしたらIdentのエラーが出た。
$ createdb -E EUC_JP -U ec_shop1 db_ec_shop1 createdb: could not connect to database postgres: FATAL: Ident authentication failed for user "ec_shop1"
きっとOSのユーザも作らなければならないんだろうと思ったけど、面倒だし、EC-CUBEも別に外部に公開するような用途に使用するわけではないので、設定ファイルを編集する。
設定ファイル: /etc/postgresql/8.3/main/pg_hda.conf
# TYPE DATABASE USER CIDR-ADDRESS METHOD # "local" is for Unix domain socket connections only #local all all ident sameuser ←コメントアウト local all all trust ←追加
postgresql を再起動。
% sudo /etc/init.d/postgresql-8.3 restart
もう一度やってみたら今度は違うエラー。
postgres@pluto:~$ createdb -E EUC_JP -U ec_shop1 db_ec_shop1 createdb: database creation failed: ERROR: encoding EUC_JP does not match server's locale ja_JP.UTF-8 DETAIL: The server's LC_CTYPE setting requires encoding UTF8.
ロケールとエンコーディングが違っているよとのことで、グーグルで検索したら、initdb で、「--no-locale」を指定しないといけないらしい。ちなみに initdb してなかった。。。インストール時にやってくれたのかな。
参考サイト: UbuntuのPostgreSQLでEUC_JPのデータベースを作る - World Wide Wonderful
initdbするため、既存のやつを mv して一応バックアップ。
postgres@pluto:~$ cd /var/lib/postgresql/8.3/main postgres@pluto:~/8.3/main$ mv main main_bak
initdb を実行。エンコーディングは指定しないでみる。後々EC-CUBEの2系もインストールする予定だけど、2系はUTF-8の為。
ちなみに、PostgreSQL 8.4 では、データベースの作成時に、ロケールの設定が出来るようになっているみたい。8.3 までは initdb(データベースクラスタ) 実行時。
参考サイト: ロケール(国際化と地域化) — Let's Postgres
postgres@pluto:~$ /usr/lib/postgresql/8.3/bin/initdb -D /var/lib/postgresql/8.3/main --no-locale The files belonging to this database system will be owned by user "postgres". This user must also own the server process. The database cluster will be initialized with locale C. The default database encoding has accordingly been set to SQL_ASCII. The default text search configuration will be set to "english". fixing permissions on existing directory /var/lib/postgresql/8.3/main ... ok creating subdirectories ... ok selecting default max_connections ... 100 selecting default shared_buffers/max_fsm_pages ... 24MB/153600 creating configuration files ... ok creating template1 database in /var/lib/postgresql/8.3/main/base/1 ... ok initializing pg_authid ... ok initializing dependencies ... ok creating system views ... ok loading system objects' descriptions ... ok creating conversions ... ok creating dictionaries ... ok setting privileges on built-in objects ... ok creating information schema ... ok vacuuming database template1 ... ok copying template1 to template0 ... ok copying template1 to postgres ... ok WARNING: enabling "trust" authentication for local connections You can change this by editing pg_hba.conf or using the -A option the next time you run initdb. Success. You can now start the database server using: /usr/lib/postgresql/8.3/bin/postgres -D /var/lib/postgresql/8.3/main or /usr/lib/postgresql/8.3/bin/pg_ctl -D /var/lib/postgresql/8.3/main -l logfile start
ん、、最後に、initdb で作成したデータベースクラスタを指定して起動できるよみたいなことが。。mv で main のバックアップとる必要はないのかも(新しく作ってそれを指定)。あと何か警告が出てるけど、これは Identエラー対処の結果かなと思って、main 配下を消して
postgres@pluto:~$ /usr/lib/postgresql/8.3/bin/initdb -A trust -D /var/lib/postgresql/8.3/main --no-locale
してみたら警告は表示されなかった。
で、pg_ctl でサーバ起動。
/usr/lib/postgresql/8.3/bin/pg_ctl -D /var/lib/postgresql/8.3/main -l /var/log/postgresql/postgresql-8.3-main.log start
そして、再度 createdb を実行したら問題なく行った。
postgres@pluto:~$ createdb -E EUC_JP -U ec_shop1 db_ec_shop1
よかったよかった。