How to Fix “pg_dump Version Mismatch” Error After PostgreSQL Upgrade on Ubuntu


12 views

After upgrading PostgreSQL from version 9.2 to 9.3 on Ubuntu, many users encounter the frustrating version mismatch error when trying to use pg_dump:

pg_dump: server version: 9.3.4; pg_dump version: 9.2.8
pg_dump: aborting because of server version mismatch

The problem occurs because the pg_dump command is actually a symlink to /usr/share/postgresql-common/pg_wrapper, which maintains multiple PostgreSQL versions. During the upgrade, the system might not automatically update the default version used by the wrapper.

First, check what PostgreSQL versions you have installed:

ls -l /usr/lib/postgresql/

And verify where your pg_dump points to:

which pg_dump
ls -l $(which pg_dump)

The most reliable fix is to ensure all PostgreSQL client tools are upgraded:

sudo apt-get update
sudo apt-get install postgresql-client-9.3 postgresql-common

You can directly call the version-specific pg_dump:

/usr/lib/postgresql/9.3/bin/pg_dump -U username dbname > backup.sql

To avoid similar problems during future upgrades:

sudo update-alternatives --config pg_dump

Select the appropriate version from the list presented.

If issues persist, check the complete environment:

echo $PATH
pg_dump --version
psql --version

Remember that server and client versions must match for certain operations.


So you've successfully upgraded PostgreSQL from 9.2 to 9.3 following the official Ubuntu repository instructions, but now pg_dump is throwing this frustrating error:

pg_dump: server version: 9.3.4; pg_dump version: 9.2.8
pg_dump: aborting because of server version mismatch

The issue stems from Ubuntu's postgresql-common package maintaining version-specific binaries in separate paths. The pg_dump command is actually a wrapper script (/usr/share/postgresql-common/pg_wrapper) that tries to find the correct version, but sometimes gets confused after upgrades.

First, let's verify which versions are actually installed:

dpkg -l | grep postgresql-9.

And check where the binaries are located:

ls -l /usr/lib/postgresql/*/bin/pg_dump

Here's how to properly resolve this:

sudo apt-get update
sudo apt-get install --reinstall postgresql-client-9.3 postgresql-common

After running these commands, verify the fix:

pg_dump --version

If the above doesn't work, try specifying the full path to the 9.3 version:

/usr/lib/postgresql/9.3/bin/pg_dump -U username dbname > backup.sql

Or create an alias in your .bashrc:

alias pg_dump='/usr/lib/postgresql/9.3/bin/pg_dump'

When upgrading PostgreSQL in the future, always remember to:

  • First stop all PostgreSQL services
  • Explicitly install the new version's client tools
  • Remove old versions completely if not needed

For systems with multiple PostgreSQL versions, you can configure the default version:

sudo update-alternatives --config pg_dump

Select the appropriate version from the list presented.