psql和server版本不一致的问题

版权声明:本文为博主原创之文章,未经博主允许谢绝转载。 https://blog.csdn.net/pg_hgdb/article/details/81079457

问题

如果在Linux服务器上安装了多个版本的PostgreSQL,当你尝试登陆数据库时,可能会发现以下的WARNING:

postgres@hyl:~$ psql -h 127.0.0.1 test
psql (9.5.12, server 10.2)
WARNING: psql major version 9.5, server major version 10.
         Some psql features might not work.
Type "help" for help.


简单地说就是,你确实已经安装了10.2版本的数据库,但是psql脚本却是来自旧版本,本例中为9.5。如果不处理这个警告,对数据库进行操作时,有一些psql的特性会不能工作。

解决办法

首先,我们查看psql的路径,结果为:

postgres@hyl:~$ which psql
/usr/bin/psql

然后,我们需要移除原有的路径,然后创建符号链接,创建新的路径,确保新的版本链接到默认的路径集。(需要使用root用户进行操作)

root@hyl:~# mv /usr/bin/psql /usr/bin/psql-bk
root@hyl:~# ln -s  /usr/local/pgsql/bin/psql /usr/bin/psql


现在,再次尝试登陆数据库,可以看到psql的版本已经为新的版本,问题解决。

postgres@hyl:~$ psql -h 127.0.0.1 test
psql (10.2)
Type "help" for help.

By Kalath

猜你喜欢

转载自blog.csdn.net/pg_hgdb/article/details/81079457
今日推荐