Schema changes
Run Prisma, Drizzle, or Django schema migrations.
Neon · Const
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.
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.
postgresql://user:password@endpoint.region.aws.neon.tech/dbname?sslmode=requireconst 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.
Run Prisma, Drizzle, or Django schema migrations.
Execute CREATE INDEX CONCURRENTLY.
Maintain LISTEN/NOTIFY or other session-level behavior.
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.
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.
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 connectionPgBouncerConnection poolingmax_connectionsSchema migrationsLISTEN / NOTIFY