【问题标题】:Issue during connect to Data Base using psql command使用 psql 命令连接到数据库期间的问题
【发布时间】:2014-10-18 07:43:21
【问题描述】:

我使用的是 CentOS6.3 并安装了 PostgreSQL9.1 服务器。使用 psql 命令连接到 Postgres 服务器。

psql -h localhost -U postgres

这是我得到的结果。

postgres=# \c MYDB  
psql (8.4.11, server 9.1.7)  
WARNING: psql version 8.4, server version 9.1.  
         Some psql features might not work.  
You are now connected to database "MYDB".  
MYDB=#

谁能告诉我可能是什么原因。

更新

即使我卸载了 PostgreSQL9.1 服务器,仍然可以看到以下命令的结果。

`[root@testserver bin]# find / -name 'postgres'
/var/spool/mail/postgres
[root@testserver bin]# find / -name 'psql'
/usr/bin/psql
[root@testserver bin]# which psql
/usr/bin/psql
[root@testserver bin]# which postgres
/usr/bin/which: no postgres in (/usr/lib64/qt-    3.3/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/root/bin)
[root@testserver bin]# psql --version
psql (PostgreSQL) 8.4.11
contains support for command-line editing
[root@testserver bin]#`

这里我的意图是如果你执行 which psql 命令,如果没有安装服务器,它不应该显示任何输出。但是,我卸载了 Postgres 服务器并删除了 /opt/PostgreSQL 文件夹。

提前感谢。

【问题讨论】:

    标签: postgresql centos psql


    【解决方案1】:

    原因是您使用psql 8.4 版连接到9.1 数据库。

    大概PATH上默认的psql是旧版本吧。

    如果您使用 yum.postgresql.org 安装 9.1,您应该查看以下输出:

    update-alternatives --display pgsql-psql
    

    您很可能同时安装了 9.1 和 8.4,并且将旧版本设置为默认值。如果是,请运行:

    update-alternatives --auto pgsql-psql
    

    自动选择较新的版本,或者:

    update-alternatives --config pgsql-psql
    

    手动选择要运行的。

    如果您通过其他方式安装了 9.1,则需要使用完全显式的 /path/to/9.1/bin/psql(无论您的 9.1 安装是什么),或者将您的 PATH 更改为在系统默认值之前指向该 bin 目录那些。

    【讨论】:

    • 感谢您的回复 Craig,小家伙,CentOS 安装中是否有任何默认 psql 客户端。
    • which psqlrpm -qif psqlupdate-alternatives --display pgsql-psql 的输出是什么?您是如何使用什么存储库/包/安装程序从哪里安装 PostgreSQL 的?
    • 其中 psql=/usr/bin/psql,其余两个命令没有显示任何内容。作为其他应用程序的一部分,我也在无人值守模式下安装这个 postgres。postgresql-9.1.7- 1-linux-x64.run 是我用来安装 Postgres 的那个。
    • @Honey ...您从...下载了该安装程序?至于其他命令,那就试试ls -al /usr/bin/psql吧。无论如何,既然你已经安装了一些第 3 方包,你需要更新你的 PATH 以使用他们的 psql 或使用像 /opt/postgresql91/bin/psql 这样的显式路径或它安装到的任何位置。
    猜你喜欢
    • 2016-02-28
    • 2019-11-27
    • 2021-03-10
    • 2020-07-16
    • 1970-01-01
    • 2015-12-21
    • 2019-11-07
    • 2015-12-25
    • 1970-01-01
    相关资源
    最近更新 更多