Skip to content

Instantly share code, notes, and snippets.

@xjcoan
Last active January 25, 2024 20:22
Show Gist options
  • Select an option

  • Save xjcoan/e58743c17922171a4ab459e71cb48b59 to your computer and use it in GitHub Desktop.

Select an option

Save xjcoan/e58743c17922171a4ab459e71cb48b59 to your computer and use it in GitHub Desktop.
Upgrading Existing Postgres in Docker/Compose

Example done from an upgrade from 12.5 to 15.4

App is a Rails app, the default container user has limited access and no direct sql/psql access

  • build the image with current pg version & docker compose up
  • docker exec -it <NAME_OF_CONTAINER> pg_dump <NAME_OF_PRIMARY_DB> > db.out -U postgres
    • had issues doing pg_dumpall; wondering if the default postgres database interferred?
  • backup the data from the volume. I store in a tmp folder in the repo.
  • clear the folder your data is saved in or delete the volume
  • update the postgres version in docker compose, run docker compose build & up
  • service should start and create default database if configured to do so
  • copy the db.out into the database container:
    • docker ps and copy the ID of the container
    • docker cp db.out <ID>:/db.out
  • Load the db from the dump file
    • docker exec -it <NAME_OF_DATABASE_CONTAINER> /bin/bash
    • ls to ensure the db.out file is present
    • psql <DATABSE_NAME> < db.out -U postgres
      • substititute postgres for the name of the db connection user as-needed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment