Skip to content

cap postgres connections at 1h#27

Merged
tom-pang merged 1 commit intomainfrom
max_conn_lifetime
Mar 13, 2026
Merged

cap postgres connections at 1h#27
tom-pang merged 1 commit intomainfrom
max_conn_lifetime

Conversation

@tom-pang
Copy link

@tom-pang tom-pang commented Mar 12, 2026

Problem: we grab the extension age for things like pginsights etc via
the postgres_exporter. But, the extension version changes via
session_preload_libraries for new connections only, which means our
metrics are wrong as postgres_exporter keeps connections open for a very
long time.

Solution: set max connection lifetime to an hour - at the hour
mark, sql.DB closes a connection after a query returns it to the pool
and opens a new connection.

**Problem**: we grab the extension age for things like pginsights etc via
the postgres_exporter. But, the extension version changes via
`session_preload_libraries` for new connections only, which means our
metrics are wrong as postgres_exporter keeps connections open for a very
long time.

**Solution**: set max connection lifetime to an hour - at the hour
mark, `sql.DB` closes a connection after a query returns it to the pool
and opens a new connection.
@tom-pang tom-pang requested a review from a team as a code owner March 12, 2026 15:44
@tom-pang tom-pang changed the title Set ConnMaxLifetime on exporter DB connection cap postgres connections at 1h Mar 12, 2026
@tom-pang tom-pang merged commit 4354227 into main Mar 13, 2026
8 checks passed
@tom-pang tom-pang deleted the max_conn_lifetime branch March 13, 2026 11:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants