import pg from 'pg'; import 'dotenv/config'; import { log } from '../log.js'; export const pool = new pg.Pool({ connectionString: process.env.DATABASE_URL, max: 10, idleTimeoutMillis: 30_000 }); // An idle pooled client can emit 'error' (DB restart, replication failover on // the .215 cluster). With no listener, EventEmitter throws and the process // crashes. Log and let pg discard the dead client; the pool reconnects lazily. pool.on('error', (err) => { log.error({ err }, 'idle pg client error'); });