Skip to main content

Database Migration Guide

GuardRails On-Premise Database Migration Guide

Pre-requisites

Ensure that the external database is set up with the following values:

  • username: guardrails
  • database: guardrails-onpremise

Optional:

  • SSL certificate for SSL connection

Part 1

Scale down the containers within the GuardRails stack.


# Scale the services down
kubectl -n <namespace> scale --replicas=0 deployment api
kubectl -n <namespace> scale --replicas=0 deployment core-api
kubectl -n <namespace> scale --replicas=0 statefulset worker
kubectl -n <namespace> scale --replicas=0 deployment probot
kubectl -n <namespace> scale --replicas=0 deployment scaoracleagent

# Perform a dump of the Postgres DB with the following command
docker exec -t $(docker ps -q -f name=replXXXX_postgres) pg_dumpall -c -U postgres > gr_db_dump.sql

kubectl -n <namespace> exec -it $(kubectl -n <namespace> get pods -o=name | grep "pod/postgres\-") -- pg_dumpall -c -U postgres > SSDDMMYYY-gr-db-dump.sql

Part 2

On the GuardRails settings page, set the database to external.

DB Setting

The URI should look something like this:

postgresql://dbadmin%40guardrailsdb:p%[email protected]:5432/guardrails-onpremise

Do note that any special characters in the username and/or password must be URL encoded. E.g. @ becomes %40.

Part 3

Restore the SQL dump into the new external database psql -U postgres -d guardrails-onpremise -f SSDDMMYYY-gr-db-dump.sql

Scale up the services:

kubectl -n <namespace> scale --replicas=1 deployment api
kubectl -n <namespace> scale --replicas=1 deployment core-api
# note the replica for the worker should be the same as in the admin console cluster settings
kubectl -n <namespace> scale --replicas=X statefulset worker
kubectl -n <namespace> scale --replicas=1 deployment probot
kubectl -n <namespace> scale --replicas=1 deployment scaoracleagent

Useful commands:

kubectl -n  <namespace> exec -it $(kubectl -n  <namespace> get pods -o=name | grep "pod/postgres\-") -- psql postgres://postgres:onpremise@postgres:5432/

# list tables
\t
# list databases
\l
# drop database
drop database "guardrails-onpremise"
# create database
create database "guardrails-onpremise"
# import dump
cat /path/to/dump.sql | kubectl exec -i $(kubectl -n <namespace> get pods -o=name | grep "pod/postgres\-") -- psql -U postgres -d guardrails-onpremise