---
title: "Connect to PostgreSQL"
description: "Use the correct host, port, database, role and SSL mode in an application or psql."
---

> Documentation Index
> Fetch the complete documentation index at: https://docs.pgnext.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Connect to PostgreSQL

Your compute must be ready, and you need permission to read its connection information. The PostgreSQL password is separate from your PG Next sign-in password.

## Get connection details

1. Open your project and select **Connect**.
2. Select the correct branch, compute, database and role.
3. Choose an external connection for a personal computer or an application outside the cluster. Kubernetes internal addresses require access from the appropriate network.
4. Check the host, port and SSL mode returned by the console. Use values for this compute; do not construct a host from the project name.
5. Copy the connection string. If the button says **Copy template**, the string does not yet contain a real password. Add it privately before use.

A connection string containing a password is a secret. Do not share it in chat, commit it to Git or put it in a frontend `VITE_*` variable.

## Use psql without putting a password in the command

Replace the illustrative values below with details from the console. This is not a real endpoint:

```sh
psql "host=HOST_FROM_CONSOLE port=PORT_FROM_CONSOLE dbname=DATABASE_FROM_CONSOLE user=ROLE_FROM_CONSOLE sslmode=SSL_MODE_FROM_CONSOLE" -W
```

Enter the password at the prompt. Do not assume all endpoints support the same TLS mode, or lower the SSL mode just to bypass a certificate error. If your application needs stronger security than the endpoint provides, stop and verify the configuration with the operator.

```sql
SELECT current_database(), current_user;
```

Both values should match your console selections. In an application, keep connection strings in server-side secret storage supported by your framework. Avoid exposing them in logs and error messages.

## Troubleshoot a connection

| Symptom | What to check |
| --- | --- |
| Timeout or connection refused | Is the compute running? Do the host and port match the connection type? Can your network reach it? |
| Password authentication failed | Are the PostgreSQL role and current password correct? Did you fill in the template password? |
| Database does not exist | Does the string name a database that exists in this compute? |
| SSL or certificate error | Verify the endpoint's SSL mode and certificate. Do not bypass verification to test quickly. |

Parameter syntax follows the [PostgreSQL libpq documentation](https://www.postgresql.org/docs/17/libpq-connect.html). PG Next TLS capabilities depend on the actual endpoint.

Source: https://docs.pgnext.dev/guides/connect/index.mdx
