Rails + Postgres drop error: database is being accessed by other users

前端 未结 16 2139
时光取名叫无心
时光取名叫无心 2020-12-04 06:26

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

16条回答
  •  爱一瞬间的悲伤
    2020-12-04 07:06

    I had this same issue when working with a Rails 5.2 application and PostgreSQL database in production.

    Here's how I solved it:

    First, log out every connection to the database server on the PGAdmin Client if any.

    Stop every session using the database from the terminal.

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

    Start the PostgreSQL server, since the kill operation above stopped the PostgreSQL server.

    sudo systemctl start postgresql
    

    Drop the database in the production environment appending the production arguments.

    rails db:drop RAILS_ENV=production DISABLE_DATABASE_ENVIRONMENT_CHECK=1
    

    That's all.

    I hope this helps

提交回复
热议问题