fix: configure postgres idle timeout and connection recycling for Railway

Railway proxy closes idle DB connections after ~60s, causing
CONNECTION_CLOSED errors on stale sockets. Set idle_timeout=20s and
max_lifetime=5m so postgres-js recycles connections before they die.

Also fix sendCommand to fall back to persistent device ID on reconnect.
This commit is contained in:
Sanju Sivalingam
2026-02-18 13:56:34 +05:30
parent 3bab84f611
commit 88af77ddc7
4 changed files with 13 additions and 3 deletions

View File

@@ -5,6 +5,10 @@ import { env } from '$env/dynamic/private';
if (!env.DATABASE_URL) throw new Error('DATABASE_URL is not set');
const client = postgres(env.DATABASE_URL);
const client = postgres(env.DATABASE_URL, {
idle_timeout: 20,
max_lifetime: 60 * 5,
connect_timeout: 10
});
export const db = drizzle(client, { schema });