Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

docker-compose rails rake db:reset fails, "cannot drop the currently open database"

I can't seem to reset my database while using docker compose. I've tried killing the server, killing just the database, and restarting the machine.

Anyone know the best way to clear out the development database?

Here's what I tried:

docker-compose run web rake db:reset

I am getting this error:

PG::ObjectInUse: ERROR: cannot drop the currently open database : DROP DATABASE IF EXISTS "postgres" Couldn't drop database 'postgres' rake aborted!

I'm using the setup exactly as described by the docker-compose quickstart: https://docs.docker.com/compose/rails/

I have a rails container and a postgres container

like image 864
shortwavedave Avatar asked Aug 25 '16 02:08

shortwavedave


1 Answers

You are using the wrong database.

The database postgres is normally not used for user data, but for administrative purposes. For example, if you want to drop a database, you have to be connected to a different database in the PostgreSQL database cluster to issue the SQL statement DROP DATABASE. Normally, the database postgres is used for that purpose, and I have no doubt that Docker does exactly that when it tries to drop a database.

If you really want to drop the database postgres, you'd have to connect to some other database in the cluster. The correct solution, however, is to keep your data in a different database. Then the problem should go away by itself.

like image 107
Laurenz Albe Avatar answered Nov 09 '22 06:11

Laurenz Albe