-
Notifications
You must be signed in to change notification settings - Fork 4
feat(postgres): add support for SetConnMaxLifetime #522
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
WalkthroughAdds a new ConnectionOptions field Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant CLI as CLI (flags)
participant Config as ConnectionOptions
participant Module as module.Open (logs)
participant DB as OpenSQLDB / *sql.DB
CLI->>Config: parse flags (includes conn-max-lifetime)
Config->>Module: pass ConnectionOptions
Module->>DB: OpenSQLDB(connectionOptions)
DB->>DB: sql.Open / connector setup
DB->>DB: SetConnMaxLifetime(conn-max-lifetime) %% applied if non-zero
DB-->>Module: return *sql.DB
Module-->>CLI: log "opening database connection" (includes conn-max-lifetime)
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes
Poem
Pre-merge checks and finishing touches✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Comment |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #522 +/- ##
==========================================
- Coverage 34.77% 27.63% -7.15%
==========================================
Files 139 162 +23
Lines 6061 6605 +544
==========================================
- Hits 2108 1825 -283
- Misses 3842 4669 +827
Partials 111 111 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Add configuration support for database connection max lifetime: - Add ConnMaxLifetime field to ConnectionOptions struct - Add postgres-conn-max-lifetime CLI flag (default: 0 - disabled) - Call SetConnMaxLifetime in OpenSQLDB when value is non-zero - Include ConnMaxLifetime in connection logging and String() output This allows configuring how long a connection may be reused before being closed and replaced, helping prevent stale connections and ensuring periodic connection refresh in the database pool.
ad4e39f to
0abea09
Compare
Summary
This PR adds support for configuring database connection max lifetime using
SetConnMaxLifetime.Changes
ConnMaxLifetimefield toConnectionOptionsstruct (bun/bunconnect/connect.go:23)--postgres-conn-max-lifetimeCLI flag with default value of 0 (disabled)SetConnMaxLifetime()call inOpenSQLDB()when value is non-zero (bun/bunconnect/connect.go:55-57)conn-max-lifetimeparameterBenefits
According to database/sql documentation,
SetConnMaxLifetimesets the maximum amount of time a connection may be reused. This helps:Usage
Test plan
--postgres-conn-max-lifetimeflag is available