yuzhou...@163.com
unread,Jun 10, 2008, 5:46:47 AM6/10/08Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to PostgreSQL 8 DBA 專業指南中文版
我仔细测试了一下:
1. initdb -D /pgdata --locale=C
2. pg_ctl start -D /pgdata -o '-p 9999 -i'
3. createdb -p 9999 -U postuser -E UNICODE testdb
4. psql -p 9999 -U postuser -l
返回列表:
数据库列表
名字 | 所有者 | 编码
-----------+-----------+-----------
postgres | postuser | SQL_ASCII
template0 | postuser | SQL_ASCII
template1 | postuser | SQL_ASCII
testdb | postuser | UTF8
(4 行)
5.向数据库中建表,插入数据(其中有中文)
psql -p 9999 -U postuser -d testdb -q -f test.sql
执行成功,没有出现错误信息.
test.sql 内容如下:
SET client_encoding = 'GB18030';
SET check_function_bodies = false;
SET SESSION AUTHORIZATION 'postuser';
SET search_path = public, pg_catalog;
CREATE TABLE test (
iid serial NOT NULL,
name character varying,
code character varying
);
INSERT INTO test (iid, name, code) VALUES (1, '礽', NULL);
INSERT INTO test (iid, name, code) VALUES (2, '礽中国', 'testcode');
INSERT INTO test (iid, name, code) VALUES (3, '礽中国是什么陈致慜聚鑫物昊物甄拓鑫',
'testcode');
INSERT INTO test (iid, name, code) VALUES (4, '礽中国是什么陈致慜聚鑫物昊物甄拓鑫中打开打开
开裆裤的', NULL);
5.psql -p 9999 -U postuser -d testdb
psql =>
可以进入交互模式
6.在 交互模式中 查询表的数据(其中有中文)
psql => select * from test;
返回结果,可以正确显示中文
7.在 交互模式中 设置 encoding
psql =>\encoding GB18030
psql =>\set
AUTOCOMMIT = 'on'
VERBOSITY = 'default'
PROMPT1 = '%/%R%# '
PROMPT2 = '%/%R%# '
PROMPT3 = '>> '
DBNAME = 'testdb'
USER = 'postuser'
PORT = '9999'
ENCODING = 'GB18030'
HISTSIZE = '500'
证明成功
8.在 交互模式中 再次查询表的数据(其中有中文)
psql => select * from test;
返回结果,没有错误信息出现,但是结果列表为乱码.
9.在 交互模式中 执行 \l 命令:
psql => \l
ERROR: invalid byte value for encoding "SQL_ASCII": 0xe5
10.退出 交互模式,编辑postgresql.conf
client_encoding = GB18030
保存文件,重新启动数据库。
直接用psql 命令
psql -p 9999 -U postuser -l
ERROR: invalid byte value for encoding "SQL_ASCII": 0xe5
错误与 9 相同
我原来的linux 是 redhat 9.0 数据库是 postgresql 7.1.4
locale 命令返回为:
LANG=zh_CN.GB18030
LC_CTYPE="zh_CN.GB18030"
LC_NUMERIC="zh_CN.GB18030"
LC_TIME="zh_CN.GB18030"
LC_COLLATE="zh_CN.GB18030"
LC_MONETARY="zh_CN.GB18030"
LC_MESSAGES="zh_CN.GB18030"
LC_PAPER="zh_CN.GB18030"
LC_NAME="zh_CN.GB18030"
LC_ADDRESS="zh_CN.GB18030"
LC_TELEPHONE="zh_CN.GB18030"
LC_MEASUREMENT="zh_CN.GB18030"
LC_IDENTIFICATION="zh_CN.GB18030"
LC_ALL=
我新装的linux 为 Red Hat Enterprise Linux 5,自带数据库是 postgresql 8.1.4
locale 命令返回为:
LANG=zh_CN.UTF-8
LC_CTYPE="zh_CN.UTF-8"
LC_NUMERIC="zh_CN.UTF-8"
LC_TIME="zh_CN.UTF-8"
LC_COLLATE="zh_CN.UTF-8"
LC_MONETARY="zh_CN.UTF-8"
LC_MESSAGES="zh_CN.UTF-8"
LC_PAPER="zh_CN.UTF-8"
LC_NAME="zh_CN.UTF-8"
LC_ADDRESS="zh_CN.UTF-8"
LC_TELEPHONE="zh_CN.UTF-8"
LC_MEASUREMENT="zh_CN.UTF-8"
LC_IDENTIFICATION="zh_CN.UTF-8"
LC_ALL=
我原来的系统的上的数据库没有任何问题,上面的执行的过程完全一样。
换了新系统和数据库就不行了。