Skip to main content

psql

psql is a common CLI tool offering a variety of commands. You can download and install psql to connect to, manage, and query data in your Relyt databases.


Before you start

Ensure you have the following information:

  • The name of the Relyt database to connect

  • The domain name and port of the DW service unit that hosts the Relyt database

  • The name and password of a DW user that has access permissions to the Relyt database


Step 1. Download and install psql

This section guides you through downloading and installing psql from the official PostgreSQL website. You can also use other methods if preferred.

note

If you already have psql installed, skip this step.

  1. Download the appropriate version of PostgreSQL from the official PostgreSQL website.

  2. Open the downloaded .dmg file and follow the installation wizard to complete the installation.

  3. In your terminal, run the following commands to add psql to the PATH environment variable to make the psql command globally accessible.

    echo 'export PATH="/Library/PostgreSQL/<pg_version>/bin:$PATH"' >> ~/.zshrc
    source ~/.zshrc

    Replace <pg_version> with the version number of the PostgreSQL you have installed.

  4. Check that psql has successfully installed.

    psql --version

Step 2. Connect to your Relyt database

  1. In your terminal, run the following command:

    psql -h <endpoint_domain> -p <endpoint_port> -U <dw_user_name> -d <db_name>

    The following table describes related parameters.

    ParameterDescription
    endpoint_domainThe public endpoint for connecting to the Relyt DW service unit.
    endpoint_portThe port for connecting to the Relyt DW service unit. The default is 5432.
    dw_user_nameThe name of the DW user that connects to the Relyt DW service unit.
    db_nameThe name of the Relyt database to connect.

  2. Enter the password for the DW user as prompted.

    When you see the postgres=> is displayed, the connection is successful.



Step 3. Use psql to interact with Relyt

After the connection is established, you can interact with your Relyt database by using psql commands.

Here are some examples.

Example 1: List all roles/DW users in the current database, including their names, attributes, and privileges

\du

Information similar to the following is displayed:

Example 2: List databases in the connected DW service unit

\l

or

\list

Information similar to the following is displayed:


Example 3: List schemas in the current database

\dn

Information similar to the following is displayed:


Example 4: List tables in the current database

\dt

Information similar to the following is displayed:


info

To list tables in a specified schema, you can run \dt <schema_name>.*. Replace <schema_name> with the schema name.