Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Neon · Const

Direct connection

A direct connection connects straight to Postgres without PgBouncer. Use it for stable, long-lived sessions and operations that require session state, such as migrations or LISTEN/NOTIFY.

How it works

A direct connection goes straight to Postgres without PgBouncer. Use its connection string when a workflow needs a stable, long-lived session or functionality that pooling does not support; ordinary high-concurrency application traffic should use the pooled endpoint instead.

Syntax

postgresql://user:password@endpoint.region.aws.neon.tech/dbname?sslmode=require

Key points

  • It reaches the PostgreSQL database directly and bypasses Neon’s connection pooler.
  • Choose it when the client must retain a stable session over the operation’s lifetime.
  • Migration tools are a documented direct-connection use case.
  • Concurrent index creation is listed as an operation requiring a direct connection.
  • Use a direct session when temporary tables or prepared statements must persist between queries.

Common mistakes

  • Direct connections consume the compute's PostgreSQL connection capacity, so high-concurrency application traffic can exhaust the available limit.

Example: Read a direct connection URL

const directUrl = process.env.DATABASE_URL_UNPOOLED;
if (!directUrl) throw new Error("DATABASE_URL_UNPOOLED is required");

console.log(directUrl);

Reads the direct, unpooled PostgreSQL connection string commonly used for schema operations.

When to use it

Schema changes

Run Prisma, Drizzle, or Django schema migrations.

Concurrent index creation

Execute CREATE INDEX CONCURRENTLY.

Session-dependent workflows

Maintain LISTEN/NOTIFY or other session-level behavior.

Interview questions

QWhat is a Neon direct connection?

A direct connection connects straight to Postgres without PgBouncer. It is appropriate for stable, long-lived connections and operations such as migrations or session-dependent features.

Follow-up: What should a highly concurrent application usually use instead? A pooled connection, identified by a hostname containing -pooler, because pooling supports many concurrent connections more efficiently.

QWhen should direct connections be used?

Use a direct connection for schema migrations, CREATE INDEX CONCURRENTLY, LISTEN/NOTIFY, temporary tables, or prepared statements that must work across multiple queries. These operations depend on connection or session behavior that pooling may not preserve.

Follow-up: Why can temporary tables be problematic through pooling? A later statement may be handled by a different backend session, so the temporary table is unavailable.

QWhat is the main scalability limitation of a direct connection?

Direct connections are bounded by PostgreSQL's max_connections setting, whose value depends on the compute size. Therefore, they are not the right default for workloads that create many concurrent connections.

Follow-up: How can the connection limit be avoided for application concurrency? Use Neon's pooled endpoint, whose hostname includes -pooler.

  • Pooled connection
  • PgBouncer
  • Connection pooling
  • max_connections
  • Schema migrations
  • LISTEN / NOTIFY

Source: Choosing your connection method. Checked 2026-10-16.