Skip to content

feat: configure explicit Postgres connection pool and timeouts#114

Merged
rubenhensen merged 2 commits into
mainfrom
feat/db-pool-config
Jul 1, 2026
Merged

feat: configure explicit Postgres connection pool and timeouts#114
rubenhensen merged 2 commits into
mainfrom
feat/db-pool-config

Conversation

@rubenhensen

Copy link
Copy Markdown
Contributor

Closes #100.

Gives the app's Postgres client explicit, env-tunable pool sizing and timeouts. Previously src/lib/server/db/index.ts used postgres(env.DATABASE_URL) with library defaults (notably no connect/idle timeouts), and the pool couldn't be sized against Postgres max_connections across replicas.

Changes

  • db/index.ts now sets max, idle_timeout, connect_timeout, and max_lifetime, each overridable via env (DB_POOL_MAX, DB_IDLE_TIMEOUT, DB_CONNECT_TIMEOUT, DB_MAX_LIFETIME) with sensible defaults.
  • .env.example documents the new optional knobs.

Already covered

The other half of #100 — the migration script using a single short-lived connection — was already in place: scripts/migrate.ts uses postgres(DATABASE_URL, { max: 1 }) and calls client.end(). No change needed there.

@dobby-coder

dobby-coder Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

On it, @rubenhensen! I'm reviewing PR #114 (Postgres pool sizing and timeouts) for correctness and rule-compliance now — I'll post a consolidated review shortly.

@dobby-coder dobby-coder Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approve — clean, well-scoped change.

Review: intFromEnv correctly falls back on unset/empty/non-numeric/zero/negative/float input; the four postgres.js options (max, idle_timeout, connect_timeout, max_lifetime) are valid for postgres@3.4.x, and the .env.example defaults match the code (10 / 20 / 10 / 1800). Build (vite) OK and all 83 unit tests pass.

Rule compliance: conventional-commit title (feat:), non-draft, Closes #100 present, PR body matches the delivered diff. No violations found across the rule set.

Nit (non-blocking): a small unit test pinning intFromEnv's fallback branches would lock in the behaviour that was verified manually here — worth adding if you touch this again.

@dobby-coder

dobby-coder Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Reviewed and approved! Everything looks solid — conventional title, closes #100, intFromEnv fallbacks are correct, postgres.js option names check out for 3.4.x, and the .env.example defaults match the code. All 83 unit tests pass.

One non-blocking nit in the review: it'd be nice to have a unit test covering the fallback branches of intFromEnv, but that's not a blocker.

Review: approved

@rubenhensen

Copy link
Copy Markdown
Contributor Author

Thanks @dobby-coder — added tests/unit/db-pool.test.ts covering intFromEnv's branches (valid int, unset, empty, non-numeric, zero/negative, float fallback). intFromEnv is now exported; the test stubs postgres/drizzle/$env so importing the db module doesn't open a connection. 6/6 pass locally.

@rubenhensen rubenhensen merged commit 7d638cb into main Jul 1, 2026
14 checks passed
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.

Database: configure explicit Postgres connection pool + timeouts

1 participant