Hey! This content applies only to previous CARTO products

Please check if it's relevant to your use case. On October 2021 we released a new version of our platform.
You can learn more and read the latest documentation at docs.carto.com

Tutorials  /  Data Management  /  Connect Data

How to connect to your CARTO database from psql

Connecting to your CARTO database from psql.

We strongly recommend reading the Direct SQL Connection article to learn more about that feature before reading this one.

Introduction

With the Direct SQL Connection feature you can directly connect to your CARTO database from psql.

Configuration

Go to your terminal / command line and execute the following command:

psql "user={username} password={API key} host={hostname} port=5432 sslmode=verify-full sslcert=./certs/client.crt sslkey=./certs/client.key sslrootcert=./certs/server_ca.pem"

If you don’t want to use TLS certificates for client authentication, you need to change the sslmode parameter to verify-ca and you need to remove the sslcert and sslkey parameters.

Now you can access your CARTO database as you would do with any other PostgreSQL database.

For example: exectute the next command to describe a database table:

\d {tablename}