Skip to content

Instantly share code, notes, and snippets.

@richardvenneman
Last active March 4, 2020 12:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save richardvenneman/c4be5a9cda99448f88d43497f5ffff08 to your computer and use it in GitHub Desktop.
Save richardvenneman/c4be5a9cda99448f88d43497f5ffff08 to your computer and use it in GitHub Desktop.
Pull Heroku Postgres DB excluding specific table data
# Using the `--exlude-table-data` argument for the `heroku pg:pull` command doesn't seem to be working.
# Instead we're going to copy the Heroku PG database by using the Postgres `pg_dump` and `pg_restore` commands.
# Get the "Connection info string" for myapp
heroku pg:credentials:url DATABASE_URL -a myapp
# Download the database, excluding the `visits` and `ahoy_events` table data.
pg_dump "<PASTE_CONNECTION_INFO_STRING_HERE>" --exclude-table-data visits --exclude-table-data ahoy_events -O -x -Fc -f without_vists_and_ahoy_events.out -v
# In myapp, setup an empty database
bin/rails db:drop && bin/rails db:create
# Finally, restore the dump
pg_restore --verbose --clean --no-acl --no-owner -h localhost -d myapp without_vists_and_ahoy_events.out
@TareevEugene
Copy link

Actually its working for the moment
Try to use this
heroku pg:pull DATABASE_URL <local_db_name> --exclude-table-data="table1;table2;etc" --app <APP>

@richardvenneman
Copy link
Author

Actually its working for the moment
Try to use this
heroku pg:pull DATABASE_URL <local_db_name> --exclude-table-data="table1;table2;etc" --app <APP>

Cool! Thanks for letting me know!

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