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:
@@ -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 });
|
||||
|
||||
Reference in New Issue
Block a user