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


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>
    Copy to Clipboard Toggle word wrap
  2. Verify that the pods are scaled down:

    $ oc get deploymentconfig system-app -o jsonpath='{.status.availableReplicas}{"\n"}'
    0
    Copy to Clipboard Toggle word wrap
    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)
    Copy to Clipboard Toggle word wrap
    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"
    Copy to Clipboard Toggle word wrap
  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
    Copy to Clipboard Toggle word wrap
  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>
    Copy to Clipboard Toggle word wrap
  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
      Copy to Clipboard Toggle word wrap
  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>
    Copy to Clipboard Toggle word wrap
  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
    Copy to Clipboard Toggle word wrap
  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}}}}'
    Copy to Clipboard Toggle word wrap
  13. Remove local postgresql deployment:

    $ oc delete service system-postgresql
    $ oc delete deploymentconfig system-postgresql
    $ oc delete pvc postgresql-data
    Copy to Clipboard Toggle word wrap
  14. Verify that the pods are scaled up:

    $ oc wait --for=condition=available apimanager/<apimanager_sample> --timeout=-1s
    Copy to Clipboard Toggle word wrap
Back to top
Red Hat logoGithubredditYoutubeTwitter

Learn

Try, buy, & sell

Communities

About Red Hat Documentation

We help Red Hat users innovate and achieve their goals with our products and services with content they can trust. Explore our recent updates.

Making open source more inclusive

Red Hat is committed to replacing problematic language in our code, documentation, and web properties. For more details, see the Red Hat Blog.

About Red Hat

We deliver hardened solutions that make it easier for enterprises to work across platforms and environments, from the core datacenter to the network edge.

Theme

© 2025 Red Hat