Chinese environment, the use of PostgreSQL

2011-09-29  来源:本站原创  分类:Database  人气:87 

Chinese environment, the use of PostgreSQL

[email protected]

http://www.redgres.com/web/node/8

While the official documents mentioned coding problems, but relatively simple for the Chinese speaking to a lot of Chinese users of PostgreSQL trouble, this simple Chinese environment PostgreSQL briefly how to properly set the encoding.

First, the server-side encoding settings

PostgreSQL on the server only supports two simplified Chinese encoding: EUC_CN and UTF-8, and because windows does not support EUC Therefore, under the windows environment can only choose UTF-8.

1 encoding settings when installing

1.1 Linux under the Chinese encoding settings

Set EUC_CN
[Localhost ~] $ initdb-E EUC_CN-D data7 - locale = zh_CN

Set to UTF-8
[ Galy @ localhost ~] $ initdb-E UTF-8-D DATA7 - locale = zh_CN.UTF-8

1.2 Windows Chinese encoding settings under

Set to UTF-8
initdb.exe-E UTF8-D c: \ data3 - locale = chinese

2 common problems:

2.1 does not support the server code

If the environment's default encoding is not supported by PostgreSQL, then the time of initialization error, such as the following code to the Chinese environment, GBK, while the PG does not support GBK, so the error.
[Localhost ~] $ export LANG = zh_CN.gbk
[Localhost ~] $ initdb-D testencoding

The database cluster will be initialized with locale zh_CN.gbk.
initdb: locale zh_CN.gbk requires unsupported encoding GBK
Encoding GBK is not allowed as a server-side encoding.
Rerun initdb with a different locale selection.

2.2 locale and encoding conflict

If the specified locale and encoding format of conflict, the same will be error. Convenient solution is to specify the encoding compatible locale.

[Localhost ~] $ locale
LANG = zh_CN.gbk
LC_CTYPE = "zh_CN.gbk"

The default locale is Chinese gbk, the following code does EUC_CN, so the system error, the solution is to specify - locale = zh_CN

[Localhost ~] $ initdb-E EUC_CN-D data6
The files belonging to this database system will be owned by user "galy".
This user must also own the server process.

The database cluster will be initialized with locale zh_CN.gbk.
initdb: encoding mismatch
The encoding you selected (EUC_CN) and the encoding that the
selected locale uses (GBK) do not match. This would lead to
misbehavior in various character string processing functions.
Rerun initdb and either do not specify an encoding explicitly,
or choose a matching combination.

initdb: warning: encoding mismatch The encoding you selected (EUC_CN) and the selected language environment using the encoding (GBK) do not match.
This will cause the function to handle different string error.
To fix this problem, rerun initdb and do not explicitly specify the encoding, or choose a matching combination of the first type.

Second, the client code

Although the PG supports client and server-side code automatically converted, but also need to comply with a principle: the local environment and the client code required to encode the same. Otherwise it will be garbled or other problems.

GBK encoding is the local environment
C: \ Program Files \ PostgreSQL \ 9.1 \ bin> chcp
The active code page: 936

Database encoding to UTF8
= # \ T
Name | lenovo
Owner | lenovo
Encoding | UTF8
Collate | Chinese (Simplified) _People's Republic of China.936
Ctype | Chinese (Simplified) _People's Republic of China.936
Access privileges |

Client code to GBK
lenovo = # \ encoding
GBK

Now the local environment and the client code is GBK, so there is no problem GBK client input characters will be automatically converted to UTF-8
lenovo = # insert into test values ​​('test');
INSERT 0 1

Server-side UTF-8 encoding, spread to the client when the code will be automatically converted to GBK:
lenovo = # select * from test;
name
------
Test
(1 row)

If the client is set to UTF-8 then, and the local environment GBK inconsistency problem occurs
lenovo = # \ encoding UTF-8

Since the client code and server-side line, as UTF-8, so I do not convert to a client-side, and the operating system to display it as GBK, so garbled:
lenovo = # select * from test;
name
------
Test
(1 row)

The characters are inserted in the form of direct spread to GBK encoding server, the server could not understand, so an error.
lenovo = # insert into test values ​​('test');
ERROR: invalid byte sequence for encoding "UTF8": 0xb2
ERROR: invalid byte sequence for encoding "UTF8": 0xb2

Both input and display issues, this is because if the client and server encoding are the same, then, is not transcoding, while the input is in accordance with the local environment encoding GBK, GBK encoding into UTF-8 library, of course there will be problem.

Third, the Chinese would display information

PostgreSQL supports multi-language message, if you want the server side and client-side message for the Chinese, but also requires some additional setup.

First of all, when compiled with natural language support module required

. / Configure - enable-nls

Secondly, the configuration file postgresql.conf in the parameter settings for the Chinese

lc_messages = 'zh_CN' # locale for system error message

So the server side and client message is displayed as Chinese

[Localhost ~] $
Log: Started autovacuum
Log: The database system is ready to accept connections

# Dsd;
Error: syntax error in "dsd" at or near the first character at the statement: dsd;
Error: syntax error in "dsd" or near

相关文章
  • Chinese environment, the use of PostgreSQL 2011-09-29

    Chinese environment, the use of PostgreSQL [email protected] http://www.redgres.com/web/node/8 While the official documents mentioned coding problems, but relatively simple for the Chinese speaking to a lot of Chinese users of PostgreSQL trouble, thi

  • Chinese environment hp Itanium platform configuration 2010-07-30

    hp Itanium platform to support the Chinese language environment must be configured. profile The user. Profile where you can add the following sentence: export LANG=zh_CN.hp15CN

  • cenos Chinese environment settings http://www.oschina.net/bbs/thread/8273 2010-10-25

    Stick the code here

  • Chinese environment settings linux 2010-12-08

    export LANG = zh_CN.GB2312;

  • Debian Chinese environment settings (GNOME) 2011-08-19

    $ Sudo apt-get install locales $ Sudo dpkg-reconfigure locales Select the relevant $ Locale Often little time, patience wait for a while, and then restart can succeed. Reference Posts: http://hi.baidu.com/% B7% D7% E7% A1/blog/item/122efb0377e30e7a38

  • Centos Chinese. English system environment settings 2010-08-06

    vim / etc/sysconfig/i18n Chinese environment settings: LANG="zh_CN.GB18030" LANGUAGE="zh_CN.GB18030:zh_CN.GB2312:zh_CN" SUPPORTED="zh_CN.GB18030:zh_CN:zh:en_US.UTF-8:en_US:en" SYSFONT="lat0-sun16" English environmen

  • Postgresql database server, the backup and restore ------ SQL dump papers 2011-02-13

    Author: P From: LinuxSir.Org Summary: and everything that contains valuable data, like something, PostgreSQL databases should be backed up regularly. There are three ways to backup the PostgreSQL database, pros and cons of various methods, this artic

  • Sybase / PHP / JSP development environment, the establishment of the main points 2010-03-29

    Sybase / PHP / JSP development environment, the establishment of the main points Apache/2.0.54 Sybase / 11.9 Client PHP/4.3.7 Weblogic / 8.1 Windows / 2000 Pro Development workstation window2000 pro, ip: 192.168.0.33, while a Sybase server database s

  • Redhat Linux Enterprise 5.4 Chinese display and input Chinese 2010-02-05

    Bahrain Redhat Linux Enterprise 5.4 just pretty excited, but I would like to configure the search in the Linux environment, it is necessary to test the Chinese search, Chinese environment must support. First, I will change the Chinese Language, when

  • Java / JSP Chinese garbage problem-solving experience (change) 2010-06-09

    From: http://www.xici.net/u9206704/d56632455.htm Since access to Java and JSP has been with the Java on the issue of Chinese garbage deal, and now finally been completely resolved, we now experience and share solutions. 1, Java the Chinese origin of

  • doc vim after the installation of the Chinese under the Chinese garbled in the windows solution 2010-06-25

    http://blog.sina.com.cn/s/blog_5dcf0e570100fh6m.html Vim properly set the character encoding options (gVim / Vim on Win32 Chinese Environment) And all of the popular text editor, like, Vim can edit all kinds of good character encoding of the file, wh

  • Chinese doc vim after the installation of windows under the Chinese garbled in the solution 2010-06-25

    http://blog.sina.com.cn/s/blog_5dcf0e570100fh6m.html Vim properly set the character encoding options (gVim / Vim on Win32 Chinese environment) And all of the popular text editor, like, Vim can edit all kinds of good character encoding of the file, wh

  • PostgreSQL on the Ubuntu Installation Guide 2010-07-29

    Installation environment: Ubuntu 10.04-desktop-i386 PostgreSQL 8.4 1. Install PostgreSQL Enter the following command sudo apt-get install postgresql Will be prompted to install the required disk space, enter "y", install the program automaticall

  • The Chinese set about Debian 2010-07-30

    If we install debian base system when the choice of the English language environment, and later want to change it to Chinese, we need to complete the following aspects of work. Set locale If the locale is not installed tool, you must first install it

  • Chinese garbled analytical approach to Java 2010-09-07

    I write this not explain the gap between Chinese and English, decoding, I would work the last few years I meet all kinds of garbage solution, sum up, I hope you can solve their own faint garbled method tells that, we get a solution to the garbled "ho

  • Linux oracle em Chinese garbage solutions 2010-09-07

    If the installation, our system environment variable set in Chinese environment, then there would be no problem. The root of the problem is that installation, JDK / JRE automatically select the character set. In the $ ORACLE_HOME / jdk / jre / lib an

  • linux latex Chinese solution (UTF8) 2010-09-19

    CJK talking about here is a solution, but simple, step by step, it wants to follow suit. The focus here is the Chinese character configuration (UTF8 encoded). latex has been the Chinese font configuration is headache. If you do not find on the way Af

  • [Transfer] ssh Chinese garbled 2010-10-20

    Chinese garbled ssh Is fine. Rich and colorful. linux problem under normal display Chinese, the author has been most concerned about. When using ssh to log in to the Chinese environment, linux server, Chinese or garbled. We supposed to do? This is bo

  • smartforms printing garbled in Chinese and English 2010-10-30

    In smartforms encounter when printing with the form in English Sometimes the system will not be processed garbled sometimes do not know what the system or configuration of things Now is my solution because it is in English and Chinese environment wit

  • Reprinted - Linux development environment tools 2010-11-12

    Blog page up and exchange proposed adding Links recommended list of complaints Search: Help Snake dance snake Millennium, the Millennium cultivation; snake dance, air swallowing the sky. jcodeer.cublog.cn * Management blog * Published an article * Me