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.txtAdd 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>tolets the database through its NetworkPolicy to the source. Use anipBlockfor a server outside the cluster, or anamespaceSelectorandpodSelectorfor one inside it.appshas one entry for each product to import, by its name.
The values reference lists every value.
Import
-
Stop writes to the source database. The import copies a snapshot, and later writes don't reach the product.
-
Install the product as Install shows. Its pods wait for the database while it imports. For a large database, raise
--timeout. -
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.
-
Remove
global.rigfab.database.importfromsite.yaml. -
Upgrade each product that imported. The upgrade only removes the import from the database's definition. The data stays.
-
Delete the Secret in each product's namespace:
kubectl delete secret database-import --namespace rft-app-<PRODUCT>
Next steps
- Install your licence.
- If the product doesn't start, see Troubleshooting.