Skip to main content

How to connect to a Database Lab clone

Direct connection (psql)​

GUI​

  1. From the Database Lab clone page under section Connection info copy psql connection string field contents by clicking the Copy button. Database Lab clone page / psql connection string
  2. In terminal type psql and paste 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've set during clone creation.
  4. Test established connection by listing tables in the database with \d command. Terminal / psql

CLI​

Before you run any commands, install Database Lab CLI and initialize configuration. For more information, see Install and initialize Database Lab 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 password you've 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 established connection by listing tables in the database with \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've set during clone creation. CloudBeaver / New connection
  5. Test the connection by fetching tables. CloudBeaver / Tables

SSH port forwarding​

tip

SSH keys need to be on the server with the Database Lab engine to use this connection option.

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 tab of terminal 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 tab of terminal type psql and paste 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 password you've set during clone creation.
  6. Test established connection by fetching the list of tables with \d command. Terminal / psql with port forward

CLI​

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

Reference​

Connection​

  1. In the first tab of terminal 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 password you've 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 established connection by listing tables in the database with \d command.