Last active
November 19, 2023 05:32
-
-
Save dctalbot/b37f8ae6ab03380c3bbf8bdef9041764 to your computer and use it in GitHub Desktop.
A psql command that dumps a postgres database into CSV files, 1 per table.
This file contains 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
psql -Atc "select tablename from pg_tables where schemaname='$SCHEMA'" $DB |\ | |
while read TBL; do | |
psql -c "COPY $SCHEMA.$TBL TO STDOUT WITH CSV HEADER" $DB > $TBL.csv | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Of course you need to set the right credentials info via a connection string or environment variables e.g.
export PGPASSWORD=foo
. Plus you can setSCHEMA
andDB
, for the schema/database pair you want to dump. Hope this helps someone!