I'm switching our Drizzle connection driver from node-postgres to postgres-js because our app runs in a serverless environment. The same connection string that worked before now times out.
The main issue is that I can (using the exact connection code that Supabase instructs for connecting with Drizzle) connect fine to my database if I use the 5432 port (Sessions mode), but the second I change that port to 6543, the connection times out. This exact setup with the correct 6543 port worked just fine with node-postgres.
Additional context:
Here's my connection logic:
import { PRIVATE_DATABASE_CERT } from '$env/static/private';
import postgres from 'postgres';
import { drizzle } from 'drizzle-orm/postgres-js';
import * as schema from './schema';
import * as relations from './relations';
const client = postgres(`postgres://<DB_USERNAME>:${encodeURIComponent("<DB_PASSWORD>")}@db.<PROJECT_ID>.supabase.co:6543/postgres`, {
prepare: false,
ssl: {
ca: PRIVATE_DATABASE_CERT,
},
max: 1,
idle_timeout: 20,
max_lifetime: 60 * 30,
});
const db = drizzle({
client,
schema: { ...schema, ...relations },
});
export default db;
Please help!
The user is experiencing a timeout issue when switching from node-postgres to postgres-js in a serverless environment. The connection works on port 5432 (Sessions mode) but times out on port 6543 (Transaction mode). The setup previously worked with node-postgres.