Question

In my rails 3 app, every time I run rake db:test:prepare in my local development environment, my PostgreSQL database gets dropped, and I get the following message:

Chriss-MacBook-Pro-2:castingflow Fif$ rake db:test:prepare
rake aborted!
PG::ObjectInUse: ERROR:  database "Fif" is being accessed by other users
DETAIL:  There are 3 other session(s) using the database.
: DROP DATABASE IF EXISTS "Fif"
/Users/Fif/.rvm/gems/ruby-1.9.3-p448/gems/activerecord-3.2.15/lib/active_record/connection_adapters/postgresql_adapter.rb:650:in `exec'
/Users/Fif/.rvm/gems/ruby-1.9.3-p448/gems/activerecord-3.2.15/lib/active_record/connection_adapters/postgresql_adapter.rb:650:in `block in execute'
/Users/Fif/.rvm/gems/ruby-1.9.3-p448/gems/activerecord-3.2.15/lib/active_record/connection_adapters/abstract_adapter.rb:280:in `block in log'
/Users/Fif/.rvm/gems/ruby-1.9.3-p448/gems/activesupport-3.2.15/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/Users/Fif/.rvm/gems/ruby-1.9.3-p448/gems/activerecord-3.2.15/lib/active_record/connection_adapters/abstract_adapter.rb:275:in `log'
/Users/Fif/.rvm/gems/ruby-1.9.3-p448/gems/activerecord-3.2.15/lib/active_record/connection_adapters/postgresql_adapter.rb:649:in `execute'
/Users/Fif/.rvm/gems/ruby-1.9.3-p448/gems/activerecord-3.2.15/lib/active_record/connection_adapters/postgresql_adapter.rb:772:in `drop_database'
/Users/Fif/.rvm/gems/ruby-1.9.3-p448/gems/activerecord-3.2.15/lib/active_record/railties/databases.rake:623:in `drop_database'
/Users/Fif/.rvm/gems/ruby-1.9.3-p448/gems/activerecord-3.2.15/lib/active_record/railties/databases.rake:532:in `block (3 levels) in <top (required)>'
/Users/Fif/.rvm/gems/ruby-1.9.3-p448/gems/activerecord-3.2.15/lib/active_record/railties/databases.rake:559:in `block (3 levels) in <top (required)>'
/Users/Fif/.rvm/gems/ruby-1.9.3-p448/bin/ruby_executable_hooks:15:in `eval'
/Users/Fif/.rvm/gems/ruby-1.9.3-p448/bin/ruby_executable_hooks:15:in `<main>'
Tasks: TOP => db:test:load => db:test:purge
(See full trace by running task with --trace)

I know there are other sessions using the database, but why would the database get dropped because of this? This never happens when I use sqlite for the development environment. How do I fix this?

Was it helpful?

Solution

PostgreSQL won't let you drop a database if there are connected users. I don't know, but maybe SQLite doesn't care. Is "Fif" your test database? Or your development database? It's a little strange you would have 3 connections to your test database, unless you have some automated test framework in place like guard/zeus, etc.

In any event, you need to close those down so you can recreate that database.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top