How to Connect to PostgreSQL Database Clusters

Last verified 10 Jul 2026

PostgreSQL is an open source, object-relational database built for extensibility, data integrity, and speed. Its concurrency support makes it fully ACID-compliant, and it supports dynamic loading and catalog-driven operations to let users customize its data types, functions, and more.

Connect to DigitalOcean managed PostgreSQL database clusters from psql, GUI clients such as DataGrip, or other applications. Retrieve each cluster’s hostname, port, credentials, and TLS settings using the Control Panel, API, or CLI, then configure your client.

Retrieve Database Connection Details Using Automation

You can retrieve connection details using the DigitalOcean CLI (doctl) or the API.

Retrieve Database Connection Details via CLI

How to Retrieve Database Connection Details Using the DigitalOcean CLI
  1. Install doctl, the official DigitalOcean CLI.
  2. Create a personal access token and save it for use with doctl.
  3. Use the token to grant doctl access to your DigitalOcean account.
    doctl auth init
  4. Finally, run doctl databases connection. Basic usage looks like this, but you can read the usage docs for more details:
    doctl databases connection <database-cluster-id> [flags]

The following example retrieves the connection details for a database cluster with the ID f81d4fae-7dec-11d0-a765-00a0c91e6bf6:

doctl databases connection f81d4fae-7dec-11d0-a765-00a0c91e6bf6

Retrieve Database Connection Details via API

This API call retrieves the information about your database, including its connection details. The connection details are located in the returned connection JSON object.

How to Retrieve Database Connection Details Using the DigitalOcean API

Create a personal access token and save it for use with the API.

cURL

Send a GET request to https://api.digitalocean.com/v2/databases/{database_cluster_uuid}.

Using cURL:

curl -X GET \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $DIGITALOCEAN_TOKEN" \
  "https://api.digitalocean.com/v2/databases/9cc10173-e9ea-4176-9dbc-a4cee4c4ff30"

Go

Using Godo, the official DigitalOcean API client for Go:

import (
    "context"
    "os"

    "github.com/digitalocean/godo"
)

func main() {
    token := os.Getenv("DIGITALOCEAN_TOKEN")

    client := godo.NewFromToken(token)
    ctx := context.TODO()

    cluster, _, err := client.Databases.Get(ctx, "9cc10173-e9ea-4176-9dbc-a4cee4c4ff30")
}

Python

Using PyDo, the official DigitalOcean API client for Python:

import os
from pydo import Client

client = Client(token=os.environ.get("DIGITALOCEAN_TOKEN"))

get_resp = client.databases.get_cluster(database_cluster_uuid="a7a89a")

Retrieve PostgreSQL Cluster Connection Details Using the Control Panel

To retrieve your cluster’s connection details, go to the Databases page and select the cluster whose connection details you need. On the cluster’s Overview page, scroll to the Connection Details section.

Databases Overview screen showing connection string

In the Connection Details section, choose the network, database, user, and TLS settings to generate the connection details you need:

  • Public network and VPC network provide connection details for your cluster’s public and private hostnames. Only resources in the same VPC network as the cluster can connect using the private hostname.

  • The Database/Pool field updates the connection details for the selected database or connection pool.

  • The User field updates the connection details with the selected user credentials.

  • On PostgreSQL Standard Edition clusters, select Want maximum security? Download the CA certificate and use verify-full to update the connection details for full TLS certificate verification. Without this option, connection details return ssl: true and set the client sslmode parameter to require, which encrypts traffic in transit but does not verify the server identity. For setup steps, see Connect to the Cluster.

The Connection Details section showing the Want maximum security verify-full option selected.

Use the format menu in the Connection Details section to display the same connection information in one of three formats:

  • Connection parameters: Separate fields for username, password, host, port, database, and sslmode. Use this format when your client or application expects individual connection settings, such as DataGrip or pgAdmin.

  • Connection string: A single PostgreSQL URI (postgresql://user:password@host:port/database). Use this format when your client accepts a connection string on the command line or in an environment variable or application config file.

  • Flags: A complete psql command with connection values as environment variables and flags (-U, -h, -p, -d). Use this format to connect from a terminal with psql.

By default, the Control Panel doesn’t reveal the cluster’s password for security reasons. Click Copy to copy connection details with the password, or click show to reveal the password.

Download the CA Certificate

PostgreSQL Standard Edition clusters include a CA certificate you can download to verify the server identity when connecting with verify-full. PostgreSQL Advanced Edition clusters require TLS but do not currently provide a downloadable CA certificate or support verify-full.

To download the CA certificate, go to the Databases page and select the cluster whose CA certificate you want to download. On the cluster’s Overview page, in the Connection Details section, click Download CA certificate.

Databases connection details with Download CA Certificate selected

When you configure your client applications, save the certificate on your local system and reference its path in your connection settings. Each client application is configured differently, so check the documentation for the tool you use for more detail on setting up TLS connections.

Connect to the Cluster

This section describes how to connect to your cluster with psql or DataGrip and open a session in a database such as defaultdb.

To connect to a PostgreSQL database cluster using psql, do the following:

Copy connection details from the Control Panel and run psql using the Flags or Connection string format. Replace placeholder values with your credentials. On Standard Edition clusters using verify-full, also replace the path to your downloaded CA certificate.

Connect with sslmode=require (default)

By default, connection details return ssl: true and set the client sslmode parameter to require, which encrypts traffic in transit but does not verify the server identity. You do not need a CA certificate file for this mode.

Flags format: The Control Panel default flags command uses --set=sslmode=require, but that option does not configure TLS in psql. Set PGSSLMODE=require instead:

PGPASSWORD=<your-password> \
PGSSLMODE=require \
psql -U doadmin -h <your-cluster-hostname> -p 25060 -d defaultdb

Connection string: Pass the connection string from the Control Panel in quotes to psql, replacing <your-username>, <your-password>, and <your-cluster-hostname>:

psql "postgresql://<your-username>:<your-password>@<your-cluster-hostname>:25060/defaultdb?sslmode=require"
Connect with verify-full

These steps apply to PostgreSQL Standard Edition clusters only. PostgreSQL Advanced Edition clusters require TLS but do not currently provide a downloadable CA certificate or support verify-full.

Select Want maximum security? Download the CA certificate and use verify-full in the Control Panel to show connection details for full TLS certificate verification.

Flags format: Paste the entire command from the Control Panel into your terminal. Replace <your-password>, <path-to-ca-certificate>, and <your-cluster-hostname>:

PGPASSWORD=<your-password> \
PGSSLMODE=verify-full \
PGSSLROOTCERT=<path-to-ca-certificate> \
psql -U doadmin -h <your-cluster-hostname> -p 25060 -d defaultdb

Connection string: Pass the connection string from the Control Panel in quotes to psql. Replace <your-username>, <your-password>, <path-to-ca-certificate>, and <your-cluster-hostname>:

psql "postgresql://<your-username>:<your-password>@<your-cluster-hostname>:25060/defaultdb?sslmode=verify-full&sslrootcert=<path-to-ca-certificate>"

When you connect successfully, your terminal changes to the psql prompt, which displays the name of the database you’re connected to, like defaultdb=>.

At the psql prompt, you can change databases or users, execute SQL queries, and perform other database administration tasks. For common commands, see the SQL cheat sheet. For full reference, see the official psql documentation.

If you’re having trouble connecting to the database, you can troubleshoot the connection using our Support page, or you can reference PostgreSQL connection parameter documentation.

To connect to a PostgreSQL database cluster using DataGrip, do the following:

To connect to your PostgreSQL database using a standard TCP/IP connection, open DataGrip, click File, New Data Source, and then select PostgreSQL from the list of options.

In the Data Sources and Drivers window, enter a descriptive name for the connection in the Name field.

In the General tab, use the information from your cluster’s Connection Details to fill out the necessary fields.

DataGrip Data Sources and Drivers window with connection information

To connect using TLS, click the SSH/SSL tab. Select the Use SSL option. In the Mode field, select Require. You do not need a CA certificate file for this mode, which matches the default client sslmode setting in connection details (require).

DataGrip Data Sources and Drivers SSL tab with connection information

On PostgreSQL Standard Edition clusters, to use full TLS certificate verification (verify-full), download the CA certificate, enter its path in the CA File field, and change Mode to Verify full.

When finished, click Test Connection. If you receive a message with a green checkmark, click OK in the Data Sources and Drivers window to save the connection configuration. DataGrip automatically connects to the database. If you receive an error, recheck that you entered your credentials correctly and then retry the test.

If you’re having trouble connecting to the database, you can troubleshoot the connection using our Support page, or you can reference DataGrip’s connection documentation.

We can't find any results for your search.

Try using different keywords or simplifying your search terms.