Forked from gh0st026/docker_export_postgre_table.sh
Last active
May 17, 2021 04:02
-
-
Save Fallenstedt/5a0406a3c86e3e96cc2c609cef444e9f to your computer and use it in GitHub Desktop.
Dump PostgreSQL Table in docker container as CSV file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CONTAINER="name" | |
DB="Db name" | |
TABLE="Table Name" | |
FILE="file.csv" | |
sudo docker exec -u postgres ${CONTAINER} psql -d ${DB} -c "COPY ${TABLE} TO STDOUT WITH CSV HEADER " > ${FILE} | |
# Copy csv to table | |
# sudo psql -h localhost -U root -d my_db -p 5432 -c "\COPY source_table TO '/home/user/source_table.csv' DELIMITER ',' CSV HEADER;" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment