Serverless-postgres is a wrapper for node-postgres (pg) designed for serverless/FaaS environments like AWS Lambda. Current stable version is 2.1.2, released via semantic-release. It manages database connections to prevent 'too many clients' errors by garbage collecting zombie connections and retrying with backoff on failure. Key differentiators: connection filtering via application_name (v2+), automatic connection cleanup, and configurable retry delays. Unlike raw pg, it addresses connection pooling issues in serverless contexts.
npm install serverless-postgresNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Basic usage of serverless-postgres in an AWS Lambda handler: create client outside handler, connect, query, clean connections.
Update existing clients to set application_name explicitly, or use v1.x if filtering is not desired.
If you rely on clean() to kill all idle connections without filtering, set application_name to null or adjust configuration.
Set a custom application_name in client config to avoid naming collisions.
Set configuration before calling .connect(), or call .connect() again after .setConfig().
Ensure PostgreSQL is running and correct host/port are supplied.
Ensure client.clean() is called after each invocation. Increase max_connections if needed. Use connection filtering (v2+).
Run npm install pg