2010年7月15日木曜日

postgrsql.8.4.xでcreatedb実行時に文字コードエラー

どうも、俺@残業中です。

postgresql.8.4系で
$ createdb hoge_db -E UTF8
createdb: database creation failed: ERROR: new encoding (UTF8) is incompatible with the encoding of the template database (EUC_JP)
HINT: Use the same encoding as in the template database, or use template0 as template.
のエラーが出ました。

これはinitdb時に文字コードをEUC-JPで作成したためUTF-8なデータベースが作成できないよ!というエラーです。ちなみにpostgresql8.4系から出るエラーだそうです。

こんな時は、「Use the same encoding as in the template database, or use template0 as template」しましょう。
つまり、template0のテンプレートデータベースを使ってcreatedbしましょう。

$ createdb hoge_db -E UTF8 -T template0
これで出来るはずです。

テンプレートデータベースとはなんじゃらほい?ですが、
PostgreSQL テンプレートデータベースに説明があります。
template1というデータベースはデータベース作成時に元となるテンプレートで、initdbなどした初期設定の情報などが入っています。
template0というデータベースは、初期設定のないテンプレートだそうです。


ちゃんちゃん。

0 件のコメント: