Does shrinking a JDBC connection pool actually save PostgreSQL memory? I measured it.
At a previous company, I spent quite a bit of time tuning a custom-built JDBC connection pool. One of the most effective memory optimizations I found was automatically shrinking the pool during idle periods. PostgreSQL uses a process-per-connection model, so keeping unnecessary connections open has a real memory cost.
I wanted to revisit this with HikariCP and measure both the memory savings and the cost of reopening connections.
I ran two Spring Boot instances sharing PostgreSQL 16, comparing three pool configurations under the same burst → idle → burst workload.
Results:
- Default pool: 20 connections remained open, PostgreSQL memory ~57.5 MiB.
- Shrinking pool: connections dropped to 2, PostgreSQL memory ~28.5 MiB.
- Savings: ~29 MiB of PostgreSQL memory.
The tradeoff was connection reopening. Median acquisition time increased from under 3 ms to around 200 ms when traffic returned.
One interesting detail: setting minimumIdle=1 alone wasn't enough when idle retirement was disabled. The pool still held all 20 connections after the burst.
The experiment used a deliberately short idle timeout to make the behavior observable, not as a production recommendation.
With many application instances maintaining independent connection pools, the potential savings can add up.
To clarify the practical motivation: this was a deliberately small experiment to isolate the effect, not just an exercise in saving 29 MiB on one server.
At my previous company, we had many application VMs connecting to a shared PostgreSQL database. Shrinking idle pools across those instances produced substantial aggregate memory savings. For example, 30 instances with 32 connections each means 960 persistent connections. If idle retirement brings that down to an average of 16 per instance, that's 480 fewer PostgreSQL connections consuming resources.
Actual savings depend on the workload, but this is where the approach becomes particularly valuable.
Full article, measurements, and reproducible experiment:
https://pvrlabs.xyz/articles/spring-boot-jdbc-pool-reclaim.html
Do you use fixed-size pools in production, or allow idle connections to retire?
View all comments
Show parent comment
2
u/fykup Oct 16 '26
Just because something looks obvious to you in isolation doesn't mean it's a trivial problem in production.
When we migrated a large enterprise deployment at an S&P 100 company to PostgreSQL, its process-per-connection memory model introduced real challenges. We needed pragmatic optimizations that worked within the existing architecture, not simplistic advice to replace mature components or throw PgBouncer at the problem. Retiring idle connections delivered substantial resource savings across many application instances.
This wasn't some toy application. We were dealing with one of the largest enterprise deployments of its kind, where seemingly minor inefficiencies multiplied across hundreds of processes and connections.
As for monetization, I'm fortunate enough to have the time to revisit these problems and share what I've learned. Yes, I run a consulting business, but these experiments aren't sales pitches or a funnel for consulting work. The methodology, raw data, and reproduction scripts are all publicly available on GitHub.
I'm genuinely interested in an area I believe is underexplored: running smaller, more efficient, self-hosted systems without automatically reaching for heavyweight infrastructure. I'm not particularly interested in writing yet another Kubernetes tutorial.
You may find the results obvious. That doesn't make the underlying engineering problem trivial, and it certainly doesn't make the research disguised spam.
I'm writing for engineers who are interested in understanding real-world tradeoffs, not those who dismiss problems without bothering to understand their context.