LoginSignup
1
2

More than 3 years have passed since last update.

"xxxxx_development" is being accessed by other users

Last updated at Posted at 2019-09-12

"xxxxx_development" is being accessed by other usersエラー

bin/rails db:migrate:reset
PG::ObjectInUse: ERROR:  database "xxxxx_development" is being accessed by other users
DETAIL:  There are 2 other sessions using the database.
: DROP DATABASE IF EXISTS "xxxxx_development"
Couldn't drop database 'xxxxx_development'

psql -l //データベース名を確認
psql postgres //postgreSQLにログイン
\du //ユーザーと権限を確認

#この場合、接続中のユーザセッションを強制的に切断後に再実行します。
#まずは、接続中のユーザのpidを以下のコマンドで求めます。
postgres=# SELECT pid FROM pg_stat_activity where pid <> pg_backend_pid();
  pid  
-------
 82450
 82454
 21658
(3 rows)

#接続中のユーザセッションを強制的に切断する
postgres=# SELECT pg_terminate_backend(82450);
 pg_terminate_backend 
----------------------
 t
(1 row)

postgres=# SELECT pg_terminate_backend(82454);
 pg_terminate_backend 
----------------------
 t
(1 row)

postgres=# SELECT pg_terminate_backend(21658);
 pg_terminate_backend 
----------------------
 t
(1 row)

#抜ける
postgres=# \q

正常に動いた!

参考
http://kzdev.hatenablog.com/entry/2017/09/21/125839

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2