How do I fix this pg_dump error, "pg_dump: error: aborting because of server version mismatch"?

The pg_dump error, pg_dump: error: aborting because of server version mismatch, occurs when there is a discrepancy between the pg_dump and server versions. The pg_dump backup tool is designed to work with specific server versions, and if the versions do not match, compatibility issues may occur.

To resolve this error, you can either:

  1. Upgrade either your pg_dump or server version to match the other.
  2. Use a third-party backup tool, instead of pg_dump.

Upgrade pg_dump version

If you are managing your PostgreSQL database cluster on a newer version than the pg_dump utility installed on your local machine or Droplet, you can upgrade or reinstall the pg_dump utility to match your database version.

To upgrade pg_dump on Ubuntu, verify you have root privileges, and then run the following command:

sudo apt install postgresql-client-15 -y

After postgresql-client-, you need to specify the latest version of PostgreSQL client package, such as postgresql-client-15. Replace the client number with your desired version. For example, if your database version is on version 14 but your pg_dump is version 13, then you can match their versions by running the previous command with the version of your server. The package manager then handles the installation process and upgrades pg_dump to the desired version automatically.

If you want to match your pg_dump to the current server version, you can install a specific pg_dump version. For more information about PostgreSQL versions, see the official PostgreSQL release notes.

Use a third-party backup tool

You could alternatively explore third-party backup tools that are compatible with your managed PostgreSQL database version. While these tools typically offer greater flexibility and support for various database versions, make sure the backup tool you select matches your managed PostgreSQL database version, as this will prevent further compatibility issues.

We recommend you to refer to the official documentation for more detailed instructions and version compatibility guidelines about the resources specific to your PostgreSQL version and the backup tools.