Skip to main content
Connect to a PostgreSQL cluster
Last update:

Connect to a PostgreSQL cluster

You can connect to a PostgreSQL cloud database cluster by DNS address, private IP address, and public IP address.

We recommend connecting by DNS address because DNS addresses correspond to node roles and lead to the actual IP addresses of the master and replicas. IP addresses correspond to specific nodes. If the master is unavailable, one of the replicas will assume its role, the master's IP address will change, and the IP connection will stop working.

If the cluster is connected to a private subnet and you want to work with it via DNS, connect the cluster subnet to a cloud router with access to the external network. Use the instructions Set up Internet access through the cloud router.

If the cluster is connected to a private network and you need to configure access to the node from the Internet, connect a public IP address.

Ports

Use ports to connect to PostgreSQL:

  • 5433 — port for connecting to the selected node via connection pooler — allows to reduce the load on PostgreSQL;
  • 5432 is the port to connect directly to the PostgreSQL process.

Ways of connection

  • through the psql terminal client;
  • through graphical database management tools: pgAdmin or an office suite with ODBC or JDBC support;
  • from program code with and without SSL.

Connection with SSL certificate is available for all methods.

View the address for connection

  1. In the Control panel, on the top menu, click Products and select Cloud Databases.
  2. Open the Active tab.
  3. Open the Database Cluster page → Connection tab.
  4. In the Addresses to connect block, look up the address.

Connect with SSL

Connecting using TLS/SSL encryption provides a secure connection between your server and the database cluster.

  1. Download the root certificate and place it in the ~/.postgresql/ folder:

    mkdir -p ~/.postgresql/
    wget https://storage.dbaas.selcloud.ru/CA.pem -O ~/.postgresql/root.crt
    chmod 0600 ~/.postgresql/root.crt
  2. Connect to the cluster:

    psql "host=<host>
    port=<port>
    dbname=<database_name>
    user=<database_user_name>
    sslmode=verify-ca"

    Specify:

    • <host> — DNS address of the node;
    • <port> — port to connect to;
    • <database_name> — database name;
    • <database_user_name> — database user name.

Connect without SSL

  1. Open the CLI.

  2. Connect to the cluster:

    psql "host=<host>
    port=<port>
    dbname=<database_name>
    user=<database_user_name>
    --sslmode=disable"

    Specify:

    • <host> — DNS address of the node;
    • <port> — port to connect to;
    • <database_name> — database name;
    • <database_user_name> — database user name.