Skip to Content
RigFabTech docs
Install

Import a database

To start a product with the data of a PostgreSQL database you already run, have the product's database import it when it's created. For example, the database the product used before you moved it to the platform.

CloudNativePG copies the database into the product's own cluster, <PRODUCT>-db, with pg_dump and pg_restore. It uses its microservice import. When the product starts, its migrations bring the schema up to date.

The import runs once, when the product's database is created at its first install. A product that's already installed doesn't import. To import into it, uninstall it, which deletes its database, and install it again.

Before you begin

  • The source server runs a PostgreSQL major version no newer than the platform's, global.rigfab.database.imageName.
  • A user on the source that can dump the whole database with pg_dump. The database's owner usually can. A superuser always can.
  • The source accepts that user's connections from the cluster, over TLS unless you set sslMode.
  • The product's database volume can hold the dump and the restored database at once while it imports.

Give each product the password

In the namespace of each product that imports, create a Secret with the import user's password under password:

kubectl create secret generic database-import --namespace rft-app-<PRODUCT> --from-file=password=password.txt

Add the import to site.yaml

global:
  rigfab:
    database:
      import:
        host: <SOURCE_HOST>
        existingSecret: database-import
        to:
          - ipBlock:
              cidr: <SOURCE_ADDRESS>/32
        apps:
          <PRODUCT>:
            database: <SOURCE_DATABASE>
            user: <SOURCE_USER>
  • to lets the database through its NetworkPolicy to the source. Use an ipBlock for a server outside the cluster, or a namespaceSelector and podSelector for one inside it.
  • apps has one entry for each product to import, by its name.

The values reference lists every value.

Import

  1. Stop writes to the source database. The import copies a snapshot, and later writes don't reach the product.

  2. Install the product as Install shows. Its pods wait for the database while it imports. For a large database, raise --timeout.

  3. Follow the import:

    kubectl --namespace rft-app-<PRODUCT> logs --follow job/<PRODUCT>-db-1-import

The product's own user owns everything imported. The source's grants and other roles don't come across.

Turn it off

Once the products run on their imported data, turn the import off. Left in place, it imports again whenever a product's database is created anew, such as after a reinstall.

  1. Remove global.rigfab.database.import from site.yaml.

  2. Upgrade each product that imported. The upgrade only removes the import from the database's definition. The data stays.

  3. Delete the Secret in each product's namespace:

    kubectl delete secret database-import --namespace rft-app-<PRODUCT>

Next steps