This error occurs when the pg_dump client tool version is older than the PostgreSQL server you're backing up. PostgreSQL requires pg_dump to be the same version or newer than the target server.
The "pg_dump: aborting because of server version mismatch" error is a compatibility check that prevents pg_dump from attempting to back up a database when the client utility is older than the server version. PostgreSQL enforces this restriction because pg_dump cannot reliably handle database features and syntax from newer server versions. pg_dump is designed to be backward compatible (it can dump from older servers) but not forward compatible. This means a pg_dump version 14 client can safely back up PostgreSQL 12, 13, or 14 servers, but it cannot back up a PostgreSQL 15 or 16 server. The version mismatch typically occurs after server upgrades when the client tools aren't updated to match. The error message will show both versions, for example: "pg_dump: server version: 16.1; pg_dump version: 15.3". This makes it clear which component needs to be upgraded to resolve the incompatibility.
First, verify the version mismatch by checking both components:
# Check pg_dump version
pg_dump --version
# Check PostgreSQL server version
psql -U your_username -d your_database -c "SELECT version();"The output will show you exactly which version needs to be upgraded. For example, if pg_dump shows 15.3 and the server shows 16.1, you need to upgrade pg_dump to at least version 16.
Install the PostgreSQL client package matching your server version:
Ubuntu/Debian:
# Add PostgreSQL repository if needed
sudo apt-get install wget ca-certificates
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
# Update and install specific version (e.g., PostgreSQL 16)
sudo apt-get update
sudo apt-get install postgresql-client-16RHEL/CentOS/Rocky Linux:
# Install PostgreSQL repository
sudo dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-9-x86_64/pgdg-redhat-repo-latest.noarch.rpm
# Install specific version client
sudo dnf install -y postgresql16macOS (Homebrew):
# Upgrade PostgreSQL (includes client tools)
brew upgrade postgresql@16
# Or install specific version
brew install postgresql@16If you have multiple PostgreSQL versions installed, specify the full path to the correct pg_dump:
# Find all pg_dump installations
which -a pg_dump
# Or locate them manually
ls /usr/lib/postgresql/*/bin/pg_dump
# Use the specific version
/usr/lib/postgresql/16/bin/pg_dump -U your_username -d your_database > backup.sqlYou can also update your PATH to prioritize the newer version:
# Add to ~/.bashrc or ~/.zshrc
export PATH="/usr/lib/postgresql/16/bin:$PATH"
# Reload shell configuration
source ~/.bashrcConfirm that both versions now match or pg_dump is newer:
# Should show matching or newer version
pg_dump --version
# Test the backup
pg_dump -U your_username -d your_database -f test_backup.sql
# Verify the backup file was created
ls -lh test_backup.sqlIf successful, you'll see no errors and a properly sized backup file will be created.
Version Compatibility Rules:
According to PostgreSQL documentation, pg_dump can dump from servers older than its own version and load into servers newer than its version. However, it cannot dump from servers newer than its own major version. The tool supports servers back to version 8.0.
Docker Environments:
When using Docker, ensure your backup container uses the same or newer PostgreSQL version as your database container. For example:
services:
postgres:
image: postgres:16
backup:
image: postgres:16 # Match or exceed database version
command: pg_dump -h postgres -U user dbnameCross-Version Considerations:
If you need to dump from a newer server to restore on an older server (not recommended), you may need to manually edit the dump file to remove syntax not understood by the older version. Use the --quote-all-identifiers flag when dealing with servers of different major versions to avoid reserved word conflicts.
Alternative Tools:
For environments where upgrading pg_dump is not feasible, consider using third-party backup tools like pgBackRest, Barman, or cloud-native solutions (AWS RDS automated backups, Google Cloud SQL backups) that handle version compatibility automatically.
ERROR: syntax error at end of input
Syntax error at end of input in PostgreSQL
Bind message supplies N parameters but prepared statement requires M
Bind message supplies N parameters but prepared statement requires M in PostgreSQL
Multidimensional arrays must have sub-arrays with matching dimensions
Multidimensional arrays must have sub-arrays with matching dimensions
ERROR: value too long for type character varying
Value too long for type character varying
insufficient columns in unique constraint for partition key
How to fix "insufficient columns in unique constraint for partition key" in PostgreSQL