run a specific version of pg_dump with docker

Just some interesting code to remember

The Issue

When local postgres installation has a different version than on server, pg_dump might fail with the following message:

pg_dump: server version: 9.6.8; pg_dump version: 9.5.5
pg_dump: aborting because of server version mismatch

My Solution

With docker it's easy to use exactly the version as on the server.

Put hostname and credentials into an env-file .env-for-dump:

PGHOST=dbhost.example.com
PGPORT=5432
PGREQUIRESSL=true
PGDATABASE=mydatabase
PGUSER=myuser
PGPASSWORD=mypassword

Run the following command und a bash or powershell:

docker run --env-file .env-for-dump --volume ${PWD}:/tmp -it postgres:9.6-alpine pg_dump > dump.sql

Read More

comments powered by Disqus