I'm using the 3.9.13 PostgreSQL Client's PgPool to connect to multiple RDS instances with multiple microservices. I'm seeing a strange issue where long lived connections in these pools seem to be causing a memory leak at the database level. The memory consumption will increase over time so much that all available memory for the DB instance will run out and start using gigs of swap, before the DB crashes and gets restarted. On a DB instance with 4 GB of RAM and only about 10 connections to the DB, it will usually take a few days to completely run out of memory and use about 2 GB of swap. That means each connection is somehow using more than 600 MB of RAM.
If I restart the application, it clears out the connections and all the memory on the DB is freed up again.
I'm at a loss as to what could be using that much memory, and what at the application level could be causing that. Most of the DBs themselves are brand new and quite small, with maybe 4 or 5 tables with no more than a couple thousand rows in them. I know long lived postgres connections can accumulate metadata and consume memory, but for a DB this size, I'm not sure that's what I'm seeing here.
So here's my questions:
1) Is there something on the client (vertx) side that could be causing this memory accumulation? If so, is there any way to clear it out?
2) If not, what's the best way to expire DB connections in the pool? Ideally, I could remove connections after a specified time or number of queries ran after checking it back into the pool, and just grab a new connection. All I see is an option for idleTimeout but that will only clear out connections if they are idle for a specified time. With a small pool with constant traffic, they may never (or rarely) go idle for long enough to expire.
Here's my pool setup:
val connectOptions = pgConnectOptionsOf(
database = config.getString("name"),
host = config.getString("host"),
port = 5432,
connectTimeout = 30,
idleTimeout = 30,
user = config.getString("user"),
password = config.getString("password")
)
val pool = PgPool.pool(vertx, connectOptions, poolOptionsOf(maxSize = 10))