[英]Postgresql 9.2 pg_dump version mismatch
I am trying to dump a Postgresql database using the pg_dump tool.我正在尝试使用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-version
option is now deprecated and really would not be aa solution to my issue even if it had worked. --ignore-version
选项现在已弃用,即使它有效,也不会真正成为我的问题的解决方案。
How can I upgrade pg_dump to resolve this issue?我如何升级pg_dump来解决这个问题?
Check the installed version(s) of pg_dump:检查 pg_dump 的安装版本:
find / -name pg_dump -type f 2>/dev/null
My output was:我的输出是:
/usr/pgsql-9.3/bin/pg_dump /usr/bin/pg_dump
There are two versions installed.安装了两个版本。 To update pg_dump with the newer version:
要使用较新版本更新 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.这将创建指向较新版本的符号链接。
I encountered this while using Heroku on Ubuntu, and here's how I fixed it:我在 Ubuntu 上使用 Heroku 时遇到了这个问题,下面是我修复它的方法:
Add the PostgreSQL apt repository as described at " Linux downloads (Ubuntu) ".按照“ Linux 下载 (Ubuntu) ”中的说明添加 PostgreSQL apt 存储库。 (There are similar pages for other operating systems.)
(其他操作系统也有类似的页面。)
Upgrade to the latest version (9.3 for me) with:使用以下命令升级到最新版本(对我来说是 9.3):
sudo apt-get install postgresql
Recreate the symbolic link in /usr/bin
with:使用以下命令在
/usr/bin
中重新创建符号链接:
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 version
number in the error you received.上面
/usr/lib/postgresql/...
路径中的版本号应该与您收到的错误中的server version
号相匹配。 So if your error says, pg_dump: server version: 9.9
, then link to /usr/lib/postgresql/9.9/...
.因此,如果您的错误显示
pg_dump: server version: 9.9
,则链接到/usr/lib/postgresql/9.9/...
。
Macs have a builtin /usr/bin/pg_dump
command 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
获得另一个二进制文件
You can just locate pg_dump
and 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
You can either install PostgreSQL 9.2.1 in the pg_dump
client machine or just copy the $PGHOME
from the PostgreSQL server machine to the client machine.您可以在
pg_dump
客户端机器上安装 PostgreSQL 9.2.1,或者只是将$PGHOME
从 PostgreSQL 服务器机器复制到客户端机器。 Note that there is no need to initdb
a new cluster in the client machine.请注意,无需在客户端计算机中
initdb
新集群。
After you have finished installing the 9.2.1 software, remember to edit some environment variables in your .bash_profile
file.完成 9.2.1 软件安装后,记得编辑
.bash_profile
文件中的一些环境变量。
If you're on Ubuntu, you might have an old version of postgresql-client
installed.如果您使用的是 Ubuntu,则可能安装了旧版本的
postgresql-client
。 Based on the versions in your error message, the solution would be the following:根据错误消息中的版本,解决方案如下:
sudo apt-get remove postgresql-client-9.1
sudo apt-get install postgresql-client-9.2
If you have docker installed you can do something like:如果您安装了 docker,您可以执行以下操作:
$ docker run postgres:9.2 pg_dump books > books.out
That will download the Docker container with Postgres 9.2 in it, run pg_dump
inside of the container, and write the output.这将下载带有 Postgres 9.2 的 Docker 容器,在容器内运行
pg_dump
,并写入输出。
On Ubuntu you can simply add the most recent Apt repository and then run:在 Ubuntu 上,您可以简单地添加最新的 Apt 存储库,然后运行:
sudo apt-get install postgresql-client-11
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
。
For those running Postgres.app :对于那些运行Postgres.app的人:
Add the following code to your .bash_profile
:将以下代码添加到您的
.bash_profile
:
export PATH=/Applications/Postgres.app/Contents/Versions/latest/bin:$PATH
Restart terminal.重启终端。
For Macs with Homebrew.对于装有 Homebrew 的 Mac。 I had this problem when fetching the db from Heroku.
从 Heroku 获取数据库时我遇到了这个问题。 I've fixed it just running:
我已经修复它只是运行:
brew upgrade postgresql
For mac users put to the top of.profile file.对于 mac 用户放在 .profile 文件的顶部。
export PATH="/Applications/Postgres.app/Contents/MacOS/bin:$PATH"
then run然后运行
. ~/.profile
An alternative answer that I don't think anyone else has covered.我认为其他任何人都没有涵盖的替代答案。
If you have multiple PG clusters installed (as I do), then you can view those using pg_lsclusters
.如果你安装了多个 PG 集群(就像我一样),那么你可以使用
pg_lsclusters
查看它们。
You should be able to see the version and cluster from the list displayed.您应该能够从显示的列表中看到版本和集群。
From there, you can then do this:从那里,您可以执行以下操作:
pg_dump --cluster=9.6/main books > books.out
Obviously, replace the version and cluster name with the appropriate one for your circumstances from what is returned by pg_lsclusters
separating the version and cluster with a /.显然,从
pg_lsclusters
返回的内容中,用适合您情况的版本和集群名称替换版本和集群名称,用 / 分隔版本和集群。 This targets the specific cluster you wish to run against.这针对您希望运行的特定集群。
For me the issue was updating psql
apt-get
wasn't resolving newer versions, even after update
.对我来说,问题是更新
psql
apt-get
没有解决更新的版本,即使在update
之后也是如此。 The following worked.以下工作。
Ubuntu Ubuntu
Start with the import of the GPG key for PostgreSQL packages.从为 PostgreSQL 包导入 GPG 密钥开始。
sudo apt-get install wget ca-certificates
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
Now add the repository to your system.现在将存储库添加到您的系统。
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ `lsb_release -cs`-pgdg main" >> /etc/apt/sources.list.d/pgdg.list'
Install PostgreSQL on Ubuntu在 Ubuntu 上安装 PostgreSQL
sudo apt-get update
sudo apt-get install postgresql postgresql-contrib
https://www.postgresql.org/download/linux/ubuntu/ https://www.postgresql.org/download/linux/ubuntu/
As explained, this is because your postgresql is in old version -> update it For Mac via homebrew:正如所解释的,这是因为你的 postgresql 是旧版本 - >通过自制软件更新它对于 Mac:
brew tap petere/postgresql
, brew tap petere/postgresql
,
brew install <formula>
(eg: brew install petere/postgresql/postgresql-9.6
) brew install <formula>
(例如: brew install petere/postgresql/postgresql-9.6
)
Remove old postgre:删除旧的 postgre:
brew unlink postgresql
brew link -f postgresql-9.6
If any error happen, don't forget to read and follow brew instruction in each step.如果发生任何错误,请不要忘记阅读并遵循每个步骤中的 brew 说明。
Check this out for more: https://github.com/petere/homebrew-postgresql查看更多: https ://github.com/petere/homebrew-postgresql
The answer sounds silly but if you get the above error and wanna run the pg_dump for earlier version go to bin directory of postgres and type答案听起来很傻但是如果你得到上面的错误并且想运行早期版本的 pg_dump 去 postgres 的 bin 目录并输入
./pg_dump servername > out.sql./ ignores the root and looks for pg_dump in current directory ./pg_dump servername > out.sql./ 忽略根并在当前目录中查找 pg_dump
I had same error and this is how I solved it in my case.我有同样的错误,这就是我在我的案例中解决它的方法。 This means your postgresql version is 9.2.1 but you have started postgresql service of 9.1.6.
这意味着你的postgresql版本是9.2.1,但是你启动了9.1.6的postgresql服务。
If you run psql postgres
you will see:如果你运行
psql postgres
你会看到:
psql (9.2.1, server 9.1.6)
What I did to solve this problem is:我为解决这个问题所做的是:
brew services stop postgresql@9.1.6
brew services restart postgresql@9.2.1
Now run psql postgres
and you should have: psql (9.2.1)
现在运行
psql postgres
,你应该有: psql (9.2.1)
You can also run brew services list
to see the status of your postgres.您还可以运行
brew services list
来查看您的 postgres 的状态。
This worked for me, a collection of solutions from above and other sites.这对我有用,是来自上面和其他站点的解决方案的集合。 If you specified a version like postgressql-client-11 before then you need to remove that version first.
如果您之前指定了类似 postgressql-client-11 的版本,那么您需要先删除该版本。
sudo apt-get remove -y postgresql-client
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ `lsb_release -cs`-pgdg main" >> /etc/apt/sources.list.d/pgdg.list'
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
sudo apt-get update
sudo apt-get install -y postgresql-client-12
I was facing the same issue.我遇到了同样的问题。 I used docker instead of upgrading pg_dump.
我使用 docker 而不是升级 pg_dump。
run following command to create a Docker container of postgres 14.2, or any other version as you like.运行以下命令以创建 postgres 14.2 或您喜欢的任何其他版本的 Docker 容器。
sudo docker run --name mac_postgres -p 5444:5432 -e POSTGRES_PASSWORD=password -d postgres:14.2
Then take dump using following command.然后使用以下命令进行转储。 Note: you should change the host , port , username and password according to your actual database credentials.
注意:您应该根据您的实际数据库凭据更改host 、 port 、 username和password 。
sudo docker exec -it mac_postgres pg_dump --host=xxxxx0.b.db.ondigitalocean.com --port=250xx --username=doadmin --dbname=test --password > out.sql
After entering password.输入密码后。 Your dump will be ready in out.sql file.
您的转储将在out.sql文件中准备就绪。 Then you can delete the docker-container.
然后你可以删除docker-container。
sudo docker stop mac_postgres
sudo docker rm mac_postgres
If you're using Heroku's Postgres.app the pg_dump (along with all the other binaries) is in /Applications/Postgres.app/Contents/MacOS/bin/
如果您使用的是 Heroku 的 Postgres.app,则 pg_dump(以及所有其他二进制文件)位于
/Applications/Postgres.app/Contents/MacOS/bin/
so in that case it's所以在那种情况下
ln -s /Applications/Postgres.app/Contents/MacOS/bin/pg_dump /usr/local/bin/pg_dump
or要么
ln -s /Applications/Postgres.app/Contents/MacOS/bin/* /usr/local/bin/.
to just grab them all抓住他们
** after install postgres version is match(9.2) Create a symbolic link or new shortcut ** 安装 postgres 版本后匹配 (9.2) 创建符号链接或新快捷方式
**- on '/usr/bin' **- 在“/usr/bin”上
syntag is = sudo ln -s [path for use] [new shortcut name]
example例子
sudo ln -s /usr/lib/postgresql/9.2/bin/pg_dump new_pg_dump
-- how to call: new_pg_dump -h 192.168.9.88 -U postgres database -- 调用方式:new_pg_dump -h 192.168.9.88 -U postgres database
Try that:试试看:
export PATH=/usr/local/bin:$PATH
If the database is installed on a different machine it has probably correct version of pg_dump installed.如果数据库安装在不同的机器上,它可能安装了正确版本的 pg_dump。 This means that you can execute pg_dump command remotely with SSH:
ssh username@dbserver pg_dump books > books.out
这意味着您可以使用 SSH 远程执行 pg_dump 命令:
ssh username@dbserver pg_dump books > books.out
You can also use public key authentication for passwordless execution.您还可以使用公钥身份验证进行无密码执行。 Steps to achieve that:
实现这一目标的步骤:
Well, I had the same issue as I have two postgress versions installed.好吧,我遇到了同样的问题,因为我安装了两个 postgress 版本。
Just use the proper pg_dump and you don't need to change anything, in your case:只需使用正确的 pg_dump 并且你不需要改变任何东西,在你的情况下:
$> /usr/lib/postgresql/9.2/bin/pg_dump books > books.out
For macs, use find / -name pg_dump -type f 2>/dev/null
find the location of pg_dump对于 macs,使用
find / -name pg_dump -type f 2>/dev/null
找到 pg_dump 的位置
For me, I have following results:对我来说,我有以下结果:
Applications/Postgres.app/Contents/Versions/9.5/bin/pg_dump
/usr/local/Cellar/postgresql/9.4.5_2/bin/pg_dump
If you don't want to use sudo ln -s new_pg_dump old_pg_dump --force
, just use:如果您不想使用
sudo ln -s new_pg_dump old_pg_dump --force
,只需使用:
Applications/Postgres.app/Contents/Versions/9.5/bin/pg_dump
to replace with pg_dump
in your terminal Applications/Postgres.app/Contents/Versions/9.5/bin/pg_dump
替换为终端中的pg_dump
For example:例如:
Applications/Postgres.app/Contents/Versions/9.5/bin/pg_dump books > books.out
It works for me!这个对我有用!
I am trying to dump a Postgresql database using the pg_dump tool.我正在尝试使用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-version
option is now deprecated and really would not be aa solution to my issue even if it had worked. --ignore-version
选项现在已弃用,即使它有效,也不会真正解决我的问题。
How can I upgrade pg_dump to resolve this issue?如何升级pg_dump以解决此问题?
First step: see if postgres has a repository with prebuilt binaries for the version you want for your OS: https://www.postgresql.org/download/第一步:查看 postgres 是否有一个存储库,其中包含您想要的操作系统版本的预构建二进制文件: https ://www.postgresql.org/download/
If that doesn't work (for instance if your distro is there but is no longer supported, so correct binaries aren't provided for it), or if you just want to go straight or the source and not have to worry about adding remote repo's, etc.如果这不起作用(例如,如果您的发行版在那里但不再受支持,则不会为它提供正确的二进制文件),或者如果您只想直接使用源代码而不必担心添加远程回购等
What I did is download the raw source of postgres for the desired version.我所做的是下载所需版本的原始 postgres 源代码。
Untar it, cd into it, build it ./configure && make
, then:解压它,进入它,构建它
./configure && make
,然后:
postgresql-12.3 $ find . -name pg_dump
./src/bin/pg_dump/pg_dump
$ ./src/bin/pg_dump/pg_dump
unable to load libpg.so.5 # if it says this...
$ find . -name libpg.so.5
$ export LD_LIBRARY_PATH=/your/path/to/the/shared/dir/of/above/file
$ ./src/bin/pg_dump/pg_dump # works now
Now you have access to any version that builds on your box.现在您可以访问在您的盒子上构建的任何版本。 Which should be any.
哪个应该是任何。
On my scenario the production version was 12, and my development version was 11, upgrading the package postgresql-client-xx
was enough to solve my incident.在我的场景中,生产版本是 12,我的开发版本是 11,升级包
postgresql-client-xx
足以解决我的事件。
Reference web page: https://www.postgresql.org/download/linux/ubuntu/参考网页: https ://www.postgresql.org/download/linux/ubuntu/
sudo apt-get update && sudo apt-get -y upgrade postgresql-client
One interest thing to point out is that after the upgrade the previous version kept installed:需要指出的一件有趣的事情是,在升级之后,以前的版本仍然安装:
mlazo@mlazo-pc:~$ dpkg -l |grep -i postgresql-client
ii postgresql-client-11 11.8-1.pgdg18.04+1 amd64 front-end programs for PostgreSQL 11
ii postgresql-client-12 12.4-1.pgdg18.04+1 amd64 front-end programs for PostgreSQL 12
Hope my experience would be helpful to someone.希望我的经验对某人有帮助。
Greetings,问候,
Your local version needs to match the one used by AWS on the remote server.您的本地版本需要与 AWS 在远程服务器上使用的版本相匹配。 Unfortunately, apt-get install will lag behind the official release.
不幸的是,apt-get install 会落后于官方发布。
So you need to proceed the following way:所以你需要按照以下方式进行:
sudo apt-get remove postgresql
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
Then check your error message should be something like然后检查你的错误信息应该是这样的
pg_dump: server version: 12.3; pg_dump version: 10.16 (Ubuntu 10.16-0ubuntu0.18.04.1)
So it means you want version 12 (and not 13), for the install of the matching version by specifying the version number (without minor) during your fresh install:所以这意味着您需要版本 12(而不是 13),通过在全新安装期间指定版本号(没有次要版本)来安装匹配版本:
sudo apt-get -y install postgresql-12
Now it works:现在它起作用了:
pg_dump -h {{endpoint}} -U {{username}} -f dump.sql {{tablename}}
NB: You get the endpoint in Connectivity & security go to https://us-east-2.console.aws.amazon.com/rds/home?region=us-east-2 and click on your DB instance注意:您在Connectivity & security中获得端点转到https://us-east-2.console.aws.amazon.com/rds/home?region=us-east-2并单击您的数据库实例
I had the same message, for me it was that I had to adjust the following:我有同样的信息,对我来说,我必须调整以下内容:
export LD_LIBRARY_PATH=/usr/pgsql-12/lib:....
export LD_RUN_PATH=/usr/pgsql-12/lib:.....
I am trying to dump a Postgresql database using the pg_dump tool.我正在尝试使用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-version
option is now deprecated and really would not be aa solution to my issue even if it had worked. --ignore-version
选项现在已弃用,即使它有效,也不会真正解决我的问题。
How can I upgrade pg_dump to resolve this issue?如何升级pg_dump以解决此问题?
For Ubuntu 20.04 with the "official" postgresql repo, moving from pg12 to pg13, I had to do this:对于具有“官方”postgresql 存储库的 Ubuntu 20.04,从 pg12 移动到 pg13,我必须这样做:
sudo apt purge postgresql-12
This was very hard for me to pinpoint.这对我来说很难确定。 I had played with a variety of these packages:
我玩过各种这些包:
run pg_dump -d [DATABASE] -h [HOST] -p [PORT] -U [USER]
it matches pg_dump with postgres version and runs your dump successfully它匹配 pg_dump 与 postgres 版本并成功运行你的转储
I experienced a similar problem on my Fedora 17 installation.我在安装 Fedora 17 时遇到了类似的问题。 This is what I did to get around the issue
这就是我为解决这个问题所做的
pg_dump
at /usr/bin/pg_dump
(as root: "rm /usr/bin/pg_dump")/usr/bin/pg_dump
中的内置pg_dump
(作为 root:“rm /usr/bin/pg_dump”) Now make a symbolic link of the postgresql installation现在创建 postgresql 安装的符号链接
Again as root ln -s /usr/pgsql-9.2/bin/pg_dump /usr/bin/pg_dump
再次作为 root
ln -s /usr/pgsql-9.2/bin/pg_dump /usr/bin/pg_dump
That should do the trick这应该够了吧
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.