1.创建数据库的时候会指定encoding编码:
CREATE DATABASE test WITH ENCODING = 'GBK'---此处的encoding并不支持GBK,可以使用EUC_CN替代GBK;
********** Error **********
错误: GBK 是一个无效编码名字
SQL state: 42704
create database test with encoding = 'UTF8';---支持UTF8
2.创建一个数据库连接之后可以修改client_encoding:
set client_encoding='GBK'; -此处支持GBK,此时该设置仅对该连接有效
show client_encoding;
-----------------------
GBK
3.pg官网对字符集支持的阐述:
http://www.postgresql.org/docs/9.3/interactive/multibyte.html#MULTIBYTE-CHARSET-SUPPORTED
Name | Description | Language | Server? | Bytes/Char | Aliases |
---|---|---|---|---|---|
BIG5 | Big Five | Traditional Chinese | No | 1-2 | WIN950, Windows950 |
EUC_CN | Extended UNIX Code-CN | Simplified Chinese | Yes | 1-3 | |
EUC_JP | Extended UNIX Code-JP | Japanese | Yes | 1-3 | |
EUC_JIS_2004 | Extended UNIX Code-JP, JIS X 0213 | Japanese | Yes | 1-3 | |
EUC_KR | Extended UNIX Code-KR | Korean | Yes | 1-3 | |
EUC_TW | Extended UNIX Code-TW | Traditional Chinese, Taiwanese | Yes | 1-3 | |
GB18030 | National Standard | Chinese | No | 1-2 | |
GBK | Extended National Standard | Simplified Chinese | No | 1-2 | WIN936, Windows936 |
SQL_ASCII | unspecified (see text) | any | Yes | 1 | |
UHC | Unified Hangul Code | Korean | No | 1-2 | WIN949, Windows949 |
UTF8 | Unicode, 8-bit | all | Yes | 1-4 | Unicode |
4.在新建数据库的时候,指定的Encoding会影响LC_CTYPE,使用的template也会影响编码:
http://www.postgresql.org/docs/9.3/interactive/sql-createdatabase.html
The character set encoding specified for the new database must be compatible with the chosen locale settings (LC_COLLATE and LC_CTYPE). If the locale is C (or equivalently POSIX), then all encodings are allowed, but for other locale settings there is only one encoding that will work properly. (On Windows, however, UTF-8 encoding can be used with any locale.) CREATE DATABASE will allow superusers to specify SQL_ASCII encoding regardless of the locale settings, but this choice is deprecated and may result in misbehavior of character-string functions if data that is not encoding-compatible with the locale is stored in the database.
The encoding and locale settings must match those of the template database, except when template0 is used as template. This is because other databases might contain data that does not match the specified encoding, or might contain indexes whose sort ordering is affected by LC_COLLATE andLC_CTYPE. Copying such data would result in a database that is corrupt according to the new settings. template0, however, is known to not contain any data or indexes that would be affected.