Using pgxpool as an import for Client Side Pooling, also using RDS Proxy for pooling
Folder Structure
pghelper.go (here used singleton pgxPool.ConnectConfig(ctx, config) and returning connect instance to all the handlers
inside handler calling the connection Pool instance to run the DB query
Note: Not closing the instance inside the handler or anywhere in the code, based on few docs in the Stackoverflow
Is this the correct way?
As the ClientConnections are closing but the Database connections are not closing even after the timeouts are recieved in RDS Proxy
Timeouts set
How should I make pooling work as expected as I feel pooling is not happening and neither the DB connections are not closing after timeouts?
There 2 types of connections you have with RDS proxy
The timeout you set in the proxy configuration is for the 1st type of connections. The proxy maintains a bunch of connections to the actual DB instance even if there are no connections from an application.
DB connections are not closing after timeouts
There doesn't seem to be a way to change this behaviour from AWS console. But you can use the modify-db-proxy-target-group
command in AWS CLI to change the max amount of Idle DatabaseConnections that the proxy maintains.
aws rds modify-db-proxy-target-group \
--target-group-name default \
--db-proxy-name <name-of-your-proxy> \
--connection-pool-config MaxConnectionsPercent=80,MaxIdleConnectionsPercent=20
This will limit the connections to Database to 80% of max_connections
and limit idle connections to 20%
The documentation mentions that these values default to 100% as the limit for connections to DB and 50% for idle connections to the DB. After lowering the limit for idle connections you should start seeing the proxy maintain fewer idle connections
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With