Skip to content

Connecting to TEST Postgres DB locally with DBeaver

Ricardo Campos edited this page Nov 24, 2023 · 3 revisions

These steps provide you with simple guide on how you can connect to the running Postgres database instance on the TEST OpenShift namespace through port forwarding.

Requirements

Steps to take

  1. Start the VPN connection
  2. Authenticate your oc on the TEST namespace
  1. Set the test project locally
  • Run the command: oc project b9d53b-test
  • Note that b9d53b-test is the SPAR TEST namespace code
  1. Find the running database pod (container)
  • Run the command: oc get pods | grep nr-spar-test-database | grep Running
  • Where nr-spar-test-database is the database container name
  • You should see an output similar to nr-spar-test-database-36-4qgbl
  1. Start the Port Forwarding
  • Run the command: oc port-forward nr-spar-test-database-36-4qgbl 15432:5432
  • Where nr-spar-backend-test-database-36-4qgbl is the container name and 15432:5432 is the port mapping. We'll be mapping the port 15432 locally to the container port 5432. (If you like, you can map to 5432:5432).
  1. Open up your Database tool, let's say DBeaver, and create a new connection
  • Hostname: localhost
  • Port: 15432
  • Database name (schema): nr-spar
  • Database username: nr-spar
  • Database password: auto-generated. You'll need to grab it every time you need it. See the next step.
  • You can extract the database secret with oc extract secret/nr-spar-test-database -n b9d53b-test --to=-, a sample output will be like this (note that there are three secrets and its values right below):
# database-name
nr-spar
# database-password
123456789abcdefgh
# database-user
nr-spar
  • Hit "Test connection". It should succeed.
  • Hit Save.
  • That's it.

Notes