Backup/Restore a dockerized PostgreSQL database

后端 未结 10 1947
[愿得一人]
[愿得一人] 2020-12-22 15:50

I\'m trying to backup/restore a PostgreSQL database as is explained on the Docker website, but the data is not restored.

The volumes used by the database image are:<

10条回答
  •  一个人的身影
    2020-12-22 16:08

    cat db.dump | docker exec ... way didn't work for my dump (~2Gb). It took few hours and ended up with out-of-memory error.

    Instead, I cp'ed dump into container and pg_restore'ed it from within.

    Assuming that container id is CONTAINER_ID and db name is DB_NAME:

    # copy dump into container
    docker cp local/path/to/db.dump CONTAINER_ID:/db.dump
    
    # shell into container
    docker exec -it CONTAINER_ID bash
    
    # restore it from within
    pg_restore -U postgres -d DB_NAME --no-owner -1 /db.dump
    

提交回复
热议问题