数据库服务器编码
指数据库服务器能够从客户端接收、存储以及向客户端提供该种编码的字符,并能将该种编码的字符转换到其它编码
查看PostgreSQL数据库服务器端编码:
postgres=# show server_encoding;
postgres=# \l
数据库客户端编码
客户端工具支持某种编码,必须能够显示从数据库读取的该种编码的字符,也能通过本工具将该种编码的字符提交到给服务器端。
查看PostgreSQL客户端工具psql编码
postgres=# show client_encoding;
postgres=# \encoding
指定Postgresql会话的客户端编码:
postgres=# set client_encoding to 'utf8';
乱码问题:
C/S间编码不一致时服务端自动进行字符编码转换
遵从一个原则:本地环境的编码和客户端编码需一致
客户端通过client_encoding通知服务端自己的编码
设置client_encoding到的几种方式(越往下优先级越高)
postgresql.conf
连接包(StartupMessage)的参数
set client_encoding to ‘XXX

集群服务(postgresql.conf)

数据库(pg_database)

postgres=# show server_encoding;
server_encoding
-----------------
UTF8
(1 row)
postgres=# show client_encoding;
client_encoding
-----------------
UTF8
(1 row)
postgres=# insert into star values(1,'梅西');
INSERT 0 1
postgres=# \encoding GBK
postgres=# show client_encoding;
client_encoding
-----------------
GBK
(1 row)
postgres=# insert into star values(1,'哈维');
INSERT 0 1
postgres=# select * from star;
no | star_name
----+-----------
1 | ÷ 1 | 哈维
(2 rows)
postgres=# show server_encoding;
server_encoding
-----------------
UTF8
(1 row)
postgres=# select * from star;
no | star_name
----+-----------
1 | ÷ 1 | 哈维
(2 rows)
postgres=# reset client_encoding;
RESET
postgres=# show client_encoding;
client_encoding
-----------------
UTF8
(1 row)
postgres=# select * from star;
no | star_name
----+-----------
1 | 梅西
1 | 鍝堢淮
(2 rows)
postgres=#
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。




