Skip to content

fix: keep postgres connections alive with heartbeat#797

Merged
harshsingh1002 merged 4 commits intomainfrom
kant777-patch-2
Sep 19, 2025
Merged

fix: keep postgres connections alive with heartbeat#797
harshsingh1002 merged 4 commits intomainfrom
kant777-patch-2

Conversation

@kant777
Copy link
Copy Markdown
Contributor

@kant777 kant777 commented Sep 19, 2025

Harden Postgres connection handling to avoid insert timeouts after idle periods.

Details

Pool settings:

  • MaxOpenConns=25, MaxIdleConns=20 to keep a warm stash.

  • ConnMaxLifetime=0 disables age-based churn.

  • ConnMaxIdleTime=0 prevents idle reaping. Ensures the pool never drops healthy connections.

Heartbeat goroutine:

  • Runs db.PingContext every 2 minutes.

  • Keeps at least one connection active, preventing k8s/LB/NAT or Postgres from closing all idle sessions.

  • Interval chosen < common infra idle timeout (~10m).

Why

Without this, long quiet gaps drained the pool; the next insert had to open a new conn (dial + TLS + auth) inside the 5s insert deadline → context deadline exceeded.
These changes ensure a live connection is always available, so inserts stay within the 5s budget even after idle periods.

@kant777 kant777 changed the title Update postgres.go fix: Update postgres.go Sep 19, 2025
@kant777 kant777 changed the title fix: Update postgres.go fix update postgres.go Sep 19, 2025
@kant777 kant777 changed the title fix update postgres.go fix: update postgres.go Sep 19, 2025
@kant777 kant777 changed the title fix: update postgres.go fix: keep postgres connections alive with heartbeat Sep 19, 2025
Comment thread cl/singlenode/payloadstore/postgres.go Outdated
Comment thread cl/singlenode/payloadstore/postgres.go Outdated
@harshsingh1002 harshsingh1002 merged commit 61a7e8f into main Sep 19, 2025
5 checks passed
@harshsingh1002 harshsingh1002 deleted the kant777-patch-2 branch September 19, 2025 17:01
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.

4 participants