Skip to content

Conversation

@mdpatrick
Copy link
Contributor

These changes allow you to push / pull without needing to run migrations on either end

relevant to issue #25

@mdpatrick
Copy link
Contributor Author

While this is an improvement, I still end up needing to rake db:drop & rake db:create before doing db:pull or I end up getting "relation doesn't exist" errors.

@mdpatrick
Copy link
Contributor Author

I've amended the pull request to add three important steps:

  • disconnecting all existing database connections (necessary to drop db)
  • drop the database
  • recreate the database

If this is not done, it will appear as though the db has been pushed or pulled correctly, however it will get "relations" errors which could go unnoticed. Googling around it seems the only way to resolve these is to recreate the db so that it matches template0 instead of template1 (pg quirk). Additionally, it's necessary to disconnect database connections otherwise the database will not drop while a connection is active from the webserver, for example.

I believe this pull request resolves all issues with postgresql. You can push or pull a database and it will be copied perfectly regardless of whether it exists and needs to be overwritten or does not currently exist and must be created from dump.

The SQL necessary to disconnect all connections except the one currently being used to connect to the database ONLY works on Postgres 9.2. For postgres 9.1 and before pg_terminate_backend(procpid) must be used instead of pg_terminate_backend(pid). See the second answer on this page for more info on disconnecting postgresql server connections: http://stackoverflow.com/questions/7073773/drop-postgresql-database-through-command-line

sgruhier added a commit that referenced this pull request Mar 30, 2014
use heroku dump/restore arguments for postgresql
@sgruhier sgruhier merged commit eca16cf into sgruhier:master Mar 30, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants