Skip to content

Instantly share code, notes, and snippets.

@ksoda
Last active March 26, 2022 13:07
Show Gist options
  • Save ksoda/2ad7ab4c7996b782a72f263dff761309 to your computer and use it in GitHub Desktop.
Save ksoda/2ad7ab4c7996b782a72f263dff761309 to your computer and use it in GitHub Desktop.
psql -U postgres -h localhost \
-XAtc "SELECT tablename FROM pg_catalog.pg_tables where schemaname='public'" | while read table
do psql -U postgres -h localhost \
-c "\copy (SELECT * FROM $table) to $table.csv with csv header"
done
docker run -it --rm --name="postgres" \
--publish="5432:5432" \
--volume 'postgres-14-data:/var/lib/postgresql/data' \
--env='POSTGRES_HOST_AUTH_METHOD=trust' \
postgres:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment