Database
3 minute read
The database microservice is the central component of the United Manufacturing Hub and is based on TimescaleDB, an open-source relational database built for handling time-series data. TimescaleDB is designed to provide scalable and efficient storage, processing, and analysis of time-series data.
You can find more information on the datamodel of the database in the Data Model section, and read about the choice to use TimescaleDB in the blog article.
How it works
When deployed, the database microservice will create two databases, with the related usernames and passwords:
grafana
: This database is used by Grafana to store the dashboards and other data.factoryinsight
: This database is the main database of the United Manufacturing Hub. It contains all the data that is collected by the microservices.
Then, it creates the tables based on the database schema.
If you want to learn more about how TimescaleDB works, you can read the TimescaleDB documentation.
Kubernetes resources
- StatefulSet:
united-manufacturing-hub-timescaledb
- Service:
- Internal ClusterIP for the replicas:
united-manufacturing-hub-replica
at port 5432 - Internal ClusterIP for the config:
united-manufacturing-hub-config
at port 8008 - External LoadBalancer:
united-manufacturing-hub
at port 5432
- Internal ClusterIP for the replicas:
- ConfigMap:
- Patroni:
united-manufacturing-hub-timescaledb-patroni
- Post init:
timescale-post-init
- Postgres BackRest:
united-manufacturing-hub-timescaledb-pgbackrest
- Scripts:
united-manufacturing-hub-timescaledb-scripts
- Patroni:
- Secret:
- Certificate:
united-manufacturing-hub-certificate
- Patroni credentials:
united-manufacturing-hub-credentials
- Users passwords:
timescale-post-init-pw
- Certificate:
- PersistentVolumeClaim:
- Data:
storage-volume-united-manufacturing-hub-timescaledb-0
- WAL-E:
wal-volume-united-manufacturing-hub-timescaledb-0
- Data:
Configuration
There is only one parameter that usually needs to be changed: the password used
to connect to the database. To do so, set the value of the db_password
key in
the _000_commonConfig.datastorage
section of the Helm chart values file.
Environment variables
Variable name | Description | Type | Allowed values | Default |
---|---|---|---|---|
BOOTSTRAP_FROM_BACKUP | Whether to bootstrap the database from a backup or not. | int | 0, 1 | 0 |
PATRONI_KUBERNETES_LABELS | The labels to use to find the pods of the StatefulSet. | string | Any | {app: united-manufacturing-hub-timescaledb, cluster-name: united-manufacturing-hub, release: united-manufacturing-hub} |
PATRONI_KUBERNETES_NAMESPACE | The namespace in which the StatefulSet is deployed. | string | Any | united-manufacturing-hub |
PATRONI_KUBERNETES_POD_IP | The IP address of the pod. | string | Any | Random IP |
PATRONI_KUBERNETES_PORTS | The ports to use to connect to the pods. | string | Any | [{"name": "postgresql", "port": 5432}] |
PATRONI_NAME | The name of the pod. | string | Any | united-manufacturing-hub-timescaledb-0 |
PATRONI_POSTGRESQL_CONNECT_ADDRESS | The address to use to connect to the database. | string | Any | $(PATRONI_KUBERNETES_POD_IP):5432 |
PATRONI_POSTGRESQL_DATA_DIR | The directory where the database data is stored. | string | Any | /var/lib/postgresql/data |
PATRONI_REPLICATION_PASSWORD | The password to use to connect to the database as a replica. | string | Any | Random 16 characters |
PATRONI_REPLICATION_USERNAME | The username to use to connect to the database as a replica. | string | Any | standby |
PATRONI_RESTAPI_CONNECT_ADDRESS | The address to use to connect to the REST API. | string | Any | $(PATRONI_KUBERNETES_POD_IP):8008 |
PATRONI_SCOPE | The name of the cluster. | string | Any | united-manufacturing-hub |
PATRONI_SUPERUSER_PASSWORD | The password to use to connect to the database as the superuser. | string | Any | Random 16 characters |
PATRONI_admin_OPTIONS | The options to use for the admin user. | string | Comma separated list of options | createrole,createdb |
PATRONI_admin_PASSWORD | The password to use to connect to the database as the admin user. | string | Any | Random 16 characters |
PGBACKREST_CONFIG | The path to the configuration file for Postgres BackRest. | string | Any | /etc/pgbackrest/pgbackrest.conf |
PGDATA | The directory where the database data is stored. | string | Any | $(PATRONI_POSTGRESQL_DATA_DIR) |
PGHOST | The directory of the runnning database | string | Any | /var/run/postgresql |