7

When using the base PostgreSQL Docker image, you choose a PostgreSQL version, spin up a container and you're running. Great! But what the the correct/best way to upgrade to a newer version of PostgreSQL in the future?

4

There is no easy solution for this at the moment, but the simplest I've found is to pg_dump the old version and then load that dump into the newer version.

There is a fair bit of discussion at https://github.com/docker-library/postgres/issues/37 on possible solutions to this problem, and a proof of concept for a docker-based upgrade at https://github.com/tianon/docker-postgres-upgrade

2

After running PostgreSQL in a container for over a year I tend to think databases aren't that great to containerize for exactly reasons like this. Containers are not intended to be used like VMs, and so every aspect of the tooling will fight you if you try to treat it like a VM that you administer. Containers are like glorified chroots - isolation and reproducible environments for a particular application, and the less configuration that application requires the better.

All that said, if you insist that you must run PostgreSQL in a container, at the very least you should mount a volume from somewhere to put the data files on so that you can safely destroy or modify your database server image (for things like PostgreSQL upgrades). Any configuration that has to be done should be done in the Dockerfile so that upgrades are also handled by editing the Dockerfile - if you're doing a minor upgrade for example, you might only just need to change the tag of the FROM image in your Dockerfile.

1

You just need to specify a tag, which corresponds to a version of PostgreSQL within an image. You should not upgrade PostgreSQL manually withing running container, because that defeats the purpose of using the base image.

In Dockerfile, using FROM instruction:

FROM postgres:9.4

From command line, using run command:

$ sudo docker run [OPTIONS] postgres:9.4 [COMMAND] [ARG...]
  • I could be mistaken, but I think this would not upgrade your data, so you'd run into compatibility problems. E.g. if I'm running PSQL 9.3 and I want to upgrade to 9.4, changing the version of the Docker image would leave the 9.4 binary trying to reference and use data that's structured according to the 9.3 formats. There's a migration step that's missing. That's what A Lee's answer addresses – Nathan Wallace Apr 28 '17 at 2:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.