Application database configuration
Configure an application or framework that reads DATABASE_URL.
Neon · Const
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.
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.
postgresql://[role]:[password]@[hostname]/[database]?sslmode=require&channel_binding=requireA PostgreSQL connection URL containing credentials and the selected Neon database endpoint details.
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.
Configure an application or framework that reads DATABASE_URL.
Use the CLI to target a branch, database, and role.
Handle high-concurrency application workloads with the pooler endpoint.
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.
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.
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_URLneon connection-stringpooled connection stringdirect connection stringConnect to your branch