Postgres: terminanting db connections.
Next time you get stuck with a message like:
ActiveRecord::StatementInvalid: PG::ObjectInUse: ERROR: database "bummer_test" is being accessed by other users
DETAIL: There is 1 other session using the database.
try killing all the connections on the db. Login into the DB console, either by just using psql -d $(YOUR_DB_NAME)
, or su postgres -c psql
or bundle exec rails dbconsole
.
.. then:
SELECT pg_terminate_backend(psa.pid)
FROM pg_stat_activity AS psa
WHERE psa.datname = '<your_db_name>'
AND psa.pid <> pg_backend_pid(); -- don't terminate your own connection
Written by Nicolas Oga
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Rails
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#