diff --git a/extensions/agroal/runtime/src/main/java/io/quarkus/agroal/runtime/DataSourceJdbcRuntimeConfig.java b/extensions/agroal/runtime/src/main/java/io/quarkus/agroal/runtime/DataSourceJdbcRuntimeConfig.java index 392903d7d3105f..d2c1528f877152 100644 --- a/extensions/agroal/runtime/src/main/java/io/quarkus/agroal/runtime/DataSourceJdbcRuntimeConfig.java +++ b/extensions/agroal/runtime/src/main/java/io/quarkus/agroal/runtime/DataSourceJdbcRuntimeConfig.java @@ -115,6 +115,15 @@ public interface DataSourceJdbcRuntimeConfig { */ Optional validationQuerySql(); + /** + * Forces connection validation prior to acquisition (foreground validation) regardless of the idle status. + *

+ * Because of the overhead of performing validation on every call, it’s recommended to rely on default idle validation + * instead, and to leave this to `false`. + */ + @WithDefault("false") + boolean validateOnBorrow(); + /** * Disable pooling to prevent reuse of Connections. Use this when an external pool manages the life-cycle * of Connections. diff --git a/extensions/agroal/runtime/src/main/java/io/quarkus/agroal/runtime/DataSources.java b/extensions/agroal/runtime/src/main/java/io/quarkus/agroal/runtime/DataSources.java index 3b8694dcc50252..a8b005fc4aa538 100644 --- a/extensions/agroal/runtime/src/main/java/io/quarkus/agroal/runtime/DataSources.java +++ b/extensions/agroal/runtime/src/main/java/io/quarkus/agroal/runtime/DataSources.java @@ -410,6 +410,7 @@ public boolean isValid(Connection connection) { } }); } + poolConfiguration.validateOnBorrow(dataSourceJdbcRuntimeConfig.validateOnBorrow()); poolConfiguration.reapTimeout(dataSourceJdbcRuntimeConfig.idleRemovalInterval()); if (dataSourceJdbcRuntimeConfig.leakDetectionInterval().isPresent()) { poolConfiguration.leakTimeout(dataSourceJdbcRuntimeConfig.leakDetectionInterval().get());