Migration Assistance - Get expert help migrating your business workloads to Neon.
Docs/Connect/Connect from any app

Connect from any application

Learn how to connect to Neon from any application

What you will learn:

  • Where to find database connections details

  • Where to find example connection snippets

  • Protocols supported by Neon

Database connection details

When connecting to Neon from an application or client, you connect to a database in your Neon project. In Neon, a database belongs to a branch, which may be the default branch of your project (main) or a child branch.

You can find the connection details for your database in the Connection Details widget on the Neon Dashboard. Select a branch, a compute, a database, and a role. A connection string is constructed for you.

Connection details widget

Neon supports pooled and direct connections to the database. Use a pooled connection string if your application uses a high number of concurrent connections. For more information, see Connection pooling.

A Neon connection string includes the role, password, hostname, and database name.

postgresql://alex:AbC123dEf@ep-cool-darkness-123456.us-east-2.aws.neon.tech/dbname?sslmode=require
             ^    ^         ^                                               ^
       role -|    |         |- hostname                                     |- database
                  |
                  |- password

note

The hostname includes the ID of the compute, which has an ep- prefix: ep-cool-darkness-123456. For more information about Neon connection strings, see connection string.

You can use the details from the connection string or the connection string itself to configure a connection. For example, you might place the connection details in an .env file, assign the connection string to a variable, or pass the connection string on the command-line.

.env file

PGHOST=ep-cool-darkness-123456.us-east-2.aws.neon.tech
PGDATABASE=dbname
PGUSER=alex
PGPASSWORD=AbC123dEf
PGPORT=5432

Variable

DATABASE_URL="postgresql://alex:AbC123dEf@ep-cool-darkness-123456.us-east-2.aws.neon.tech/dbname?sslmode=require"

Command-line

psql postgresql://alex:AbC123dEf@ep-cool-darkness-123456.us-east-2.aws.neon.tech/dbname?sslmode=require

note

Neon requires that all connections use SSL/TLS encryption, but you can increase the level of protection by configuring the sslmode. For more information, see Connect to Neon securely.

Where can I find my password?

It's included in your Neon connection string, which you can find in the Connection Details widget on your Project Dashboard.

What port does Neon use?

Neon uses the default Postgres port, 5432.

Connection examples

The Connection Details widget on the Neon Dashboard also provides connection examples for different frameworks and languages, constructed for the branch, database, and role that you select.

Language and framework connection examples

See our frameworks and languages guides for more connection examples.

Network protocol support

Neon projects provisioned on AWS support both IPv4 and IPv6 addresses. Neon projects provisioned on Azure support IPv4.

Additionally, Neon provides a serverless driver that supports both WebSocket and HTTP connections. For further information, refer to our Neon serverless driver documentation.

Connection notes

  • Some older client libraries and drivers, including older psql executables, are built without Server Name Indication (SNI) support and require a workaround. For more information, see Connection errors.
  • Some Java-based tools that use the pgJDBC driver for connecting to Postgres, such as DBeaver, DataGrip, and CLion, do not support including a role name and password in a database connection string or URL field. When you find that a connection string is not accepted, try entering the database name, role, and password values in the appropriate fields in the tool's connection UI when configuring a connection to Neon. For examples, see Connect a GUI or IDE.

Need help?

Join our Discord Server to ask questions or see what others are doing with Neon. Users on paid plans can open a support ticket from the console. For more details, see Getting Support.

Last updated on

Was this page helpful?