Skip to main content
View rawEdit

How to connect to a DBLab clone

Direct connection (psql)​

GUI​

  1. From the DBLab clone page under section Connection info copy psql connection string field contents by clicking the Copy button. DBLab clone page / psql connection string
  2. In the terminal, type psql and paste the psql connection string field contents. Change the database name DBNAME parameter; you can always use postgres for the initial connection.
  3. Run the command and type the password you set during clone creation.
  4. Test the established connection by listing tables in the database with the \d command. Terminal / psql

CLI​

Before you run any commands, install the DBLab CLI and initialize the configuration. For more information, see Install and initialize DBLab CLI.

Reference​

Connection​

  1. Get the connection information for the clone:
dblab clone status CLONE_ID
{
"id": "CLONE_ID",
"status": {
"code": "OK",
"message": "Clone is ready to accept Postgres connections."
},
"db": {
"connStr": "host=HOSTNAME port=6000 user=USERNAME dbname=DBNAME",
"host": "HOSTNAME",
"port": "6000",
"username": "USERNAME",
"password": ""
},
...
}
  1. Connect to the clone using any Postgres client, e.g., psql. Change the database name DBNAME parameter; you can always use postgres for the initial connection. Type the password you set during clone creation:
psql "host=HOSTNAME port=6000 user=USERNAME dbname=DBNAME"
Password for user USERNAME:
psql (12.1, server 12.3)
Type "help" for help.

DBNAME=#
  1. Test the established connection by listing tables in the database with the \d command.

Direct connection (JDBC)​

  1. From the Database Lab clone page under section Connection info copy JDBC connection string field contents by clicking the Copy button. Database Lab clone page / JDBC connection string
  2. Use any Java-based PostgreSQL client to connect. For this guide, we will use CloudBeaver. Open the client.
  3. Click Connection / New connection / Custom. CloudBeaver / New connection
  4. Select the URL radio button and paste JDBC connection string field contents to JDBC URL. Change the database name DBNAME parameter; you can always use postgres for the initial connection. Change the password DBPASSWORD parameter to the password you set during clone creation. CloudBeaver / New connection
  5. Test the connection by fetching tables. CloudBeaver / Tables

DBLab in PostgresAI cloud​

A DBLab deployed to PostgresAI cloud gets no SSH keys of yours. Its clones listen on the server's localhost and are reached through an SSH tunnel as dblab-tunnel, a user that can only forward connections to the clone ports.

  1. Allow your SSH key: on the DBLab's page in the Console, in Clone access, select or add your key (organization admins), or run postgresai dblab access add <id or name> --public-key-file ~/.ssh/id_ed25519.pub. A change applies to new connections within a minute.
  2. Open the tunnel for the clone's port, for example 6000:
ssh -N -L 6000:127.0.0.1:6000 dblab-tunnel@<server ip>
  1. In a second terminal, connect to the clone through it:
psql "host=127.0.0.1 port=6000 user=<clone user> dbname=postgres"

SSH port forwarding​

tip

SSH keys need to be on the server with the DBLab Engine to use this connection option. For a DBLab in PostgresAI cloud, see DBLab in PostgresAI cloud.

GUI​

  1. From the Database Lab clone page under section Connection info copy SSH port forwarding field contents by clicking the Copy button. Database Lab clone page / SSH port forward
  2. In the first terminal tab, start SSH port forwarding using the provided command. Change USERNAME to match the username of your SSH key. Change the path to the SSH key if needed. Terminal / SSH port forward
  3. From the Database Lab clone page under section Connection info copy psql connection string (will work the same with JDBC). Database Lab clone page / psql connection string
  4. In the second terminal tab, type psql and paste the psql connection string field contents. Change the database name DBNAME parameter; you can always use postgres for the initial connection. Make sure that host=localhost, as we need to connect to the local port forwarding tunnel.
  5. Run the command and type the password you set during clone creation.
  6. Test the established connection by fetching the list of tables with the \d command. Terminal / psql with port forward

CLI​

Before you run any commands, install the DBLab CLI and initialize the configuration. For more information, see Install and initialize DBLab CLI.

Reference​

Connection​

  1. In the first terminal tab, start SSH port forwarding using the provided command. Change USERNAME to match the username of your SSH key. Change the path to the SSH key if needed.
ssh -NTML 6000:localhost:6000 ssh://USERNAME@HOSTNAME:22 -i ~/.ssh/id_rsa
  1. Get connection information of a clone.
dblab clone status CLONE_ID
{
"id": "CLONE_ID",
"status": {
"code": "OK",
"message": "Clone is ready to accept Postgres connections."
},
"db": {
"connStr": "host=HOSTNAME port=6000 user=USERNAME dbname=DBNAME",
"host": "HOSTNAME",
"port": "6000",
"username": "USERNAME",
"password": ""
},
...
}
  1. Connect to the clone using any Postgres client, e.g., psql launched from a second tab. Change the database name DBNAME parameter; you can always use postgres for the initial connection. Type the password you set during clone creation. Make sure that host=localhost, as we need to connect to the local port forwarding tunnel.
psql "host=localhost port=6000 user=USERNAME dbname=DBNAME"
Password for user USERNAME:
psql (12.1, server 12.3)
Type "help" for help.

DBNAME=#
  1. Test the established connection by listing tables in the database with the \d command.