How to use HikariCP with QuestDB without resetting the connection all the time?

I’m trying to use HikariCP JDBC pool with QuestDB instead of PostgreSQL like this:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>public static void main(String[] args) {
HikariConfig config = new HikariConfig();
config.setJdbcUrl("jdbc:postgresql://localhost:8812/qdb");
config.setUsername("admin");
config.setPassword("quest");
config.setMaxLifetime(60000);
config.setMaximumPoolSize(10);
// Create the DataSource
HikariDataSource dataSource = new HikariDataSource(config);
while (true) {
// Use the DataSource to get a connection
try (Connection connection = dataSource.getConnection();
Statement statement = connection.createStatement();
ResultSet resultSet = statement.executeQuery("SELECT now()")) {
// Process the result
while (resultSet.next()) {
System.out.println(resultSet.getString(1));
}
} catch (SQLException e) {
e.printStackTrace();
}
Os.sleep(10000);
}
}
</code>
<code>public static void main(String[] args) { HikariConfig config = new HikariConfig(); config.setJdbcUrl("jdbc:postgresql://localhost:8812/qdb"); config.setUsername("admin"); config.setPassword("quest"); config.setMaxLifetime(60000); config.setMaximumPoolSize(10); // Create the DataSource HikariDataSource dataSource = new HikariDataSource(config); while (true) { // Use the DataSource to get a connection try (Connection connection = dataSource.getConnection(); Statement statement = connection.createStatement(); ResultSet resultSet = statement.executeQuery("SELECT now()")) { // Process the result while (resultSet.next()) { System.out.println(resultSet.getString(1)); } } catch (SQLException e) { e.printStackTrace(); } Os.sleep(10000); } } </code>
public static void main(String[] args) {
    HikariConfig config = new HikariConfig();
    config.setJdbcUrl("jdbc:postgresql://localhost:8812/qdb");
    config.setUsername("admin");
    config.setPassword("quest");
    config.setMaxLifetime(60000);
    config.setMaximumPoolSize(10);

    // Create the DataSource
    HikariDataSource dataSource = new HikariDataSource(config);

    while (true) {
        // Use the DataSource to get a connection
        try (Connection connection = dataSource.getConnection();
             Statement statement = connection.createStatement();
             ResultSet resultSet = statement.executeQuery("SELECT now()")) {

            // Process the result
            while (resultSet.next()) {
                System.out.println(resultSet.getString(1));
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        Os.sleep(10000);
    }
}

My dependencies are

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code><dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
<version>6.0.0</version>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.7.3</version>
</dependency>
</code>
<code><dependency> <groupId>com.zaxxer</groupId> <artifactId>HikariCP</artifactId> <version>6.0.0</version> </dependency> <dependency> <groupId>org.postgresql</groupId> <artifactId>postgresql</artifactId> <version>42.7.3</version> </dependency> </code>
<dependency>
  <groupId>com.zaxxer</groupId>
  <artifactId>HikariCP</artifactId>
  <version>6.0.0</version>
</dependency>
<dependency>
  <groupId>org.postgresql</groupId>
  <artifactId>postgresql</artifactId>
  <version>42.7.3</version>
</dependency>

It seems working fine, I can query the db but I see in my QuestDB logs that something closes all the pooled connections after 59 seconds like this

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>2024-09-24T11:09:26.276729Z I pg-server connected [ip=127.0.0.1, fd=2241972929959]
...
2024-09-24T11:10:24.950787Z I pg-server scheduling disconnect [fd=2241972929959, reason=15]
2024-09-24T11:10:24.951148Z I pg-server disconnected [ip=127.0.0.1, fd=2241972929959, src=queue]
</code>
<code>2024-09-24T11:09:26.276729Z I pg-server connected [ip=127.0.0.1, fd=2241972929959] ... 2024-09-24T11:10:24.950787Z I pg-server scheduling disconnect [fd=2241972929959, reason=15] 2024-09-24T11:10:24.951148Z I pg-server disconnected [ip=127.0.0.1, fd=2241972929959, src=queue] </code>
2024-09-24T11:09:26.276729Z I pg-server connected [ip=127.0.0.1, fd=2241972929959]
...

2024-09-24T11:10:24.950787Z I pg-server scheduling disconnect [fd=2241972929959, reason=15]
2024-09-24T11:10:24.951148Z I pg-server disconnected [ip=127.0.0.1, fd=2241972929959, src=queue]

What is the way to use HikariCP with QuestDB so that the pooled connections stay opened and only the closed/invalid are evicted from the pool?

It does this, because you configured config.setMaxLifetime(60000);, which restricts the lifetime of a connection to 60 seconds. That means that a connection that was created 60 or more seconds ago, and is not currently checked out of the pool (i.e. in use), will be automatically closed. For contrast, the default value is 1800000 (30 minutes).

In other words, remove the setMaxLifetime setting, or at least set it a lot higher, or set it to 0 if you want to disable such eviction (which is BTW not recommended).

See also the documentation of maxLifetime (emphasis from original):

maxLifetime
This property controls the maximum lifetime of a connection in the
pool. An in-use connection will never be retired, only when it is
closed will it then be removed. On a connection-by-connection basis,
minor negative attenuation is applied to avoid mass-extinction in the
pool. We strongly recommend setting this value, and it should be
several seconds shorter than any database or infrastructure imposed
connection time limit.
A value of 0 indicates no maximum lifetime
(infinite lifetime), subject of course to the idleTimeout setting. The
minimum allowed value is 30000ms (30 seconds). Default: 1800000 (30
minutes)

1

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật