Question: I have a rails application running over Postgres.

I have two servers: one for testing and the other for production.

Very often I need to clone the production DB on the test server.

The command I'm runnig via Vlad is:

```
rake RAILS_ENV='test_server' db:drop db:create

```

The problem I'm having is that I receive the following error:

```
ActiveRecord::StatementInvalid: PGError: ERROR: database <database_name> is being accessed by other users DROP DATABASE IF EXISTS <database_name>

```

This happens if someone has accessed the application via web recently (postgres keeps a "session" opened)

Is there any way that I can terminate the sessions on the postgres DB?

Thank you.

### Edit

I can delete the database using phppgadmin's interface but not with the rake task.

How can I replicate phppgadmin's drop with a rake task?

Answer: 
Here's a quick way to kill all the connections to your postgres database.

```
sudo kill -9 `ps -u postgres -o pid` 

```

Warning: this will kill any running processes that the `postgres` user has open, so make sure you want to do this first.
Please check if your rails console or server is running in another tab and then

stop the rails server and console.

then run 

```
 rake db:drop

```