Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@gh0st026
Last active February 13, 2023 02:15
Show Gist options
  • Star 18 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save gh0st026/f02847cd6e680d484c26cafd460f3ef4 to your computer and use it in GitHub Desktop.
Save gh0st026/f02847cd6e680d484c26cafd460f3ef4 to your computer and use it in GitHub Desktop.
Dump PostgreSQL Table in docker container as CSV file
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}
@medcharaabipro
Copy link

Thx, it was exactly what I'm looking for.

@TheBunk92
Copy link

I've been battling with trying to get this to work for ages! You have saved me! Thanks!

@tutorialcreation
Copy link

Thank you.

@aderbas
Copy link

aderbas commented Oct 18, 2021

psql: error: FATAL: role "postgres" does not exist

@LoneExile
Copy link

psql: error: FATAL: role "postgres" does not exist

-u YOUR_POSTGRES_USERNAME

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