简体   繁体   中英

How to Upgrading dockerized postgres from 11 to 12

So as the title says i have a dockerized postgres database on a rails app. I'm just wondering how i'd go about upgrading the postgres version. I havn't done any upgade work before so I'm don't want to lose data.

docker-compose file

  postgres:
    image: postgres:11.5
    ports:
      - "5432:5432"
    volumes:
      - postgres_data:/var/lib/postgresql/data
    env_file:
      .docker.env

You can use pg_dumpall command for upgrading eg 11.x to 12.x:

  1. Backup your old database
docker exec -it <your-old-postgres-container-id> /usr/bin/pg_dumpall -U <postgres-username> backupfile   #postgres-username='postgres'
  1. Start new container with new Postgres version ( Note! with new volume mount )
  2. Import backuped file into new container
ocker exec -it <new-postgres-container-id> psql < backupfile
  1. Stop old container and verify Import in new container

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM