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

Neon · Const

Connection string

A Neon connection string is a standard PostgreSQL URL containing the selected role, password, hostname, and database name. Obtain it from the Console or CLI, store it as DATABASE_URL, and pass it to a PostgreSQL client.

How it works

A Neon connection string is a PostgreSQL URL containing the selected role, password, compute hostname, and database name. Copy it from the Console's Connect to your branch modal, store it in an environment variable such as DATABASE_URL, and pass that value to a PostgreSQL driver.

Syntax

postgresql://[role]:[password]@[hostname]/[database]?sslmode=require&channel_binding=require

Returns

A PostgreSQL connection URL containing credentials and the selected Neon database endpoint details.

Key points

  • In the Console, select the branch, compute, database, and role; Neon then constructs the URL.
  • DATABASE_URL is the conventional environment variable for supplying the URL to frameworks and application code.
  • The value copied from Connect can be used directly as the application's DATABASE_URL.
  • The CLI command can target a database on any project branch rather than only the default branch.

Common mistakes

  • Treat the URL as a secret because it contains the selected role's password; do not hardcode it in source code.
  • A pooled URL uses the -pooler host suffix and is intended for clients that benefit from connection pooling.

Example: Connect with DATABASE_URL

import os
import psycopg

with psycopg.connect(os.environ["DATABASE_URL"]) as conn:
    with conn.cursor() as cur:
        cur.execute("select 1")
        print(cur.fetchone()[0])

Reads the Neon URL from DATABASE_URL and uses it to open a PostgreSQL connection.

When to use it

Application database configuration

Configure an application or framework that reads DATABASE_URL.

Terminal-based connection retrieval

Use the CLI to target a branch, database, and role.

Pooled serverless connections

Handle high-concurrency application workloads with the pooler endpoint.

Interview questions

QWhat information does a Neon connection string contain?

It is a standard PostgreSQL URL containing the role, password, hostname, and database name. Applications commonly store it in DATABASE_URL and pass it to their PostgreSQL driver.

Follow-up: How would you choose between pooled and direct access? Use pooled access for many concurrent application connections; use direct access for migrations and session-level features.

QHow do you obtain a Neon connection string?

The Console constructs the URL after you choose a branch, compute, database, and role in the Connect to your branch modal. The CLI can also produce one with the neon connection-string command.

Follow-up: What CLI option changes the connection mode? --pooled adds the -pooler suffix, enabling connection pooling for clients using that URL.

QWhen should an application use pooled versus direct connections?

Use a pooled connection string when an application opens many concurrent connections. Use a direct connection for migrations and features that depend on session-level behavior.

Follow-up: Why should the URL be kept outside source code? It contains the role password, so committing it can expose database credentials.

  • DATABASE_URL
  • neon connection-string
  • pooled connection string
  • direct connection string
  • Connect to your branch

Source: Connect from any application - Neon Docs. Checked 2026-10-16.