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.
If you already have psql
installed, skip this step.
-
Download the appropriate version of PostgreSQL from the official PostgreSQL website.
-
Open the downloaded
.dmg
file and follow the installation wizard to complete the installation. -
In your terminal, run the following commands to add
psql
to thePATH
environment variable to make thepsql
command globally accessible.echo 'export PATH="/Library/PostgreSQL/<pg_version>/bin:$PATH"' >> ~/.zshrc
source ~/.zshrcReplace
<pg_version>
with the version number of the PostgreSQL you have installed. -
Check that
psql
has successfully installed.psql --version
Step 2. Connect to your Relyt database
-
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.
Parameter Description endpoint_domain The public endpoint for connecting to the Relyt DW service unit. endpoint_port The port for connecting to the Relyt DW service unit. The default is 5432. dw_user_name The name of the DW user that connects to the Relyt DW service unit. db_name The name of the Relyt database to connect.
-
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:
To list tables in a specified schema, you can run \dt <schema_name>.*
. Replace <schema_name>
with the schema name.