> For the complete documentation index, see [llms.txt](https://docs.cennso.com/cennso/cennso-db/latest/llms.txt) (all documentation: [llms.txt](https://docs.cennso.com/llms.txt)). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.cennso.com/cennso/cennso-db/latest/concepts/concepts.md).

# Cennso Database concepts

> [!IMPORTANT]
> The concepts documentation provides only reference information about the concepts that are used when you deploy a MySQL or PostgreSQL cluster and its components. You can use it to understand what the Cennso Database resources provide and how to configure them.
>
> For more information on how to deploy and operate the Cennso Database and its components, read the [Deployment](https://docs.cennso.com/cennso/cennso-db/latest/deployment-guides/guides.md) and [Operation](https://docs.cennso.com/cennso/cennso-db/latest/operation-guides/guides.md) guides.

The Cennso Database extension lets you deploy and operate MySQL and PostgreSQL clusters with Cennso. You describe a database cluster, its storage, backups, logical databases, and users as Kubernetes Custom Resources on the Management Cluster, the same way you provision any other Cennso workload. The extension then deploys and configures the database cluster on the target Kubernetes cluster.

The two main concepts are:

- [Database Operator](#database-operator)
- [Database Instance](#database-instance)

Both concepts are presented with the Kubernetes Custom Resources and have common configuration parameters, as well as configuration parameters specific to the given Custom Resource.

For more information on how to configure and deploy the database operator and the other components, see the documents in the left navigation.

## Database Operator

Database Operator automates managing your MySQL and PostgreSQL databases on Kubernetes clusters. The main role of the database operator is to install and reconcile the database instances to ensure that all resources defined by a user are in the desired state.

You can define the database operator using the corresponding Custom Resources:

- [`DBOperator`](https://docs.cennso.com/cennso/cennso-db/latest/concepts/cennso-db-operator.md) - for the MySQL operator
- [`PostgreSQLOperator`](https://docs.cennso.com/cennso/cennso-db/latest/concepts/cennso-postgresql-operator.md) - for the PostgreSQL operator

## Database Instance

A Database Instance is an instance of a MySQL or PostgreSQL server. A set of database instances forms a MySQL or PostgreSQL cluster with asynchronous replication between the database instances. You can define the database instance using the corresponding Custom Resources:

- [`DBInstance`](https://docs.cennso.com/cennso/cennso-db/latest/concepts/cennso-db-instance.md) - for the MySQL server instances
- [`PostgreSQLInstance`](https://docs.cennso.com/cennso/cennso-db/latest/concepts/cennso-postgresql-instance.md) - for the PostgreSQL server instances

## Supporting services

Next to the database instances, each database cluster runs supporting services. They give the database clients a single endpoint and keep the replication topology of the cluster healthy when a database instance fails. The set of supporting services depends on the database server.

### MySQL supporting services

Two helper services are deployed to every MySQL cluster:

- HAProxy - exposes an endpoint for the database clients and provides the ability to balance connections across the MySQL instances.
- MySQL Orchestrator - constantly tracks replication topology of the MySQL cluster, replication lag, and node health. It can promote a replica when the primary is unavailable.

### PostgreSQL supporting services

Two helper services run with every PostgreSQL cluster:

- [PgBouncer](https://www.pgbouncer.org/) - exposes an endpoint for the database clients, pools their connections, and routes them to the current primary.
- [Patroni](https://docs.cennso.com/cennso/cennso-db/latest/troubleshooting/patroni.md) - runs inside every PostgreSQL instance rather than as a separate service. It tracks the replication topology of the PostgreSQL cluster and node health, and promotes a replica when the primary is unavailable.

## Additional concepts

In addition, the Cennso Database extension provides the following concepts to simplify the operations and management of your database clusters:

- [Database backup](#database-backup)
- [Database TLS certificate](#database-tls-certificate)
- [Database schema](#database-schema)
- [Database user](#database-user)

### Database backup

A Database Backup defines backup jobs for database instances managed by the Database Operator. It uses [Restic](https://restic.net/) together with a backup utility to produce consistent, encrypted delta backups on a configurable schedule and store them in a storage-agnostic backend.

The backup utility depends on the database server type:

- [Percona XtraBackup](https://docs.percona.com/percona-xtrabackup/) to perform MySQL backups
- [pg_basebackup](https://www.postgresql.org/docs/current/app-pgbasebackup.html) to perform PostgreSQL backups

You can define a database backup using the corresponding Custom Resources:

- [`DBBackup`](https://docs.cennso.com/cennso/cennso-db/latest/technical-reference/configurations/cennso-db/xdbbackup_definition.md) for MySQL databases
- [`PostgreSQLBackup`](https://docs.cennso.com/cennso/cennso-db/latest/technical-reference/configurations/cennso-postgresql/xpostgresqlbackup_definition.md) for PostgreSQL databases

For more information on how to configure backups, read the following documents:

- [Cennso Database Backup](https://docs.cennso.com/cennso/cennso-db/latest/concepts/cennso-db-backup.md) and [Back up and restore](https://docs.cennso.com/cennso/cennso-db/latest/operation-guides/backup.md) for MySQL databases
- [Cennso PostgreSQL Backup](https://docs.cennso.com/cennso/cennso-db/latest/concepts/cennso-postgresql-backup.md) and [Back up and restore Cennso PostgreSQL](https://docs.cennso.com/cennso/cennso-db/latest/operation-guides/cennso-postgresql-backup.md) for PostgreSQL databases

### Database TLS certificate

A Database TLS Certificate defines a TLS certificate that secures connections to the database cluster. By default, if you do not specify any TLS options, both MySQL and Postgres use TLS certificates issued and renewed through [cert-manager](https://cert-manager.io/).

To configure the validity of TLS certificates, you have different options for each type of database.

To set the custom renewal period of the TLS certificates for the PostgreSQL cluster, you can use the following configuration options:

- **spec.cert.certValidityDuration**
- **spec.cert.caValidityDuration**

For more information on how to configure a TLS certificate for PostgreSQL cluster, read the following documents:

- [Manage TLS certificates](https://docs.cennso.com/cennso/cennso-db/latest/operation-guides/cennso-postgresql-certificates.md)

To set the custom renewal period of the TLS certificates for the MySQL cluster, you can use the [`DBTLSCertificate`](https://docs.cennso.com/cennso/cennso-db/latest/technical-reference/configurations/cennso-db/xdbtlscertificate_definition.md) Custom Resource.

For more information on how to configure a TLS certificate for MySQL databases, read the following documents:

- [Cennso Database Certificate](https://docs.cennso.com/cennso/cennso-db/latest/concepts/cennso-db-certificate.md)
- [Manage TLS certificates](https://docs.cennso.com/cennso/cennso-db/latest/operation-guides/certificates.md)

### Database schema

A Database Schema defines a logical database, provisioned by a job in an existing Database Instance. For MySQL databases, it also defines the default character set and collation.

You can define a database schema using the corresponding Custom Resources:

- [`DBSchema`](https://docs.cennso.com/cennso/cennso-db/latest/technical-reference/configurations/cennso-db/xdbschema_definition.md) for MySQL databases
- [`PostgreSQLSchema`](https://docs.cennso.com/cennso/cennso-db/latest/technical-reference/configurations/cennso-postgresql/xpostgresqlschema_definition.md) for PostgreSQL databases

For more information on how to provision a logical database, read the following documents:

- [Cennso Database Schema](https://docs.cennso.com/cennso/cennso-db/latest/concepts/cennso-db-schema.md) and [Create a database](https://docs.cennso.com/cennso/cennso-db/latest/operation-guides/database-creation.md) for MySQL databases
- [Cennso PostgreSQL Schema](https://docs.cennso.com/cennso/cennso-db/latest/concepts/cennso-postgresql-schema.md) and [Create a PostgreSQL database](https://docs.cennso.com/cennso/cennso-db/latest/operation-guides/cennso-postgresql-database-creation.md) for PostgreSQL databases

### Database user

A Database User defines a user account provisioned by a job in an existing Database Instance.

You can define a database user using the corresponding Custom Resources:

- [`DBUser`](https://docs.cennso.com/cennso/cennso-db/latest/technical-reference/configurations/cennso-db/xdbuser_definition.md) for MySQL databases
- [`PostgreSQLUser`](https://docs.cennso.com/cennso/cennso-db/latest/technical-reference/configurations/cennso-postgresql/xpostgresqluser_definition.md) for PostgreSQL databases

For more information on how to provision a user with privileges, read the following documents:

- [Cennso Database User](https://docs.cennso.com/cennso/cennso-db/latest/concepts/cennso-db-users.md) and [Create a database user](https://docs.cennso.com/cennso/cennso-db/latest/operation-guides/users-creation.md) for MySQL databases
- [Cennso PostgreSQL User](https://docs.cennso.com/cennso/cennso-db/latest/concepts/cennso-postgresql-user.md) and [Create a PostgreSQL user](https://docs.cennso.com/cennso/cennso-db/latest/operation-guides/cennso-postgresql-users-creation.md) for PostgreSQL databases
