Postgresql 9.2 pg_dump version mismatch

295,885

Solution 1

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. Note that there is no need to initdb a new cluster in the client machine.

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

Solution 2

  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
    

This will create the symlink to the newer version.

Solution 3

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

  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/bin with:

    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. So if your error says, pg_dump: server version: 9.9, then link to /usr/lib/postgresql/9.9/....

Solution 4

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

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

Solution 5

You can just locate pg_dump and use the full path in command

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
Share:
295,885

Related videos on Youtube

Chris Colla
Author by

Chris Colla

Updated on April 04, 2022

Comments

  • Chris Colla
    Chris Colla about 2 years

    I am trying to dump a Postgresql database using the pg_dump tool.

    $ 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 a a solution to my issue even if it had worked.

    How can I upgrade pg_dump to resolve this issue?

  • Craig Ringer
    Craig Ringer about 11 years
    Location will vary depending on how PostgreSQL was installed (EnterpriseDB installer, MacPorts, Homebrew, etc), but the gist of the answer - that the user probably has the right version already installed - is certainly right.
  • Craig Ringer
    Craig Ringer about 11 years
    Tip: in Terminal.app, find / -name pg_dump -type f 2>/dev/null
  • Craig Ringer
    Craig Ringer about 11 years
    Nonono, don't just delete package managed files! If it's in /usr/ (rather than /usr/local/, /home/ or /opt/, where deleting things is generally OK) you really need to use the package manager - rpm & yum or dpkg and apt-get or aptitude, distro-depending. Either uninstall the package with rpm or alter your PATH environment variable in your .bash_profile so that the newer version is found first. If you're in doubt about something being under package management, use rpm -qf /path/to/file (RPM) or dpkg -S /path/to/file (dpkg)
  • Alex Weber
    Alex Weber almost 11 years
    In my case, opening .bash_profile and adding "export PATH=/Applications/Postgres.app/contents/macos/bin:$PATH" did the magic.
  • Seth
    Seth about 10 years
    This only happens when you upgrade PostgreSQL. I just did a fresh install of the OS and didn't have any problems with this.
  • IanBussieres
    IanBussieres almost 10 years
    For anyone wondering, this solution applies to non-Heroku Ubuntu as well.
  • Arthur
    Arthur over 9 years
    According to what has been said in this answer, it's a pretty bad idea as well.
  • Seth
    Seth over 9 years
    That answer recommends removing software by deleting a folder. Here we're just recreating a symbolic link.
  • Yo Ludke
    Yo Ludke about 9 years
    Perfect! Recreating the symbolic link after postgres upgrade
  • Franco
    Franco over 8 years
    Worked perfectly for me. I never imagined that the version mismatch was caused by /usr/bin/pg_dump which has nothing to do with my fresh PostgreSQL update. I'm fine with the ln solution.
  • VaTo
    VaTo over 7 years
    I'm using centos and by doing yum postgresql I get that I have the latest postgresql version installed. And I still get that error :( So it doesn't work for me.
  • Seth
    Seth over 7 years
    @VaTo see the additional paragraph I added to the 3rd step.
  • Seth
    Seth over 7 years
    @VaTo what is the full text of your error? Since you're on CentOS, replace that path with the path to your installation of PostgreSQL.
  • VaTo
    VaTo over 7 years
    I had to get a pg_dump newer version from another machine and then copy that pg_dump file into this machine and now it works.
  • Davidson Lima
    Davidson Lima almost 6 years
    For CentOS users (my version is 6.9 Final): sudo /usr/pgsql-<version>/bin/pg_dump <database-name> -U <username> -h localhost
  • Obromios
    Obromios over 5 years
    It was much quicker for me to find the versions using locate pg_dump
  • Poutrathor
    Poutrathor about 5 years
    IMO, you should not add 2>/dev/null since that will throw out the ERROR stream rather than printing it to the console. I think one should want to see any errors happening, except some rare cases. For example, in my case, it reminds me that I was not root thus failing to see some directories where the newer pg_dump version was installed. In general, don't remove errors.
  • Deepak Mahakale
    Deepak Mahakale almost 5 years
    @jDub9 what version did you use while taking the dump? Make sure you are using the same
  • Andrius
    Andrius over 4 years
    This is very useful. As I was confused why pg_dump was not working on one of my clusters. Turns out, it was using default Postgresql version, when one of my clusters was upgraded to newer version. Specifying cluster, solved the problem.
  • vinh
    vinh over 4 years
    This won't replace the existing executable files on your computer, so you'll need to explicitly use the new version of pg_dump, e.g. /usr/lib/postgresql/9.6/bin/pg_dump or make a new shortcut e.g. /usr/bin/pg_dump96
  • rado
    rado about 4 years
    I didn't have to explicitly use the new it picked it up.
  • rogerdpack
    rogerdpack over 3 years
    You can sometimes (easily) get particular versions from it too do brew search postgres to see them all.
  • mikebridge
    mikebridge about 3 years
    This is by far the simplest and most flexible solution.
  • moodboom
    moodboom almost 3 years
    Agreed, but at least my package manager, apt in Ubuntu 20.04 using the "official" postgres repo, leaves this bad /usr/bin/pg_dump link from an old install and will not refresh it no matter what I ask it to do (and I asked it to do a LOT before giving up).
  • thanos.a
    thanos.a over 2 years
    The first time it needs sudo updatedb to create the locate db
  • Lahiru Jayaratne
    Lahiru Jayaratne over 2 years
    This worked just fine!
  • John Doe
    John Doe over 2 years
    This command was useful in my case: docker run --net host --rm -i postgres:14.1 pg_dump -h 127.0.0.1 -U postgres dbname > pg.dump.schema.sql
  • Zach Milan
    Zach Milan over 2 years
    For those using newer Macs (with Zsh instead of Bash), place the above in your .zshrc file.
  • Gunar Gessner
    Gunar Gessner about 2 years
    Here's a function to add to your .bashrc: pg_dump-version() { docker run --rm "postgres:${1}-alpine" pg_dump ${@:2} } ­— e.g. pg_dump 14 $PG
  • Abhinav Keshri
    Abhinav Keshri about 2 years
    You should have docker installed on your system to proceed with this solution.