Generic Best Practices for HikariCP with Azure Database for PostgreSQL
Connection pooling is crucial for Azure Database for PostgreSQL performance, as establishing new connections is resource-intensive. HikariCP, a popular Java connection pool, can encounter issues if misconfigured, leading to exhaustion, stale connections, or latency. Maximum lifetime controls how long connections are reused before being retired, with 30 minutes being a common, effective setting. Minimum idle connections should ideally match the maximum pool size to ensure immediate availability for traffic spikes. Idle timeout determines how long unused connections stay before removal, with the default 10 minutes offering a good balance. Maximum pool size is critical; too small causes timeouts, while too large overwhelms the database. A conservative starting point for maximum pool size is 10-20, adjusted after load testing. Enabling TCP keepalive prevents stale connections caused by network devices. Monitoring active and idle connections, acquisition time, and pool exhaustion helps identify correct sizing. Long-running queries are often the root cause of pool exhaustion, so query performance must be investigated. A sample production configuration is provided, balancing these parameters for Azure Database for PostgreSQL. The primary goal is a healthy balance between application responsiveness and database resource consumption, not simply maximizing connections. Following these practices improves scalability, latency, and reliability for applications connecting to Azure Database for PostgreSQL.