現在、CentOS5.3 と PostgreSQL 8.3 で検証中です。
デフォルトのエンコードはUTF8 ?
PostgreSQL のデータベースを初期化する際に、エンコード指定のオプションをつけなかった場合、データベースのエンコードは UTF8 になるようです。
ただし、これが PostgreSQL のデフォルトなのか、Linux システムのエンコードを継承しているのかは未確認。今回使用している CentOS のシステムの文字コードは UTF8 です。
[root@centos ~]# cat /etc/sysconfig/i18n LANG="ja_JP.UTF-8"
また、システム自体のエンコードとは違う文字コードの設定はできないようです。
postgres=> CREATE DATABASE sampledb2 WITH ENCODING = 'EUC_JP'; ERROR: encoding EUC_JP does not match server's locale ja_JP.UTF-8 DETAIL: The server's LC_CTYPE setting requires encoding UTF8.
データベースのエンコードの確認
データベースのエンコードの確認は、該当のデータベースに接続して、\encoding で行うことができます。
[root@centos ~]# su - centos [centos@centos ~]$ psql postgres (省略) postgres=> \encoding UTF8
また、存在するデータベースをリスト化する \l でもエンコードを確認することができます。こっちのほうが早いですね。
postgres=> \l
List of databases
Name | Owner | Encoding
-----------+----------+----------
postgres | postgres | UTF8
template0 | postgres | UTF8
template1 | postgres | UTF8
(3 rows)







