Skip to main content

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.

  1. Request bastion access here.
  2. 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
    
  3. Once connected to the bastion, open pgAdmin -> right click Servers -> Register -> Server.

  4. Enter a Name and un-tick Connect now?.

  5. 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
    
  6. Click Save.

  7. Open a terminal and run:

    az account get-access-token --resource-type oss-rdbms --query accessToken -o tsv
    
  8. 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.

  1. Request bastion access here.
  2. Open terminal and run:

    ssh bastion-prod.platform.hmcts.net
    
  3. 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"
    
  4. 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
```
This page was last reviewed on 14 March 2024. It needs to be reviewed again on 14 March 2025 by the page owner platops-build-notices .
This page was set to be reviewed before 14 March 2025 by the page owner platops-build-notices. This might mean the content is out of date.