2

Using pgxpool as an import for Client Side Pooling, also using RDS Proxy for pooling

Folder Structure

  • database

pghelper.go (here used singleton pgxPool.ConnectConfig(ctx, config) and returning connect instance to all the handlers

  • handler

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

  1. Lambda : 1 min
  2. RDS Proxy : 5 min

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?

Aagam Doshi
  • 155
  • 2
  • 14

1 Answers1

6

There 2 types of connections you have with RDS proxy

  1. Your application to RDS proxy
  2. RDS proxy to your RDS cluster/instance

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

jibby
  • 186
  • 2
  • 5