解决linux下客户端软件不能输入中文问题
最近安装一套Greenplum集群,安装后使用psql命令创建表插入中文时一直不能输入,最终定位到问题原因是因为libedit.so.0版本原因,下面介绍下排查方式及解决方法
定位问题原因
- 首先客户端不能输入中文则验证在linux系统层是否可以输入中文, 验证可以
- 怀疑是客户端自身原因则使用不同版本客户端测试,发现高版本的客户端则可以输入中文
- 说明原因是在客户端上,查看两个客户端的client encoding也全都是UTF8
- 通过ldd 查看两个命令引用的动态库两个客户端处理字符输入引用的动态库是不一样的,分别使用了/lib64/libreadline.so.6, libedit.so.0 我们在查看libedit.so.0的版本
1
2
3
4
5
6
7
8
9
10
11
12
13//高版本psql客户端
[gpadmin@mdw ~]$ ldd /usr/bin/psql
linux-vdso.so.1 => (0x00007fff64df2000)
libpq.so.5 => /usr/local/greenplum/greenplum-db/./lib/libpq.so.5 (0x00007f0ea263f000)
libssl.so.10 => /usr/lib64/libssl.so.10 (0x000000393f200000)
libreadline.so.6 => /lib64/libreadline.so.6 (0x0000003937600000)
//低版本客户端
[gpadmin@mdw ~]$ ldd /usr/local/greenplum/greenplum-db/bin/psql
linux-vdso.so.1 => (0x00007fff89b49000)
libpq.so.5 => /usr/local/greenplum/greenplum-db/./lib/libpq.so.5 (0x00007fcbaca2b000)
libssl.so.0.9.8 => /usr/local/greenplum/greenplum-db/./lib/libssl.so.0.9.8 (0x00007fcbac7db000)
libedit.so.0 => /usr/local/greenplum/greenplum-db/./lib/libedit.so.0 (0x00007fcbac5a5000)1
2
3cd /usr/local/greenplum/greenplum-db/lib
ls -ltr libedit.so.0
发现libedit.so.0 是libedit.so.0.0.29的一个软连接, 怀疑是版本问题
升级libedit版本
http://distfiles.macports.org/libedit/ 下载 libedit-20170329-3.1.tar.gz
上传到服务器上编译安装
1
2
3tar -zxvf libedit-20170329-3.1.tar.gz
./configure
make && make install将原有的软连接unlink,并创建新连接
1
2unlink /usr/local/greenplum/greenplum-db/./lib/libedit.so.0
ln -s /usr/local/lib/libedit.so.0.0.56 /usr/local/greenplum/greenplum-db/./lib/libedit.so.0再次登录psql客户端发现客户输入中文了
1
2
3
4
5
6
7
8
9
10
11postgres=# create table dhytest (id int, name char(20));
NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'id' as the Greenplum Database data distribution key for this table.
HINT: The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew.
CREATE TABLE
postgres=# insert into dhytest values(10, '董红禹');
INSERT 0 1
postgres=# select * from dhytest;
id | name
----+-------------------------
10 | 董红禹
(1 row)
问题延伸
在安装Greenplum时,会加载相应环境变量Greenplum手册中提供了相应的脚本,一般会添加到gpadmin的.bash_profile中
1 | source /usr/local/greenplum/greenplum-db/greenplum_path.sh |
加载此环境变量后使用的一些动态库会指向Greenplum安装目录下的lib目录中,这样也会导致在root用户下和gpadmin用户下执行posql引用不同动态库会出现不同结果,这点需要大家注意。