Rechercher

Ce contenu n'est pas disponible dans la langue sélectionnée.

Chapter 3. Migrating from an embedded PostgreSQL 10 database to an external PostgreSQL 10 database

download PDF
Important
  • Before scaling system.appSpec.replicas to 1, the database should be upgraded to the supported version, which is currently PostgreSQL 13. See Red Hat 3scale API Management Supported Configurations
  • This documentation is about migrating from an embedded PostgreSQL 10 database to an external PostgreSQL 10 database. To upgrade from an external PostgreSQL 10 database to an external PostgreSQL 13 database, you must following the official PostgreSQL documentation.
  • Disclaimer: Links contained herein to external website(s) are provided for convenience only. Red Hat has not reviewed the links and is not responsible for the content or its availability. The inclusion of any link to an external website does not imply endorsement by Red Hat of the website or their entities, products or services. You agree that Red Hat is not responsible or liable for any loss or expenses that may result due to your use of (or reliance on) the external site or content.

The process to move from an embedded PostgreSQL database to and external PostgreSQL database should happen with the same DB version. In this migration guide, it should be PostgreSQL 10. You should use external databases for production environments.

If you are using PostgreSQL as your system-database, use the supported version for external database installation with 3scale.

Important
  • These steps are general guidelines. Exact steps may vary depending on your operating system, version of PostgreSQL, and specific requirements of your database.
  • Read the PostgreSQL documentation and release notes carefully before upgrading.
  • Test this procedure in a non-production environment before applying it to a production deployment.
  • This process disrupts the provision of the service until the procedure finishes. Due to this disruption, be sure to have a maintenance window.

Procedure

  1. Use APIManager customer resource (CR) to scale down the system-app DeploymentConfig (DC):

    apiVersion: apps.3scale.net/v1alpha1
    kind: APIManager
    metadata:
      name: <apimanager_sample>
    spec:
      system:
        appSpec:
          replicas: 0
      wildcardDomain: <example.com>
  2. Verify that the pods are scaled down:

    $ oc get deploymentconfig system-app -o jsonpath='{.status.availableReplicas}{"\n"}'
    0
    1. Wait for all the 3scale pods to have the status of Terminated before proceeding with the PostgreSQL migration.
  3. Make a backup of the existing PostgreSQL database, including all data, configurations, and user accounts:

    $ DB_USER=$(oc get secret system-database -o jsonpath="{.data.DB_USER}" | base64 --decode)
    $ DATABASE_NAME=$(oc get secret system-database -o jsonpath="{.data.URL}" | base64 --decode | cut -d '/' -f4)
    Important

    Do not pipe to stdout. Binary files get corrupted.

  4. Dump with custom format:

    $ oc rsh $(oc get pods -l 'deploymentConfig=system-postgresql' -o json | jq -r '.items[0].metadata.name') bash -c "pg_dump -U $DB_USER -F c $DATABASE_NAME -f /tmp/<backupfilename>.backup"
  5. Download the backup:

    $ oc cp $(oc get pods -l 'deploymentConfig=system-postgresql' -o json | jq -r '.items[0].metadata.name'):/tmp/<backupfilename>.backup <backupfilename>.backup
  6. Install the same version of PostgreSQL 10 that you deployed on 3scale in your target external system. Download the installation package from the PostgreSQL website following the installation instructions.
  7. Copy and restore the backup you made of the existing PostgreSQL database, including all data, configurations, and user accounts to the target external system.
  8. Create a new database in PostgreSQL:

    $ createdb -U <username> <databasename>
  9. Import the data from the backup file into the new PostgreSQL database.

    • Restore with custom format:

      $ pg_restore [--host <databasehostname>] -U <username> -d <databasename> --verbose -F c <backupfilename>.backup
  10. Verify that the data was successfully imported into the new PostgreSQL database by connecting to the database and running queries:

    postgresql://<username>:<password>@<databasehostname>/<databasename>
  11. Update system-database secret:

    $ oc apply -f - <<EOF
    ---
    apiVersion: v1
    kind: Secret
    metadata:
      name: system-database
    stringData:
      DB_PASSWORD: <password>
      DB_USER: <username>
      URL: "postgresql://<username>:<password>@<databasehostname>:<databaseport>/<databasename>"
    type: Opaque
    EOF
  12. Update APImanager CR to enable external database and scale up system:

    $ oc patch apimanager <apimanager_sample> --type=merge --patch '{"spec": {"system": {"database": null, "appSpec": {"replicas": 1}}, "externalComponents": {"system": {"database": true}}}}'
  13. Remove local postgresql deployment:

    $ oc delete service system-postgresql
    $ oc delete deploymentconfig system-postgresql
    $ oc delete pvc postgresql-data
  14. Verify that the pods are scaled up:

    $ oc wait --for=condition=available apimanager/<apimanager_sample> --timeout=-1s
Red Hat logoGithubRedditYoutubeTwitter

Apprendre

Essayez, achetez et vendez

Communautés

À propos de la documentation Red Hat

Nous aidons les utilisateurs de Red Hat à innover et à atteindre leurs objectifs grâce à nos produits et services avec un contenu auquel ils peuvent faire confiance.

Rendre l’open source plus inclusif

Red Hat s'engage à remplacer le langage problématique dans notre code, notre documentation et nos propriétés Web. Pour plus de détails, consultez leBlog Red Hat.

À propos de Red Hat

Nous proposons des solutions renforcées qui facilitent le travail des entreprises sur plusieurs plates-formes et environnements, du centre de données central à la périphérie du réseau.

© 2024 Red Hat, Inc.