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
- https://www.postgresql.org/docs/9.6/libpq-envars.html
- https://docs.docker.com/engine/reference/commandline/run/
- https://hub.docker.com/_/postgres?tab=tags