概述
平时我在使用数据库时,一般都是使用命令行操作,PG是我使用最方便的数据库,可以自动补全命令,命令提示,敲出来的命令肯定不会错。
但是在新建的一个系统中发现不能使用该功能,很苦恼,找了一下原因。
问题描述
[postgres@erp-db01 ~]$ psql
psql (10.6)
Type "help" for help.
postgres=# \d
List of relations
Schema | Name | Type | Owner
--------+------------------+-------+----------
public | cs_sys_heartbeat | table | postgres
(1 row)
postgres=# \c cs das^[[A^[[D^[[C^[[B^C
postgres=#
postgres=# sele ^Hct^C
postgres=#
如上,补全,命令提示,和上下翻命令都是失败的
原因查找
查了一下原因,发现最初的原因,查看了一下数据库的基本信息
[postgres@erp-db01 ~]$ pg_config
BINDIR = /usr/pgsql-10/bin
DOCDIR = /usr/pgsql-10/share/doc
HTMLDIR = /usr/pgsql-10/share/doc
INCLUDEDIR = /usr/pgsql-10/include
PKGINCLUDEDIR = /usr/pgsql-10/include
INCLUDEDIR-SERVER = /usr/pgsql-10/include/server
LIBDIR = /usr/pgsql-10/lib
PKGLIBDIR = /usr/pgsql-10/lib
LOCALEDIR = /usr/pgsql-10/share/locale
MANDIR = /usr/pgsql-10/share/man
SHAREDIR = /usr/pgsql-10/share
SYSCONFDIR = /usr/pgsql-10/etc
PGXS = /usr/pgsql-10/lib/pgxs/src/makefiles/pgxs.mk
CONFIGURE = '--prefix=/usr/pgsql-10' '--with-perl' '--with-python' '--with-openssl' '--with-pam' '--with-ldap' '--with-libxml' '--with-libxslt' '--without-readline'
CC = gcc
CPPFLAGS = -D_GNU_SOURCE -I/usr/include/libxml2
CFLAGS = -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -O2
CFLAGS_SL = -fPIC
LDFLAGS = -Wl,--as-needed -Wl,-rpath,'/usr/pgsql-10/lib',--enable-new-dtags
LDFLAGS_EX =
LDFLAGS_SL =
LIBS = -lpgcommon -lpgport -lpthread -lxslt -lxml2 -lpam -lssl -lcrypto -lz -lrt -lcrypt -ldl -lm
VERSION = PostgreSQL 10.6
可以发现编译时使用了参数 —without-readline
我们在数据库的安装数据目录bin中可以查看到psql命令的依赖库情况,发现也是缺少readline的。这就是问题所在
[postgres@erp-db28 usr]$ ldd pgsql/bin/psql
linux-vdso.so.1 => (0x00007fffc011c000)
libpq.so.5 => /usr/pgsql/lib/libpq.so.5 (0x00007fb706579000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x00007fb70635d000)
librt.so.1 => /lib64/librt.so.1 (0x00007fb706155000)
libm.so.6 => /lib64/libm.so.6 (0x00007fb705e53000)
libc.so.6 => /lib64/libc.so.6 (0x00007fb705a86000)
libssl.so.10 => /lib64/libssl.so.10 (0x00007fb705814000)
libcrypto.so.10 => /lib64/libcrypto.so.10 (0x00007fb7053b3000)
libldap_r-2.4.so.2 => /lib64/libldap_r-2.4.so.2 (0x00007fb705154000)
/lib64/ld-linux-x86-64.so.2 (0x00007fb7067bf000)
libgssapi_krb5.so.2 => /lib64/libgssapi_krb5.so.2 (0x00007fb704f07000)
libkrb5.so.3 => /lib64/libkrb5.so.3 (0x00007fb704c1e000)
libcom_err.so.2 => /lib64/libcom_err.so.2 (0x00007fb704a1a000)
libk5crypto.so.3 => /lib64/libk5crypto.so.3 (0x00007fb7047e7000)
libdl.so.2 => /lib64/libdl.so.2 (0x00007fb7045e3000)
libz.so.1 => /lib64/libz.so.1 (0x00007fb7043cd000)
liblber-2.4.so.2 => /lib64/liblber-2.4.so.2 (0x00007fb7041be000)
libresolv.so.2 => /lib64/libresolv.so.2 (0x00007fb703fa5000)
libsasl2.so.3 => /lib64/libsasl2.so.3 (0x00007fb703d88000)
libssl3.so => /lib64/libssl3.so (0x00007fb703b36000)
libsmime3.so => /lib64/libsmime3.so (0x00007fb70390f000)
libnss3.so => /lib64/libnss3.so (0x00007fb7035e2000)
libnssutil3.so => /lib64/libnssutil3.so (0x00007fb7033b2000)
libplds4.so => /lib64/libplds4.so (0x00007fb7031ae000)
libplc4.so => /lib64/libplc4.so (0x00007fb702fa9000)
libnspr4.so => /lib64/libnspr4.so (0x00007fb702d6b000)
libkrb5support.so.0 => /lib64/libkrb5support.so.0 (0x00007fb702b5b000)
libkeyutils.so.1 => /lib64/libkeyutils.so.1 (0x00007fb702957000)
libcrypt.so.1 => /lib64/libcrypt.so.1 (0x00007fb702720000)
libselinux.so.1 => /lib64/libselinux.so.1 (0x00007fb7024f9000)
libfreebl3.so => /lib64/libfreebl3.so (0x00007fb7022f6000)
libpcre.so.1 => /lib64/libpcre.so.1 (0x00007fb702094000)
readline 是一个强大的库,只要使用了它的程序,都可以用同一个配置文件配置,而且用同样的方法操作命令行,让你可以方便的编辑命令行
发现同事在编译的时候,发现报readline这个错编译不过去,就直接使用without-readline 跳过了,导致了这个问题
问题解决
这个问题的解决方法最好的就是重新编译数据库了。替换掉原来的安装目录
如果插件安装的很多,替换安装目录很麻烦的换。可以直接将替换好的数据目录中的psql命令直接替换,因为psql是控制了readline的相关功能
首先需要把相关的依赖库安装
yum install readline
yum install readline-devel
在其他编译条件不变的情况下增加with-readline参数,编译安装
(在重新编译的时候,记得一定要将原来的编译环境make clean,不然会以原来的参数编译)
完成之后查看编译好的psql命令,可以发现是有readline了
[root@erp-db27 pgsql-10-text]# ldd bin/psql
linux-vdso.so.1 => (0x00007ffd87dd4000)
libpq.so.5 => /usr/pgsql-10-text/lib/libpq.so.5 (0x00007f05b3565000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f05b3349000)
libreadline.so.6 => /lib64/libreadline.so.6 (0x00007f05b3103000) <<<<<<<这里
librt.so.1 => /lib64/librt.so.1 (0x00007f05b2efb000)
libm.so.6 => /lib64/libm.so.6 (0x00007f05b2bf9000)
libc.so.6 => /lib64/libc.so.6 (0x00007f05b282c000)
libssl.so.10 => /lib64/libssl.so.10 (0x00007f05b25ba000)
libcrypto.so.10 => /lib64/libcrypto.so.10 (0x00007f05b2159000)
libldap_r-2.4.so.2 => /lib64/libldap_r-2.4.so.2 (0x00007f05b1efa000)
/lib64/ld-linux-x86-64.so.2 (0x00007f05b37ab000)
libtinfo.so.5 => /lib64/libtinfo.so.5 (0x00007f05b1cd0000)
libgssapi_krb5.so.2 => /lib64/libgssapi_krb5.so.2 (0x00007f05b1a83000)
libkrb5.so.3 => /lib64/libkrb5.so.3 (0x00007f05b179a000)
libcom_err.so.2 => /lib64/libcom_err.so.2 (0x00007f05b1596000)
libk5crypto.so.3 => /lib64/libk5crypto.so.3 (0x00007f05b1363000)
libdl.so.2 => /lib64/libdl.so.2 (0x00007f05b115f000)
libz.so.1 => /lib64/libz.so.1 (0x00007f05b0f49000)
liblber-2.4.so.2 => /lib64/liblber-2.4.so.2 (0x00007f05b0d3a000)
libresolv.so.2 => /lib64/libresolv.so.2 (0x00007f05b0b21000)
libsasl2.so.3 => /lib64/libsasl2.so.3 (0x00007f05b0904000)
libssl3.so => /lib64/libssl3.so (0x00007f05b06b2000)
libsmime3.so => /lib64/libsmime3.so (0x00007f05b048b000)
libnss3.so => /lib64/libnss3.so (0x00007f05b015e000)
libnssutil3.so => /lib64/libnssutil3.so (0x00007f05aff2e000)
libplds4.so => /lib64/libplds4.so (0x00007f05afd2a000)
libplc4.so => /lib64/libplc4.so (0x00007f05afb25000)
libnspr4.so => /lib64/libnspr4.so (0x00007f05af8e7000)
libkrb5support.so.0 => /lib64/libkrb5support.so.0 (0x00007f05af6d7000)
libkeyutils.so.1 => /lib64/libkeyutils.so.1 (0x00007f05af4d3000)
libcrypt.so.1 => /lib64/libcrypt.so.1 (0x00007f05af29c000)
libselinux.so.1 => /lib64/libselinux.so.1 (0x00007f05af075000)
libfreebl3.so => /lib64/libfreebl3.so (0x00007f05aee72000)
libpcre.so.1 => /lib64/libpcre.so.1 (0x00007f05aec10000)
将原来的psql命令替换掉
[root@erp-db28 pgsql]# mv psql bin/
mv: overwrite ‘bin/psql’? yes
此时发现数据库也可以正常使用各种快捷命令了
本站文章,未经作者同意,请勿转载,如需转载,请邮件customer@csudata.com.
0 评论
添加一条新评论