user5196618
user5196618

Reputation:

How to find the number of active connections with database in Rails application

How to find the active number of database connections in Active Record Rails.

Is there any method to find the number of connections?

Thanks,

Upvotes: 11

Views: 5502

Answers (2)

mpz
mpz

Reputation: 1848

Number of active connections In development you can see the number of connections taken up by your application by checking the database.

bundle exec rails dbconsole

This will open a connection to your development database. You can then see the number of connections to your postgres database by running:

select count(*) from pg_stat_activity where pid <> pg_backend_pid() and usename = current_user;

Which will return with the number of connections on that database:

count

5 (1 row)

see more: https://devcenter.heroku.com/articles/concurrency-and-database-connections

Upvotes: 3

zwippie
zwippie

Reputation: 15515

I'm not really sure if this number represents the actual number of active connections, but it gives me a number none the less:

ActiveRecord::Base.connection_pool.connections.size

Upvotes: 9

Related Questions