Hitting connection limits using Pgbouncer

I am connecting to my Supabase DB from my NextJS app hosted on Vercel and am pretty consistently hitting the max client connections when using PgBouncer. I have upgraded my Supabase project to use the IPV4 extension so that I can use the dedicated pooler, and I am running an XL DB. I am wondering if I am just initializing the DB incorrectly and am not properly releasing connections to the pooler? I also recently switched to the vercel fluid ocmpute model in hopes of releiving this issue. The postgres url being used is that of the dedicated pooler on port 6543! Curious if I need to update the way I am connecting in order to release connections back to the pooler? Or if my app traffic is just needed a larger DB. Any guidance would be appreciated! Here is my current instantiation of the db client that I reference throughout my code:
import { drizzle } from 'drizzle-orm/postgres-js';
import postgres from 'postgres';

const schema = {
...baseSchemas,
...relations,
};

if (!process.env.POSTGRES_URL) {
throw new Error('POSTGRES_URL is not defined');
}


const client = postgres(process.env.POSTGRES_URL, {
prepare: false,
max: 1,
idle_timeout: 15,
});

export const db = drizzle(client, { schema });
import { drizzle } from 'drizzle-orm/postgres-js';
import postgres from 'postgres';

const schema = {
...baseSchemas,
...relations,
};

if (!process.env.POSTGRES_URL) {
throw new Error('POSTGRES_URL is not defined');
}


const client = postgres(process.env.POSTGRES_URL, {
prepare: false,
max: 1,
idle_timeout: 15,
});

export const db = drizzle(client, { schema });
1 Reply
Misc
Misc5d ago
did you ever figure this out? im running into the same issue

Did you find this page helpful?