For production applications, use a connection pool to efficiently reuse database connections rather than opening a new one per request.
A good starting point: set your pool size to 5–10 connections per CPU on
your database instance. You can monitor live active connection counts on the
Performance tab.
const pool = new pg.Pool({ connectionString: "postgresql://admin:{password}@{instance-id}.pg.nearbase.app:5432/postgres?sslmode=require", max: 10, // maximum pool size idleTimeoutMillis: 30000, connectionTimeoutMillis: 2000,});