Skip to content

Instantly share code, notes, and snippets.

@egoens
Created August 14, 2015 16:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save egoens/70950031aeec2df5d074 to your computer and use it in GitHub Desktop.
Save egoens/70950031aeec2df5d074 to your computer and use it in GitHub Desktop.
Shell script for exporting all tables for any given postgresql database_name
#!/bin/bash
# exports separate sql files for each table in the db. excludes "pg_" and "sql_" prefixed tables
for table in $(psql database_name -t -c "Select table_name From information_schema.tables Where table_type='BASE TABLE' and table_name not like 'pg_%' and table_name not like 'sql_%'");
do pg_dump -t $table database_name > /path/to/export/your/tables/$table.sql;
done;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment