이 콘텐츠는 선택한 언어로 제공되지 않습니다.
Chapter 9. Migration from PostgreSQL 9 to PostgreSQL 13
By the 11th of November, 2021, the PostgreSQL version 9.6 came out of support, and CodeReady Workspaces team recommends that all users undergo migrating to version 13.
Follow the procedure below to migrate to a newer version of PostgreSQL successfully without any data loss.
Prerequisites
-
The
oc
tool is available. - An instance of CodeReady Workspaces running in OpenShift.
Procedure
- Save and push changes back to the Git repositories for all running workspaces of the CodeReady Workspaces instance.
- Stop all workspaces in the CodeReady Workspaces instance.
Scale down the CodeReady Workspaces and RH-SSO deployments:
oc scale deployment codeready --replicas=0 -n openshift-workspaces oc scale deployment keycloak --replicas=0 -n openshift-workspaces
oc scale deployment codeready --replicas=0 -n openshift-workspaces oc scale deployment keycloak --replicas=0 -n openshift-workspaces
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Backup available databases:
POSTGRES_POD=$(oc get pods -n openshift-workspaces | grep postgres | awk '{print $1}') CHE_POSTGRES_DB=$(oc get checluster/codeready-workspaces -n openshift-workspaces -o json | jq '.spec.database.chePostgresDb') oc exec -it $POSTGRES_POD -n openshift-workspaces -- bash -c "pg_dump $CHE_POSTGRES_DB > /tmp/che.sql" oc exec -it $POSTGRES_POD -n openshift-workspaces -- bash -c "pg_dump keycloak > /tmp/keycloak.sql"
POSTGRES_POD=$(oc get pods -n openshift-workspaces | grep postgres | awk '{print $1}') CHE_POSTGRES_DB=$(oc get checluster/codeready-workspaces -n openshift-workspaces -o json | jq '.spec.database.chePostgresDb') oc exec -it $POSTGRES_POD -n openshift-workspaces -- bash -c "pg_dump $CHE_POSTGRES_DB > /tmp/che.sql" oc exec -it $POSTGRES_POD -n openshift-workspaces -- bash -c "pg_dump keycloak > /tmp/keycloak.sql"
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Copy the obtained backups to a local file system:
oc cp openshift-workspaces/$POSTGRES_POD:/tmp/che.sql che.sql oc cp openshift-workspaces/$POSTGRES_POD:/tmp/keycloak.sql keycloak.sql
oc cp openshift-workspaces/$POSTGRES_POD:/tmp/che.sql che.sql oc cp openshift-workspaces/$POSTGRES_POD:/tmp/keycloak.sql keycloak.sql
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Scale down the PostgreSQL deployment:
oc scale deployment postgres --replicas=0 -n openshift-workspaces
oc scale deployment postgres --replicas=0 -n openshift-workspaces
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Delete the corresponding PVC unit to clean up old data:
oc delete pvc postgres-data -n openshift-workspaces
oc delete pvc postgres-data -n openshift-workspaces
Copy to Clipboard Copied! Toggle word wrap Toggle overflow After deleting the PVC from the step above, a new PVC will automatically appear in a few seconds.
Set the version of the new PostgreSQL database to 13.3:
oc patch checluster codeready-workspaces -n openshift-workspaces --type=json -p '[{"op": "replace", "path": "/spec/database/postgresVersion", "value": "13.3"}]'
oc patch checluster codeready-workspaces -n openshift-workspaces --type=json -p '[{"op": "replace", "path": "/spec/database/postgresVersion", "value": "13.3"}]'
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Scale up the PostgreSQL deployments:
oc scale deployment postgres --replicas=1 -n openshift-workspaces oc wait --for=condition=ready pod -l app.kubernetes.io/component=postgres -n openshift-workspaces --timeout=120s
oc scale deployment postgres --replicas=1 -n openshift-workspaces oc wait --for=condition=ready pod -l app.kubernetes.io/component=postgres -n openshift-workspaces --timeout=120s
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Provision a database:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Copy the backups to the PostgreSQL Pod:
oc cp che.sql openshift-workspaces/$POSTGRES_POD:/tmp/che.sql oc cp keycloak.sql openshift-workspaces/$POSTGRES_POD:/tmp/keycloak.sql
oc cp che.sql openshift-workspaces/$POSTGRES_POD:/tmp/che.sql oc cp keycloak.sql openshift-workspaces/$POSTGRES_POD:/tmp/keycloak.sql
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Restore the database:
oc exec -it $POSTGRES_POD -n openshift-workspaces -- bash -c "psql keycloak < /tmp/keycloak.sql" oc exec -it $POSTGRES_POD -n openshift-workspaces -- bash -c "psql $CHE_POSTGRES_DB < /tmp/che.sql"
oc exec -it $POSTGRES_POD -n openshift-workspaces -- bash -c "psql keycloak < /tmp/keycloak.sql" oc exec -it $POSTGRES_POD -n openshift-workspaces -- bash -c "psql $CHE_POSTGRES_DB < /tmp/che.sql"
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Scale up the RH-SSO and CodeReady Workspaces deployments:
oc scale deployment keycloak --replicas=1 -n openshift-workspaces oc wait --for=condition=ready pod -l app.kubernetes.io/component=keycloak -n openshift-workspaces --timeout=120s oc scale deployment codeready --replicas=1 -n openshift-workspaces oc wait --for=condition=ready pod -l app.kubernetes.io/component=codeready -n openshift-workspaces --timeout=120s
oc scale deployment keycloak --replicas=1 -n openshift-workspaces oc wait --for=condition=ready pod -l app.kubernetes.io/component=keycloak -n openshift-workspaces --timeout=120s oc scale deployment codeready --replicas=1 -n openshift-workspaces oc wait --for=condition=ready pod -l app.kubernetes.io/component=codeready -n openshift-workspaces --timeout=120s
Copy to Clipboard Copied! Toggle word wrap Toggle overflow