When I tried Rails db: migrate: reset, I got an error I had never seen and got stuck a bit, so I'd like to share the solution here.
ERROR!
ERROR: database "hoge_development" is being accessed by other users
DETAIL: There are 1 other sessions using the database.
To be honest, I wasn't sure why this happened, but it seems that other users kept connecting and couldn't access the db container.
You need to go inside the container, connect to PostgreSQL and force delete the connection.
【environment】
First, enter the db container.
$ docker exec -it hoge_db_1 bash
root@xxxxxaf78adb:/#
Once inside the container, connect to PostgreSQL.
root@xxxxxaf78adb:/# psql -U postgres
After connecting to PostgreSQL, display the pid of the connecting user with the following command.
postgres=# SELECT pid FROM pg_stat_activity where pid <> pg_backend_pid();
pid
-------
144
29
28
27
(4 rows)
Since four came out in ↑, execute the following commands one by one in order to disconnect all.
SELECT pg_terminate_backend(144);
pg_terminate_backend
----------------------
t
(1 row)
SELECT pg_terminate_backend(29);
pg_terminate_backend
----------------------
t
(1 row)
(abridgement)
I did this, got out of the container and `` `docker-compose exec web rails db: migrate: reset``` and it passed!
However, it is unclear why other users are connected even after checking, so if you can understand it, I would appreciate it if you could comment! !!
Almost every day, I output what I got stuck in my personal development. If you have any suggestions, I would appreciate it if you could comment!
Recommended Posts