© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
SupabaseS
Supabase•3mo ago•
1 reply
Shayokh

Repeatedly getting CONNECT_TIMEOUT and MaxClientsInSessionMode during local development.

🟢SSR🔢DB Connections🟡javascript
Hello. I am using Nextjs 16. During local development, when I call database from drizzle, I get a CONNECT_TIMEOUT or sometimes MaxClientsInSessionMode if I trigger Nextjs hot reload quickly. My initial guess was that I was probably creating a lot of connections during hot module reloads. Also I switched to transactional connect rather than session pooler based on this https://github.com/orgs/supabase/discussions/22305. So I implemented this Singleton pattern, which still doesn't work -

import { drizzle, type PostgresJsDatabase } from "drizzle-orm/postgres-js";
import postgres from "postgres";
import * as schema from "@/schemas/schema";

declare global {
  var database: PostgresJsDatabase<typeof schema> | undefined;
}

// Disable prefetch as it is not supported for "Transaction" pool mode
const client = postgres(process.env.DATABASE_URL as string, { prepare: false });
const instance = drizzle(client, { schema });

if (process.env.NODE_ENV !== "production") {
  global.database = instance;
}

export function getDB(): PostgresJsDatabase<typeof schema> {
  return global.database || instance;
}
import { drizzle, type PostgresJsDatabase } from "drizzle-orm/postgres-js";
import postgres from "postgres";
import * as schema from "@/schemas/schema";

declare global {
  var database: PostgresJsDatabase<typeof schema> | undefined;
}

// Disable prefetch as it is not supported for "Transaction" pool mode
const client = postgres(process.env.DATABASE_URL as string, { prepare: false });
const instance = drizzle(client, { schema });

if (process.env.NODE_ENV !== "production") {
  global.database = instance;
}

export function getDB(): PostgresJsDatabase<typeof schema> {
  return global.database || instance;
}


I am still getting this issue after every 5/6 consecutive calls to the database during Hot Module Refresh. What to do? Please help.
error.txt7.16KB
Supabase banner
SupabaseJoin
Supabase gives you the tools, documentation, and community that makes managing databases, authentication, and backend infrastructure a lot less overwhelming.
45,816Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

Failed to connect Session Pooler: MaxClientsInSessionMode
SupabaseSSupabase / help-and-questions
4mo ago
flutter can't connect on local development
SupabaseSSupabase / help-and-questions
8mo ago
Settings option not visible for org and project during local development
SupabaseSSupabase / help-and-questions
4mo ago
Local Development Issues
SupabaseSSupabase / help-and-questions
11mo ago