PostgreSQL 8.4データベースの注意点

PostgreSQL 8.4データベースの注意点

EUC_JPのデータベースが作れない

  • 次のエラーが出ます

     $ createdb -E EUC_JP bookmarkx
     createdb: データベースの生成に失敗しました: ERROR:  encoding EUC_JP does not
      match locale en_US.UTF-8
     DETAIL:  The chosen LC_CTYPE setting requires encoding UTF8.
    
  • これは、initdbにおいて次の引数の場合に起こるようです。

     /etc/rc.conf
    
     postgresql_initdb_flags="--encoding=utf-8 --lc-collate=C"
    
  • このフラグを次のように「–no-locale」を追加する

     /etc/rc.conf
    
     postgresql_initdb_flags="--encoding=utf-8 --lc-collate=C --no-locale"
    
  • 次のようにデータベースの初期化をし直す。

     # /usr/local/etc/rc.d/postgresql stop
     # rm -rf /usr/local/pgsql/data
     # /usr/local/etc/rc.d/postgresql initdb
     # /usr/local/etc/rc.d/postgresql start
    
  • ユーザの作り直し

     # su -l pgsql -c 'createuser user'
     Shall the new role be a superuser? (y/n) y
     # su -l pgsql -c "createuser www"
     Shall the new role be a superuser? (y/n) n
     Shall the new role be allowed to create databases? (y/n) n
     Shall the new role be allowed to create more new roles? (y/n) y
    
  • データベースを作る

     # su -l pgsql -c 'createdb -E EUC_JP bookmarkx'
     createdb: database creation failed: ERROR:  new encoding (EUC_JP) is
      incompatible with the encoding of the template database (UTF8)
     HINT:  Use the same encoding as in the template database, or use template0 as template.
    
  • また、エラーが出る。このエラーは次のようにするとエラーが出なくなる

     # su -l pgsql -c 'createdb -E EUC_JP -T template0 bookmarkx'
    

データベースをリストアする

 # psql -f backup-database database

お疲れ様でした。