Skip to content

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

@kiddrew

Description

@kiddrew

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions