Skip to content

Instantly share code, notes, and snippets.

@gh0st026
Last active February 13, 2023 02:15
Show Gist options
  • 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}
@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