0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

bin/rails db:drop実行に失敗した時の対処法

Last updated at Posted at 2021-08-17

症状

ターミナルで$ bin/rails db:dropコマンドを入力したら以下のような画面が表示された(データベース名はセキュリティ上伏せてある)

terminal

PG::ObjectInUse: ERROR:  database "XXXxxxx" is being accessed by other users
DETAIL:  There are 3 other sessions using the database.

rails aborted!
ActiveRecord::StatementInvalid: PG::ObjectInUse: ERROR:  database "XXXxxxx" is being accessed by other users
DETAIL:  There are 3 other sessions using the database.

原因と対応

原因は作成中のアプリ以外に接続しているアプリなどはないのに接続されっぱなしになっている模様。
$ bin/rails db:migrate:resetしても改善されなかった。
PostgreSQLの再起動で回復に成功。
DBを再起動すると他のDBを使用しているアプリまで切断されることになるので実行には注意が必要。

terminal

$ brew services stop postgresql  # postgresqlの停止
$ brew services stop postgresql  # postgresqlの起動

# 以下のコマンドでDBアプリの状態を確認できる
$ brew services list

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?