If you change the postgreSQL version your data will be lost, as a new database will be created. In other words to upgrade the database version you will need to do a migration as described here: Upgrade GCP postgreSQL
When you deploy your application with database config, NAIS will ensure the database exists in a Google Cloud SQL instance with the specified Postgres version, and configure the application with means to connect to it.
This feature is only available in GCP clusters. If you need on-prem databases, head over to navikt/database-iac.
Below is an example of the minimal configuration needed. See all configuration options in the nais.yaml reference.
... kind: Application metadata: name: myapp spec: gcp: sqlInstances: - type: POSTGRES_12 databases: - name: mydb
To connect your application to the database, use information from the environment variables below.
NAIS_DATABASE_MYAPP_MYDB is automatically generated from the instance name
myapp (defaults to application name) and
mydb (from database spec). You can customize these environment variable names by setting
.spec.gcp.sqlInstances.databases.envVarPrefix. For instance, setting this to
DB will give you
|database url with credentials||
Cloud SQL Proxy¶
The application will connect to the database using Cloud SQL Proxy, ensuring that the database communication happens in secure tunnel, authenticated with automatically rotated credentials.
NAIS will add and configure the proxy client container as a sidecar in the pod, making it available on
localhost for the application. The application will then connect to the proxy using standard database protocol just as if it was the actual database.
For more detailed information, check out the Cloud SQL Proxy documentation
Sizing your database¶
By default, the database server has 1 vCPU, 614 MB RAM and 10GB of SSD storage with no automatic storage increase. If you need to change the defaults you can do this in
The database is provisioned into the teams own project in GCP. Here the team has full access to view logs, create and restore backups and other administrative database tasks.
The database is backed up nightly at 3 AM (GMT+1) by default, but can be overridden in
nais.yaml by setting
Default 7 backups will be kept. More info here.
The backups can be found in the Google Cloud SQL instance dashboard.
Deleting the database¶
The database is not automatically removed when deleting your NAIS application. Remove unused databases to avoid incurring unnecessary costs. This is done by setting cascadingDelete in your
When you delete an Cloud SQL instance, you cannot reuse the name of the deleted instance until one week from the deletion date.
Google will automatically perform upgrades, fix bugs and apply security patches to prevent exploits. Your application should be able to handle occational downtime as this maintenance is performed. Read more on maintenance windows here. NAIS will automatically configure the maintenance window to 4 AM (GMT+1), but can be overridden in
If you wish to be notified about upcoming maintenance, you can opt-in for this on the Communications page(https://console.cloud.google.com/user-preferences/communication) in the GCP console.
Check the events on the Config Connector resources
$ kubectl describe sqlinstance <myapp> $ kubectl describe sqldatabase <mydb> $ kubectl describe sqluser <myapp>
Check the logs of the Cloud SQL Proxy
$ kubectl logs <pod> -c cloudsql-proxy
Example with all configuration options¶
See full example.