Logging HikariCP Spring boot
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Introduction
HikariCP is the default connection pool in Spring Boot. To enable HikariCP logging, set the com.zaxxer.hikari logger to DEBUG in your application.properties or application.yml. This exposes connection acquisition times, pool statistics (active, idle, waiting connections), leak detection warnings, and connection lifecycle events. Monitoring these logs is essential for diagnosing slow database queries, connection leaks, and pool exhaustion issues.
Basic Logging Configuration
application.properties
application.yml
What the Logs Show
At DEBUG level, HikariCP logs:
| Log Entry | Meaning |
total=10 | Total connections in the pool |
active=3 | Connections currently in use |
idle=7 | Connections available for use |
waiting=0 | Threads waiting for a connection |
Added connection | New connection was created |
Timeout failure | Thread could not get a connection in time |
Pool Configuration
Setting pool-name makes logs easier to identify when multiple pools exist.
Leak Detection
HikariCP can detect connections that are borrowed but not returned:
When a leak is detected, HikariCP logs a stack trace showing where the connection was acquired:
This stack trace shows exactly which code acquired the connection but did not return it.
Monitoring with JMX
Enable JMX to expose pool metrics programmatically:
Spring Boot Actuator Integration
Access pool metrics at:
Micrometer/Prometheus Integration
Logging SQL Queries Alongside Pool Logs
Common Pitfalls
- Setting pool size too high: More connections is not always better. Each connection consumes memory on both the application and database. Start with
maximum-pool-size = (2 * CPU cores) + number_of_disksand tune based on load testing. - Not enabling leak detection in development: Without
leak-detection-threshold, connections held indefinitely (e.g., from missing@Transactionalor unclosed resources) silently exhaust the pool. Set it to 30-60 seconds in development. - Confusing connection timeout with query timeout:
connection-timeoutis how long to wait for a connection from the pool. Query timeout (how long a SQL query can run) is configured separately viaspring.jpa.properties.jakarta.persistence.query.timeout. - Logging at TRACE level in production: HikariCP TRACE logging is extremely verbose and impacts performance. Use DEBUG for troubleshooting and INFO for production.
- Not monitoring
threadsAwaitingConnection: A non-zerowaitingcount means the pool is undersized or connections are held too long. This is the earliest indicator of pool exhaustion, appearing before timeout errors.
Summary
- Set
logging.level.com.zaxxer.hikari=DEBUGto enable HikariCP connection pool logging - Enable leak detection with
spring.datasource.hikari.leak-detection-threshold=30000to find unreturned connections - Use Spring Boot Actuator metrics (
hikaricp.connections.*) for runtime monitoring - Key metrics to watch: active connections, idle connections, threads awaiting connection, and timeout count
- Set
pool-namefor clear log identification, especially with multiple data sources
Related reading
- Logical operators for Boolean indexing in Pandas
- Looking for a basic and up-to-date Cassandra tutorial
- Looking for a lightweight-ish distributed DB/cache
- Looking for a mature, scalable GraphDB with .NET or C++ binding
- Logging request/response messages when using HttpClient
- Logging requests being served by tensorflow serving model
- Logic Solving Algorithm for Sudoku in Java
- Lombok 1.18.0 and Jackson 2.9.6 not working together

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.