Postgresql 9.2 pg_dump 版本不匹配

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12836312/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 23:46:48  来源:igfitidea点击:

Postgresql 9.2 pg_dump version mismatch

postgresqlbackuppg-dumppostgresql-9.2

提问by Chris Colla

I am trying to dump a Postgresql database using the pg_dumptool.

我正在尝试使用pg_dump工具转储 Postgresql 数据库。

$ pg_dump books > books.out

How ever i am getting this error.

我怎么会收到这个错误。

pg_dump: server version: 9.2.1; pg_dump version: 9.1.6
pg_dump: aborting because of server version mismatch

The --ignore-versionoption is now deprecated and really would not be a a solution to my issue even if it had worked.

--ignore-version选项现已弃用,即使它有效,也不会真正解决我的问题。

How can I upgrade pg_dumpto resolve this issue?

如何升级pg_dump以解决此问题?

采纳答案by francs

You can either install PostgreSQL 9.2.1 in the pg_dumpclient machine or just copy the $PGHOMEfrom the PostgreSQL server machine to the client machine. Note that there is no need to initdba new cluster in the client machine.

您可以在pg_dump客户端机器上安装 PostgreSQL 9.2.1,也可以将 PostgreSQL$PGHOME服务器机器上的 PostgreSQL复制到客户端机器上。请注意,initdb客户端机器中不需要新集群。

After you have finished installing the 9.2.1 software, remember to edit some environment variables in your .bash_profilefile.

安装完 9.2.1 软件后,记得编辑.bash_profile文件中的一些环境变量。

回答by Seth

I encountered this while using Heroku on Ubuntu, and here's how I fixed it:

我在 Ubuntu 上使用 Heroku 时遇到了这个问题,这是我修复它的方法:

  1. Add the PostgreSQL apt repository as described at "Linux downloads (Ubuntu) ". (There are similar pages for other operating systems.)

  2. Upgrade to the latest version (9.3 for me) with:

    sudo apt-get install postgresql
    
  3. Recreate the symbolic link in /usr/binwith:

    sudo ln -s /usr/lib/postgresql/9.3/bin/pg_dump /usr/bin/pg_dump --force
    

    The version number in the /usr/lib/postgresql/...path above should match the server versionnumber in the error you received. So if your error says, pg_dump: server version: 9.9, then link to /usr/lib/postgresql/9.9/....

  1. 添加 PostgreSQL apt 存储库,如“ Linux 下载 (Ubuntu) ”中所述。(其他操作系统也有类似的页面。)

  2. 升级到最新版本(对我来说是 9.3):

    sudo apt-get install postgresql
    
  3. 重新创建符号链接/usr/bin

    sudo ln -s /usr/lib/postgresql/9.3/bin/pg_dump /usr/bin/pg_dump --force
    

    /usr/lib/postgresql/...上面路径中的版本号应与server version您收到的错误中的版本号相匹配。因此,如果您的错误显示为pg_dump: server version: 9.9,则链接到/usr/lib/postgresql/9.9/...

回答by Omer Aslam

  1. Check the installed version(s) of pg_dump:

    find / -name pg_dump -type f 2>/dev/null
    
  2. My output was:

    /usr/pgsql-9.3/bin/pg_dump
    /usr/bin/pg_dump
    
  3. There are two versions installed. To update pg_dump with the newer version:

    sudo ln -s /usr/pgsql-9.3/bin/pg_dump /usr/bin/pg_dump --force
    
  1. 检查 pg_dump 的已安装版本:

    find / -name pg_dump -type f 2>/dev/null
    
  2. 我的输出是:

    /usr/pgsql-9.3/bin/pg_dump
    /usr/bin/pg_dump
    
  3. 安装了两个版本。要使用较新的版本更新 pg_dump:

    sudo ln -s /usr/pgsql-9.3/bin/pg_dump /usr/bin/pg_dump --force
    

This will create the symlink to the newer version.

这将创建到较新版本的符号链接。

回答by user2148301

Macs have a builtin /usr/bin/pg_dumpcommand that is used as default.

Mac 有一个/usr/bin/pg_dump默认使用的内置命令。

With the postgresql install you get another binary at /Library/PostgreSQL/<version>/bin/pg_dump

安装 postgresql 后,您将获得另一个二进制文件 /Library/PostgreSQL/<version>/bin/pg_dump

回答by Deepak Mahakale

You can just locate pg_dumpand use the full path in command

您可以pg_dump在命令中找到并使用完整路径

locate pg_dump

/usr/bin/pg_dump
/usr/bin/pg_dumpall
/usr/lib/postgresql/9.3/bin/pg_dump
/usr/lib/postgresql/9.3/bin/pg_dumpall
/usr/lib/postgresql/9.6/bin/pg_dump
/usr/lib/postgresql/9.6/bin/pg_dumpall

Now just use the path of the desired version in the command

现在只需在命令中使用所需版本的路径

/usr/lib/postgresql/9.6/bin/pg_dump books > books.out

回答by Abe Voelker

If you're on Ubuntu, you might have an old version of postgresql-clientinstalled. Based on the versions in your error message, the solution would be the following:

如果您使用的是 Ubuntu,则可能安装了旧版本postgresql-client。根据错误消息中的版本,解决方案如下:

sudo apt-get remove postgresql-client-9.1
sudo apt-get install postgresql-client-9.2

回答by solaimuruganv

Every time you upgrade or re install a new version of PostgreSQL, a latest version of pg_dump is installed.

每次升级或重新安装新版本的 PostgreSQL 时,pg_dump 都会安装最新版本。

There must be a PostgreSQL/bin directory somewhere on your system, under the latest version of PostgreSQL that you've installed ( 9.2.1 is latest) and try running the pg_dump from in there.

PostgreSQL/bin 您的系统上必须有一个目录,在您安装的最新版本的 PostgreSQL 下(9.2.1 是最新版本),然后尝试pg_dump 从那里运行 。

回答by Andreas

For those running Postgres.app:

对于那些运行Postgres.app 的人

  1. Add the following code to your .bash_profile:

    export PATH=/Applications/Postgres.app/Contents/Versions/latest/bin:$PATH
    
  2. Restart terminal.

  1. 将以下代码添加到您的.bash_profile

    export PATH=/Applications/Postgres.app/Contents/Versions/latest/bin:$PATH
    
  2. 重启终端。

回答by hcarreras

For Macs with Homebrew. I had this problem when fetching the db from Heroku. I've fixed it just running:

对于带有 Homebrew 的 Mac。从 Heroku 获取数据库时我遇到了这个问题。我已经修复它只是运行:

brew upgrade postgresql

回答by Andrey Yasinishyn

For mac users put to the top of .profile file.

对于 mac 用户,放在 .profile 文件的顶部。

export PATH="/Applications/Postgres.app/Contents/MacOS/bin:$PATH"

then run

然后运行

. ~/.profile