diff --git a/src/lib/db/index.ts b/src/lib/db/index.ts index 223cf2b5..21e2efaa 100644 --- a/src/lib/db/index.ts +++ b/src/lib/db/index.ts @@ -18,8 +18,14 @@ const connectionString = process.env.DATABASE_URL!; // `max_lifetime` recycles connections every 30 minutes so any // per-connection state drift (prepared statements, GUCs) doesn't // accumulate forever. +// Larger pool in development because Next dev fans out (HMR refetches, +// multi-widget dashboards, React Query refetch-on-focus) and a single +// admin clicking around can saturate 20 slots. Production stays at the +// conservative 20 so we don't hammer postgres in a multi-replica deploy. +const POOL_MAX = process.env.NODE_ENV === 'development' ? 60 : 20; + const queryClient = postgres(connectionString, { - max: 20, + max: POOL_MAX, idle_timeout: 20, connect_timeout: 10, max_lifetime: 60 * 30,