Postgres データベース

[Postgres 7.4.6]
7.3以降では、initdbコマンド実行時に、initdb –encoding=EUC_JP –no-locale
のように–no-localeを付けて作成しないと、日本語のソート処理、検索に不具合が発生します。


当初、initdb –encoding=EUC_JPで作って作成していたため、一部の検索がおかしかった。
(http://search.picolix.jpの業種選択でおかしなことになっていた。)
DBを再作成してOKとなりました。
尚、–no-localeを付けるのと付けないのでは、postgresql.conf中のlc_関連が下記のようになる。
これらを書き換えてcreatedbしたものは、OKですが、すでに、createdbしたものは、再作成が必要です。
–no-localeがない時
lc_messages = ‘en_US.UTF-8’
lc_monetary = ‘en_US.UTF-8’
lc_numeric = ‘en_US.UTF-8’
lc_time = ‘en_US.UTF-8’
–no-localeがある時
lc_messages = ‘C’
lc_monetary = ‘C’
lc_numeric = ‘C’
lc_time = ‘C’
[再作成手順]
#
postgresユーザでデータベースのダンプをとる。
$pg_dump lisa -u > lisa.dmp
postgresを停止させる。
#/etc/init.d/postgresql stop
データベースのディレクトリーをdata-oldにする。
(再作成に失敗した時に、data-oldをdataに戻せばいつでも復旧できます。)
$cd /usr/local/pgsql/
$mv data data-old
–encoding=EUC_JP –no-localeオプションを付けて再作成
$initdb –encoding=EUC_JP –no-locale
データべース、ユーザの作成
$createdb lisa
$createuser lisa
$psql lisa
認証は、MD5にて行うので、encryptedを付けてパスワードを作成する。
>ALTER USER postgres encrypted password ‘xxxxxxx’;
>ALTER USER lisa encrypted password ‘xxxxxxx’;
>q
ダンプしたデータのインポート
$psql lisa -U lisa < lisa.dmp
以上、メモでした。