LoginSignup
8
9

More than 5 years have passed since last update.

Debian系でPostgreSQLのロケールを変更する

Last updated at Posted at 2014-06-20

本家のやり方だと初期のロケール設定はinitdb -e UTF-8 --no-localeとかするわけですが、Debian系だとインストールしたら勝手にこれが実行されるので困ったもんだという話。

Debian系でのローカルルール

  • 設定は/etcに、データは/varに置かれます。それに伴い独自のコマンド群が用意されています。
  • apt-get installすると自動的にinitdb相当の処理が行われます。

元のinitdb等は/usr/lib/postgresql/9.1/bin/とかに置かれてますが、Debianのコマンド群を使うなら直接触らない方がよいでしょう。

最初から任意のロケールにする

initdbのデフォルト値として、ロケールは実行時のLANG環境変数等が、エンコーディングはロケールから推測するかSQL_ASCIIが使われます。

ので、apt-get installを実行するときに、目標のロケールをLANG環境変数に入れておけばOK。

ただしロケールなしにしたい時はエンコーディングが推測できずにSQL_ASCIIになってしまうので、この場合は作り直すしかないようです。

作り直す

バージョン番号(9.1)は適宜読み替えてください。

# 勝手に入れられたクラスタを削除
# pg_ctl stopとデータファイルの削除に相当
pg_dropcluster --stop 9.1 main

# 作り直し
# initdbとpg_ctl startに相当
pg_createcluster -e UTF-8 --no-locale --start main

参考

http://askubuntu.com/questions/371737/install-postgresql-why-is-initdb-unavailable
https://wiki.debian.org/PostgreSql
http://lets.postgresql.jp/documents/technical/text-processing/2

8
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
9