Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.