Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

db:pull fails in Postgres if database with same name as current user does not exist #84

Closed
kiddrew opened this issue Feb 11, 2016 · 1 comment

Comments

@kiddrew
Copy link

kiddrew commented Feb 11, 2016

The workaround for this is fairly simple, but it's an issue nonetheless. If my local Postgres instance does not have a database with the same name as my current user, the db:pull command fails. See below:

INFO [01d8d37e] Running /usr/bin/env mkdir -p /var/www/ilf-cms/rvm1scripts/ as deploy@ilf-web1
INFO [01d8d37e] Finished in 0.219 seconds with exit status 0 (successful).
INFO Uploading /Users/andrew/.rvm/gems/ruby-2.3.0/gems/rvm1-capistrano3-1.4.0/script/rvm-auto.sh 100.0%
INFO [4efcaa1e] Running /usr/bin/env chmod +x /var/www/ilf-cms/rvm1scripts/rvm-auto.sh as deploy@ilf-web1
INFO [4efcaa1e] Finished in 0.213 seconds with exit status 0 (successful).
local {"adapter"=>"postgresql", "encoding"=>"unicode", "host"=>"localhost", "username"=>"andrew", "pool"=>5, "timeout"=>5000, "port"=>5432, "database"=>"ilfcms_development"}
Local database: ilfcms_development
Please enter answer (Are you sure you want to erase your local database with server database (y)es, (n)o  ? ): y
local {"adapter"=>"postgresql", "encoding"=>"unicode", "host"=>"localhost", "username"=>"andrew", "pool"=>5, "timeout"=>5000, "port"=>5432, "database"=>"ilfcms_development"}
INFO [cd624fcb] Running /usr/bin/env cd /var/www/ilf-cms/current &&  pg_dump --no-acl --no-owner   | bzip2 - - > db/_2016-02-11-101218.sql.bz2 as deploy@ilf-web1
INFO [cd624fcb] Finished in 0.240 seconds with exit status 0 (successful).
INFO Downloading db/_2016-02-11-101218.sql.bz2 100.0%
INFO leaving /var/www/ilf-cms/current/db/_2016-02-11-101218.sql.bz2 on the server (add "set :db_remote_clean, true" to deploy.rb to remove)
INFO executing local: bunzip2 -f db/_2016-02-11-101218.sql.bz2 &&  psql -c "SELECT pg_terminate_backend(pg_stat_activity.pid) FROM pg_stat_activity WHERE pg_stat_activity.datname = 'ilfcms_development' AND pid <> pg_backend_pid();;"  -U andrew  -h localhost  -p 5432 ;  dropdb  -U andrew  -h localhost  -p 5432  ilfcms_development;  createdb  -U andrew  -h localhost  -p 5432  ilfcms_development;  psql  -U andrew  -h localhost  -p 5432  -d ilfcms_development < db/_2016-02-11-101218.sql
psql: FATAL:  database "andrew" does not exist
INFO leaving db/_2016-02-11-101218.sql (specify :db_local_clean in deploy.rb to remove)
INFO Completed database import
@kiddrew
Copy link
Author

kiddrew commented Feb 11, 2016

The issue is this line:

psql -c "SELECT pg_terminate_backend(pg_stat_activity.pid) FROM pg_stat_activity WHERE pg_stat_activity.datname = 'ilfcms_development' AND pid <> pg_backend_pid();;"  -U andrew  -h localhost  -p 5432 

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

No branches or pull requests

1 participant