Connecting to Flexible Server
You can connect to the flexible server databases using a couple of methods outlined below. Either will work but using an application like pgAdmin is arguably a bit more user friendly than the command line.
Using pgAdmin
Note: This example shows how to connect to ccd-data-store in production. Replace any ccd specific values for whichever server you are connecting to.
- Request bastion access here.
Open terminal and run:
POSTGRES_HOST=ccd-data-store-api-postgres-db-v15-prod.postgres.database.azure.com ssh bastion-prod.platform.hmcts.net -L 5440:${POSTGRES_HOST}:5432
Once connected to the bastion, open pgAdmin -> right click
Servers
->Register
->Server
.Enter a Name and un-tick
Connect now?
.Go to
Connection
tab and enter the following values:Host name/address: ccd-data-store-api-postgres-db-v15-prod.postgres.database.azure.com Port: 5432 Maintenance database: ccd_data_store Username: DTS Platform Operations SC
Click
Save
.Open a terminal and run:
az account get-access-token --resource-type oss-rdbms --query accessToken -o tsv
In pgAdmin, select the connection from the panel. You will be prompted to enter a password. Paste in the token returned from the above command.
Note: You can use DTS Platform Operations
user for non-prod servers.
Using psql
Note: This example shows how to connect to ccd-data-store in production. Replace any ccd specific values for whichever server you are connecting to.
- Request bastion access here.
Open terminal and run:
ssh bastion-prod.platform.hmcts.net
Once connected to the bastion, run:
DB_HOST=ccd-data-store-api-postgres-db-v15-prod.postgres.database.azure.com DB_NAME=ccd_data_store DB_USER="DTS\ Platform\ Operations\ SC" export PGPASSWORD=$(az account get-access-token --resource-type oss-rdbms --query accessToken -o tsv) psql "sslmode=require host=${DB_HOST} dbname=${DB_NAME} user=${DB_USER} port=5432"
You will be presented with an interactive psql shell where you can run your sql queries.
Note: You can use DB_USER="DTS\ Platform\ Operations"
user for non-prod servers.
Note: You can run sql scripts using this method by appending -f
followed by the name of the sql script e.g.
```cmd
psql "sslmode=require host=${DB_HOST} dbname=${DB_NAME} user=${DB_USER} port=5432" -f script.sql
```