Install the Cloud Foundry CLI (if needed)
If you don’t already have the cf CLI on your machine, follow the installers or download a compressed binary from the V8 CLI Installation Guide:
https://github.com/cloudfoundry/cli/wiki/V8-CLI-Installation-Guide#installers-and-compressed-binaries.
Authenticate
Log in to your Cloud Foundry organization via SSO:
cf login --sso -a <CF_API_ENDPOINT>
You can find <CF_API_ENDPOINT> under Overview of your Subaccount in the BTP cockpit.
Enable SSH on your app
Using the application name defined in your downloaded vars.yml or the whole name of application including postfix of -app then run:
cf enable-ssh <app-id from vars.yml>-app
Restart the app
Apply the SSH setting by restarting your application:
cf restart <app-id from vars.yml>-app
SSH into the container
Once the app is running again, open a shell on the instance:
cf ssh <app-id from vars.yml>-app
Extract database connection details
Inside the container, run this to print the host, port, username and database name:
echo $VCAP_SERVICES \
| jq -r '.["postgresql-db"][0].credentials
| "REMOTE_HOST=\(.hostname)\nREMOTE_PORT=\(.port)\nDB_USER=\(.username)\nDB_NAME=\(.dbname)"'
Alternatively, you can copy these values directly from your Figaf DB instance in the BTP cockpit.
Connect with psql
Use the values you retrieved to start a PostgreSQL session:
psql -h <REMOTE_HOST> -p <REMOTE_PORT> -U <DB_USER> <DB_NAME>