Skip to content

Instantly share code, notes, and snippets.

@joselcvarela
Last active February 17, 2021 10:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joselcvarela/f1a43bd24777d9e4f6c0c364f8bac1cc to your computer and use it in GitHub Desktop.
Save joselcvarela/f1a43bd24777d9e4f6c0c364f8bac1cc to your computer and use it in GitHub Desktop.
POSTGRES DOCKER COMPOSE

DUMP ALL

docker-compose exec -u postgres postgres pg_dumpall -c > prod_`date +%d-%m-%Y"_"%H_%M_%S`.sql

DUMP TABLE FROM DATABASE

docker-compose exec -u postgres postgres pg_dump -d "DATABASE" -t 'TABLE' > TABLE_`date +%d-%m-%Y"_"%H_%M_%S`.sql

EXPORT TABLE TO CSV

docker-compose exec -u postgres postgres psql -d "DATABASE" -c `copy TABLE to stdout with csv header` > TABLE.csv

IMPORT TABLE FROM CSV

docker-compose exec -T -u postgres postgres psql -d "DATABASE" -c "copy TABLE from stdin with delimiter \";\" csv header" < TABLE.csv

NOTE: update table id sequence select setval('TABLE_id_seq', select max(id) from TABLE);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment