Serverless request handling
A serverless function opens a fresh database connection for each request.
Neon · Const
A pooled Neon connection string routes through PgBouncer and has -pooler in its hostname. Use it by default for serverless applications and high-concurrency workloads.
A pooled Neon connection string targets Neon's PgBouncer pooler rather than Postgres directly. Its hostname contains the -pooler suffix, and the pooler multiplexes many client connections into a smaller set of database connections, making the string suitable for serverless and other high-concurrency workloads.
postgresql://user:pass@ep-endpoint-id-pooler.region.aws.neon.tech/database?sslmode=require&channel_binding=require-pooler in the hostname.pg_dump, and session-oriented features such as LISTEN/NOTIFY.const connectionString = process.env.DATABASE_URL;
if (!connectionString?.includes("-pooler")) {
throw new Error("Use a pooled Neon connection string");
}
console.log(connectionString);Reads a pooled Neon connection string from an environment variable and verifies its hostname marker.
A serverless function opens a fresh database connection for each request.
An application must accommodate many simultaneous client connections.
A web framework creates many short-lived database connections.
The pooled string routes traffic through PgBouncer and can handle up to 10,000 concurrent client connections. It is intended for serverless applications and workloads that create many short-lived connections.
Follow-up: How can you identify one? Its hostname contains -pooler after the endpoint identifier.
In the Neon Console, open Connect, choose the branch, compute, database, and role, enable Connection pooling, and copy the resulting string. The pooled hostname includes -pooler.
Follow-up: How can an existing string be converted? Add -pooler after the ep-... endpoint ID.
Use a direct connection for migrations, pg_dump, and LISTEN/NOTIFY, because those operations require direct or session-oriented database behavior. Use the pooled endpoint for ordinary serverless application traffic.
Follow-up: What does the pooler do internally? It multiplexes client connections into a smaller number of actual Postgres connections in transaction mode.
direct connectionConnection poolingPgBouncerConnection pooling toggleNeon Console