How to connect to a Database Lab clone
Direct connection (psql)​
GUI​
- From the Database Lab clone page under section Connection info copy psql connection string field contents by clicking the Copy button.
- In terminal type
psql
and paste psql connection string field contents. Change the database nameDBNAME
parameter, you can always usepostgres
for the initial connection. - Run the command and type the password you've set during clone creation.
- Test established connection by listing tables in the database with
\d
command.
CLI​
Before you run any commands, install Database Lab CLI and initialize configuration. For more information, see Install and initialize Database Lab CLI.
Reference​
- Command
dblab clone status
Connection​
- 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": ""
},
...
}
- Connect to the clone using any Postgres client, e.g. psql. Change the database name
DBNAME
parameter, you can always usepostgres
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=#
- Test established connection by listing tables in the database with
\d
command.
Direct connection (JDBC)​
- From the Database Lab clone page under section Connection info copy JDBC connection string field contents by clicking the Copy button.
- Use any Java-based PostgreSQL client to connect. For this guide, we will use CloudBeaver. Open the client.
- Click Connection / New connection / Custom.
- Select the URL radio button and paste JDBC connection string field contents to JDBC URL. Change the database name
DBNAME
parameter, you can always usepostgres
for the initial connection. Change the passwordDBPASSWORD
parameter to the password you've set during clone creation. - Test the connection by fetching tables.
SSH port forwarding​
tip
SSH keys need to be on the server with the Database Lab engine to use this connection option.
GUI​
- From the Database Lab clone page under section Connection info copy SSH port forwarding field contents by clicking the Copy button.
- 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. - From the Database Lab clone page under section Connection info copy psql connection string (will work the same with JDBC).
- In the second tab of terminal type
psql
and paste psql connection string field contents. Change the database nameDBNAME
parameter, you can always usepostgres
for the initial connection. Make sure thathost=localhost
, as we need to connect to the local port forwarding tunnel. - Run the command and type password you've set during clone creation.
- Test established connection by fetching the list of tables with
\d
command.
CLI​
Before you run any commands, install Database Lab CLI and initialize configuration. For more information, see Install and initialize Database Lab CLI.
Reference​
- Command
dblab clone status
Connection​
- 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
- 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": ""
},
...
}
- 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 usepostgres
for the initial connection. Type password you've set during clone creation. Make sure thathost=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=#
- Test established connection by listing tables in the database with
\d
command.