← homeProgramming (Програмування)

Analyzing the PG::ObjectInUse error (Ruby on Rails)

Sometimes during development, you may encounter the error PG::ObjectInUse: ERROR.For example: rake db:drop; It will show us the following error: PG::ObjectInUse: ERROR: database "myproject_development" is being access...

This content has been automatically translated from Ukrainian.
Sometimes during development, you may encounter the error PG::ObjectInUse: ERROR.
For example:
rake db:drop;
It will show us the following error:
PG::ObjectInUse: ERROR:  database "myproject_development" is being accessed by other users

DETAIL:  There is 1 other session using the database

Couldn't drop database 'myproject_development'

rake aborted!

ActiveRecord::StatementInvalid: PG::ObjectInUse: ERROR:  database "myproject_development" is being accessed by other users

DETAIL:  There is 1 other session using the database.

Caused by:PG::ObjectInUse: ERROR:  database "myproject_development" is being accessed by other users

DETAIL:  There is 1 other session using the database.
Tasks: TOP => db:drop:_unsafe

(See full trace by running task with --trace)
Everything here is quite simple. The message is very informative and literally says - database "myproject_development" is being accessed by other users. This means that we cannot drop the database at the moment because there is an active connection to it. Locally, this is usually either a running rails server and/or rails c (console). They need to be closed to disconnect the process from the database. After that, we restart rake db:drop; and everything should work.
Sometimes it may happen that locally there seem to be no open processes/connections in the terminal, but we still have the error "database is being accessed by other users". Usually, this means that we have a process somewhere that is still working with the database. Sometimes it may be a background process/daemon. But to find and kill this process, more context is needed. You can scan ports and processes and kill those that are using the database. But I will probably write about this in another note.

🔥 More posts

All posts
Programming (Програмування)Apr 12, '24 10:07

What is Routing?

Routing (routing) is a key stage in the process of directing network traffic to its destination. ...

Programming (Програмування)Apr 15, '24 17:50

What is entropy?

Entropy is a concept from information theory and statistics that is used to measure the degree of...

Programming (Програмування)Apr 15, '24 18:11

What are HTTP Client Hints?

HTTP Client Hints (client hints) are a web browser mechanism that transmits information about the...

ZOMBIE in Ruby. What is it?
Programming (Програмування)May 3, '24 12:41

ZOMBIE in Ruby. What is it?

Ruby is a programming language. Everything is clear here. In the code of this language, you may e...

Programming (Програмування)May 7, '24 07:24

What is native machine code?

Native machine code is a type of software code that is executed directly by a computer's processo...