PostgreSQL is an open source, object-relational database built with a focus on 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.
To connect to PostgreSQL database clusters from the command line, you need two things:
The database cluster's connection details, which tells your client how to connect to the cluster.
You can find a database cluster's connection details in the control panel. From the Databases page, click the name of the cluster to go to its Overview page.
In the Connection Details section, the drop-down menu has three options:
Connection parameters, which is meant for application configuration and is incompatible with clients like
Connection string, which is a condensed string that you can pass to a client on the command line. PostgreSQL's connection string documentation goes into detail on the structure, but the general format is
Flags, which is a complete
psql command that supplies the connection variables as individual flags.
We recommend the flags format because the readability can help if you want to customize the way you connect. The only required parameter is
sslmode, but PostgreSQL supports many options for customizing connections.
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-password to reveal the password.
To connect using the flags format, paste the entire command from the control panel in your terminal:
PGPASSWORD=your_password psql -U doadmin -h cluster-do-user-1234567-0.db.ondigitalocean.com -p 25060 -d defaultdb --set=sslmode=require
To connect using the connection string, pass the string from the control panel in quotes to
psql in your terminal:
When you connect successfully, your terminal changes to the
psql prompt, which displays the name of the database you're connected to: