#2581·drogon

PostgreSQL reconnect retry interval should be configurable

Author: AhmadPayamaniCreated Sep 3, 2026Updated Sep 3, 2026
Labelsgood first issue

Description

When a PostgreSQL connection is lost, Drogon automatically attempts to reconnect every 1 second.

This can cause unnecessary CPU usage, connection attempts, and excessive logs when PostgreSQL is unavailable for an extended period.

I am using Drogon v1.9.13.

Current behavior

In orm_lib/src/DbClientImpl.cc, the reconnect is scheduled with:

cpp
loop->runAfter(1, [weakPtr, loop, closeConnPtr] {
    ...
});

As a result, when PostgreSQL is down, I see logs like:

Pg connection failed
Pg connection failed
Pg connection failed
Pg connection failed

approximately every second for each connection in the pool.

Expected behavior

It would be useful to have a configurable reconnect interval, for example:

"reconnect_interval": 5

The default could remain 1 second for backward compatibility.

Suggested implementation

Instead of hard-coding:

cpp
 loop->runAfter(1, [weakPtr, loop, closeConnPtr] {
    ...
});

the reconnect delay could be stored in the database client configuration:

cpp
loop->runAfter(reconnectInterval, [weakPtr, loop, closeConnPtr] {
    ...
});

This would allow applications with unstable or remote PostgreSQL servers to use a more appropriate retry interval.

Thanks!