概述

平时我在使用数据库时,一般都是使用命令行操作,PG是我使用最方便的数据库,可以自动补全命令,命令提示,敲出来的命令肯定不会错。
但是在新建的一个系统中发现不能使用该功能,很苦恼,找了一下原因。

问题描述

  1. [postgres@erp-db01 ~]$ psql
  2. psql (10.6)
  3. Type "help" for help.
  4. postgres=# \d
  5. List of relations
  6. Schema | Name | Type | Owner
  7. --------+------------------+-------+----------
  8. public | cs_sys_heartbeat | table | postgres
  9. (1 row)
  10. postgres=# \c cs das^[[A^[[D^[[C^[[B^C
  11. postgres=#
  12. postgres=# sele ^Hct^C
  13. postgres=#

如上,补全,命令提示,和上下翻命令都是失败的

原因查找

查了一下原因,发现最初的原因,查看了一下数据库的基本信息

  1. [postgres@erp-db01 ~]$ pg_config
  2. BINDIR = /usr/pgsql-10/bin
  3. DOCDIR = /usr/pgsql-10/share/doc
  4. HTMLDIR = /usr/pgsql-10/share/doc
  5. INCLUDEDIR = /usr/pgsql-10/include
  6. PKGINCLUDEDIR = /usr/pgsql-10/include
  7. INCLUDEDIR-SERVER = /usr/pgsql-10/include/server
  8. LIBDIR = /usr/pgsql-10/lib
  9. PKGLIBDIR = /usr/pgsql-10/lib
  10. LOCALEDIR = /usr/pgsql-10/share/locale
  11. MANDIR = /usr/pgsql-10/share/man
  12. SHAREDIR = /usr/pgsql-10/share
  13. SYSCONFDIR = /usr/pgsql-10/etc
  14. PGXS = /usr/pgsql-10/lib/pgxs/src/makefiles/pgxs.mk
  15. CONFIGURE = '--prefix=/usr/pgsql-10' '--with-perl' '--with-python' '--with-openssl' '--with-pam' '--with-ldap' '--with-libxml' '--with-libxslt' '--without-readline'
  16. CC = gcc
  17. CPPFLAGS = -D_GNU_SOURCE -I/usr/include/libxml2
  18. CFLAGS = -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -O2
  19. CFLAGS_SL = -fPIC
  20. LDFLAGS = -Wl,--as-needed -Wl,-rpath,'/usr/pgsql-10/lib',--enable-new-dtags
  21. LDFLAGS_EX =
  22. LDFLAGS_SL =
  23. LIBS = -lpgcommon -lpgport -lpthread -lxslt -lxml2 -lpam -lssl -lcrypto -lz -lrt -lcrypt -ldl -lm
  24. VERSION = PostgreSQL 10.6

可以发现编译时使用了参数 —without-readline

我们在数据库的安装数据目录bin中可以查看到psql命令的依赖库情况,发现也是缺少readline的。这就是问题所在

  1. [postgres@erp-db28 usr]$ ldd pgsql/bin/psql
  2. linux-vdso.so.1 => (0x00007fffc011c000)
  3. libpq.so.5 => /usr/pgsql/lib/libpq.so.5 (0x00007fb706579000)
  4. libpthread.so.0 => /lib64/libpthread.so.0 (0x00007fb70635d000)
  5. librt.so.1 => /lib64/librt.so.1 (0x00007fb706155000)
  6. libm.so.6 => /lib64/libm.so.6 (0x00007fb705e53000)
  7. libc.so.6 => /lib64/libc.so.6 (0x00007fb705a86000)
  8. libssl.so.10 => /lib64/libssl.so.10 (0x00007fb705814000)
  9. libcrypto.so.10 => /lib64/libcrypto.so.10 (0x00007fb7053b3000)
  10. libldap_r-2.4.so.2 => /lib64/libldap_r-2.4.so.2 (0x00007fb705154000)
  11. /lib64/ld-linux-x86-64.so.2 (0x00007fb7067bf000)
  12. libgssapi_krb5.so.2 => /lib64/libgssapi_krb5.so.2 (0x00007fb704f07000)
  13. libkrb5.so.3 => /lib64/libkrb5.so.3 (0x00007fb704c1e000)
  14. libcom_err.so.2 => /lib64/libcom_err.so.2 (0x00007fb704a1a000)
  15. libk5crypto.so.3 => /lib64/libk5crypto.so.3 (0x00007fb7047e7000)
  16. libdl.so.2 => /lib64/libdl.so.2 (0x00007fb7045e3000)
  17. libz.so.1 => /lib64/libz.so.1 (0x00007fb7043cd000)
  18. liblber-2.4.so.2 => /lib64/liblber-2.4.so.2 (0x00007fb7041be000)
  19. libresolv.so.2 => /lib64/libresolv.so.2 (0x00007fb703fa5000)
  20. libsasl2.so.3 => /lib64/libsasl2.so.3 (0x00007fb703d88000)
  21. libssl3.so => /lib64/libssl3.so (0x00007fb703b36000)
  22. libsmime3.so => /lib64/libsmime3.so (0x00007fb70390f000)
  23. libnss3.so => /lib64/libnss3.so (0x00007fb7035e2000)
  24. libnssutil3.so => /lib64/libnssutil3.so (0x00007fb7033b2000)
  25. libplds4.so => /lib64/libplds4.so (0x00007fb7031ae000)
  26. libplc4.so => /lib64/libplc4.so (0x00007fb702fa9000)
  27. libnspr4.so => /lib64/libnspr4.so (0x00007fb702d6b000)
  28. libkrb5support.so.0 => /lib64/libkrb5support.so.0 (0x00007fb702b5b000)
  29. libkeyutils.so.1 => /lib64/libkeyutils.so.1 (0x00007fb702957000)
  30. libcrypt.so.1 => /lib64/libcrypt.so.1 (0x00007fb702720000)
  31. libselinux.so.1 => /lib64/libselinux.so.1 (0x00007fb7024f9000)
  32. libfreebl3.so => /lib64/libfreebl3.so (0x00007fb7022f6000)
  33. libpcre.so.1 => /lib64/libpcre.so.1 (0x00007fb702094000)

readline 是一个强大的库,只要使用了它的程序,都可以用同一个配置文件配置,而且用同样的方法操作命令行,让你可以方便的编辑命令行

发现同事在编译的时候,发现报readline这个错编译不过去,就直接使用without-readline 跳过了,导致了这个问题

问题解决

这个问题的解决方法最好的就是重新编译数据库了。替换掉原来的安装目录

如果插件安装的很多,替换安装目录很麻烦的换。可以直接将替换好的数据目录中的psql命令直接替换,因为psql是控制了readline的相关功能

首先需要把相关的依赖库安装

  1. yum install readline
  2. yum install readline-devel

在其他编译条件不变的情况下增加with-readline参数,编译安装

(在重新编译的时候,记得一定要将原来的编译环境make clean,不然会以原来的参数编译)
完成之后查看编译好的psql命令,可以发现是有readline了

  1. [root@erp-db27 pgsql-10-text]# ldd bin/psql
  2. linux-vdso.so.1 => (0x00007ffd87dd4000)
  3. libpq.so.5 => /usr/pgsql-10-text/lib/libpq.so.5 (0x00007f05b3565000)
  4. libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f05b3349000)
  5. libreadline.so.6 => /lib64/libreadline.so.6 (0x00007f05b3103000) <<<<<<<这里
  6. librt.so.1 => /lib64/librt.so.1 (0x00007f05b2efb000)
  7. libm.so.6 => /lib64/libm.so.6 (0x00007f05b2bf9000)
  8. libc.so.6 => /lib64/libc.so.6 (0x00007f05b282c000)
  9. libssl.so.10 => /lib64/libssl.so.10 (0x00007f05b25ba000)
  10. libcrypto.so.10 => /lib64/libcrypto.so.10 (0x00007f05b2159000)
  11. libldap_r-2.4.so.2 => /lib64/libldap_r-2.4.so.2 (0x00007f05b1efa000)
  12. /lib64/ld-linux-x86-64.so.2 (0x00007f05b37ab000)
  13. libtinfo.so.5 => /lib64/libtinfo.so.5 (0x00007f05b1cd0000)
  14. libgssapi_krb5.so.2 => /lib64/libgssapi_krb5.so.2 (0x00007f05b1a83000)
  15. libkrb5.so.3 => /lib64/libkrb5.so.3 (0x00007f05b179a000)
  16. libcom_err.so.2 => /lib64/libcom_err.so.2 (0x00007f05b1596000)
  17. libk5crypto.so.3 => /lib64/libk5crypto.so.3 (0x00007f05b1363000)
  18. libdl.so.2 => /lib64/libdl.so.2 (0x00007f05b115f000)
  19. libz.so.1 => /lib64/libz.so.1 (0x00007f05b0f49000)
  20. liblber-2.4.so.2 => /lib64/liblber-2.4.so.2 (0x00007f05b0d3a000)
  21. libresolv.so.2 => /lib64/libresolv.so.2 (0x00007f05b0b21000)
  22. libsasl2.so.3 => /lib64/libsasl2.so.3 (0x00007f05b0904000)
  23. libssl3.so => /lib64/libssl3.so (0x00007f05b06b2000)
  24. libsmime3.so => /lib64/libsmime3.so (0x00007f05b048b000)
  25. libnss3.so => /lib64/libnss3.so (0x00007f05b015e000)
  26. libnssutil3.so => /lib64/libnssutil3.so (0x00007f05aff2e000)
  27. libplds4.so => /lib64/libplds4.so (0x00007f05afd2a000)
  28. libplc4.so => /lib64/libplc4.so (0x00007f05afb25000)
  29. libnspr4.so => /lib64/libnspr4.so (0x00007f05af8e7000)
  30. libkrb5support.so.0 => /lib64/libkrb5support.so.0 (0x00007f05af6d7000)
  31. libkeyutils.so.1 => /lib64/libkeyutils.so.1 (0x00007f05af4d3000)
  32. libcrypt.so.1 => /lib64/libcrypt.so.1 (0x00007f05af29c000)
  33. libselinux.so.1 => /lib64/libselinux.so.1 (0x00007f05af075000)
  34. libfreebl3.so => /lib64/libfreebl3.so (0x00007f05aee72000)
  35. libpcre.so.1 => /lib64/libpcre.so.1 (0x00007f05aec10000)

将原来的psql命令替换掉

  1. [root@erp-db28 pgsql]# mv psql bin/
  2. mv: overwrite bin/psql’? yes

此时发现数据库也可以正常使用各种快捷命令了

0 评论  
添加一条新评论