-
Notifications
You must be signed in to change notification settings - Fork 159
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
No connection pool for 'ActiveRecord::Base' found for the 'reading' role. #275
Comments
Thanks for your report! I haven't read through this in-depth, but I know that we use a read-replica Postgres along with our Postgres primary without issue in Apartment. I'm attending a conference this week so it may be some time before I can take a closer look. @npezza93 or @mrpasquini do you have any thoughts? |
Thanks @mnovelo for the response, This is happening when we switch replica database multiple times.
This is the method we used to switch the primary as well as replica database This line is causing the issue. |
Interesting. I'm not as familiar with the MySQL implementation, but I know for Postgres it's more optimal to do the tenant switch after the db switch because the tenant switch issues a |
Can you share your Sample Postgres code here? |
@sunil-sharma what do you mean? |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. |
We are implementing multi-db on our app with help of ros-apartment gem. In our application we are using primary db as well as replica db for reading. We are switching write db with help of ros-apartment gem(Apartment::Tenant.switch!(tenant_name)) and using read db with help of
ActiveRecord::Base.connects_to(database: {reading: replica_db.to_sym })
. Loading the read replica db config dynamically using an initialiser file.app/config/initializers/db_config_load.rb
`
In some place in our code we are using reading role to read data from read replica.
ApplicatioRecord.rb
connects_to database: { writing: :primary, reading: :primary_replica }
Connection Pool for the replica_db is 25
When we hit multiple time on the api's we got the below error
No connection pool for 'ActiveRecord::Base' found for the 'reading' role.
In our mysql rds instance we have around 650 connections and it is using only 190 pools but still we got the connection pool error.
Guys any idea why the connection pool error, is it because of db config issue? or ros-aprtment tenant switch using all the connection pool?
How ros-apartment gem is handling connection pool in rails?
System configuration
Database: mysql Ver 14.14 Distrib 5.7.44, for osx10.17 (x86_64) using EditLine wrapper
Apartment version: ros-apartment (2.11.0)
Apartment config (in
config/initializers/apartment.rb
or so):use_schemas
: (true
orfalse
)Rails (or ActiveRecord) version:
Rails. 7.0
Ruby version:
Ruby : 3.0.6
The text was updated successfully, but these errors were encountered: