简体   繁体   中英

how to dump postgres database in django?

I have an application running in a docker container and psql database running in a docker container as well. i want to dump database while in django container, i know there is dumpdata in django but this command takes long time, i also tried docker exec pg_dump but inside django container this command doesn't work.

   services:
  db_postgres:
    image: postgres:10.5-alpine
    restart: always
    volumes:
      - pgdata_invivo:/var/lib/postgresql/data/
    env_file:
      - .env

  django:
    build: .

    restart: always
    volumes:
      - ./static:/static
      - ./media:/media
    ports:
      - 8000:8000
    depends_on:
      - db_postgres
    env_file:
      - .env

Is there any way to do pg_dump without using docker exec pg_dump while in django container?

While your container is running type:

docker-compose down -v

This will remove the volumes and thus all the data stored in your database of the container will be removed.

Now run

docker-compose up
docker-compose exec django python manage.py migrate

to create your tables again.

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