Database Management
db sync / migrations and maintenance
This page covers database setup, schema migration, and ongoing maintenance for Trilio Site Recovery. The service stores all DR state — sites, protection groups, consistency groups, members, volumes, operations, replication policies, and tenant mappings — in a MariaDB or MySQL database named protector. Schema evolution is managed by Alembic migrations, invoked through the protector-manage db sync command. Understanding how migrations run, how to verify schema state, and how to recover from common failure modes is essential before upgrading the service or diagnosing a failed deployment.
Before performing any database management task, ensure:
- MariaDB or MySQL is running and accessible from the node running the protector service. The database named
protectorand theprotectoruser must exist withALL PRIVILEGESon that database. trilio-site-recoverypackage is installed on the node where you will runprotector-manage. The command is shipped as a console script by this package./etc/protector/protector.confis present and contains a valid[database] connectionstring pointing to the protector database.- For Juju deployments: the
trilio-site-recovery-for-openstackcharm unit is in an appropriate state. Use Juju actions rather than runningprotector-managedirectly. - For Kolla and bare-metal deployments: you have shell access to a node where the
trilio-site-recoverypackage is installed. - When crossing migration
022_add_reconcile_operation_type, you must runprotector-manage db preflightbeforedb syncon Kolla and bare-metal deployments. The Juju charm'sdb-syncaction runs the preflight automatically. - The
dr_operatoranddr_site_adminKeystone roles must exist on both sites before the service starts, as trust creation fails if a role named indefault_trust_rolesis absent.
Create the database and user
Before running migrations, the database and user must exist. On the MariaDB or MySQL host, run the following SQL (adjust the password to match your protector.conf):
CREATE DATABASE IF NOT EXISTS protector CHARACTER SET utf8;
GRANT ALL PRIVILEGES ON protector.* TO 'protector'@'localhost' IDENTIFIED BY 'your-password';
GRANT ALL PRIVILEGES ON protector.* TO 'protector'@'%' IDENTIFIED BY 'your-password';
FLUSH PRIVILEGES;
The default database name and user are both protector (as configured by the Juju charm).
Juju deployment
For charm-managed deployments, database migration is handled by the db-sync Juju action. The charm runs the preflight check automatically before applying migrations.
Run the initial migration (or upgrade):
juju run trilio-site-recovery-for-openstack/leader db-sync
The charm reads protector.conf it has written and passes --config-file to protector-manage automatically.
Kolla-Ansible deployment
On a Kolla-managed node, migrations run inside the protector_api container. When crossing migration 022, run the preflight first:
# 1. Run the preflight check
docker exec protector_api protector-manage db preflight
# 2. Only proceed if the preflight exits 0
docker exec protector_api protector-manage db sync
The Kolla install script (deploy/kolla/install.sh) handles this sequence during initial deployment.
OpenShift (RHOSO18) deployment
On OpenShift, migrations are run by the job-db-sync init Job, which is applied by the installer script as part of the full deployment sequence:
bash deploy/openshift/scripts/install.sh
Do not apply individual manifests manually — the installer applies twelve manifests in a specific order, including init Jobs gated on completion checks. See the OpenShift deployment guide for full details.
Manual / bare-metal deployment
If you are running protector-manage directly on a machine where the trilio-site-recovery package is installed:
# 1. Run the preflight check (required when crossing migration 022)
protector-manage --config-file /etc/protector/protector.conf db preflight
# 2. Apply all pending migrations
protector-manage --config-file /etc/protector/protector.conf db sync
The --config-file flag is optional if /etc/protector/protector.conf is in its default location, but specifying it explicitly avoids ambiguity.
Database connectivity is configured in the [database] section of /etc/protector/protector.conf. All other service sections read the same file.
[database] section
| Option | Type | Default | Purpose |
|---|---|---|---|
connection | string | mysql+pymysql://protector:password@localhost/protector | SQLAlchemy connection URL for the protector database. The default points at a local MariaDB/MySQL with the protector user, password, and database; set it to your actual database host, credentials, and database name before deploying. |
Example:
[database]
connection = mysql+pymysql://protector:your-password@controller.example.com/protector
Use mysql+pymysql as the driver prefix; PyMySQL is the recommended pure-Python MySQL driver and is installed alongside the service package.
Connection URL format
mysql+pymysql://<user>:<password>@<host>[:<port>]/<database>
<user>and<database>default toprotectorin a standard Juju or Kolla deployment.<host>is the address of the MariaDB/MySQL server (or VIP for clustered deployments).<port>defaults to 3306 and can be omitted.
Connection pooling
The service uses SQLAlchemy's default connection pool with two overrides set in code:
pool_pre_ping=True— validates connections before use, recovering from dropped connections without an error on the first request after a network event.pool_recycle=3600— recycles connections after one hour, preventing issues with MySQL'swait_timeout.
These are not currently exposed as protector.conf options. If your MariaDB wait_timeout is set below 3600 seconds, increase it on the database side rather than modifying the pool recycle interval.
alembic.ini location
protector-manage locates alembic.ini by searching the following paths in order:
/opt/openstack-protector/alembic.ini(Kolla container layout)- A path relative to the installed script (source checkout layout)
/usr/share/trilio-site-recovery/alembic.ini(Debian package layout)
Do not place or reference alembic.ini under /etc/protector/ — it is not installed there by any deployment path.
The protector-manage command
protector-manage is the single supported entry point for all database management operations. It is installed as a console script by the trilio-site-recovery package at /usr/bin/protector-manage.
General syntax:
protector-manage [--config-file <path>] [--debug] db <subcommand> [args]
The --config-file flag may be repeated to merge multiple configuration files. When omitted, the command reads /etc/protector/protector.conf.
Subcommands
db sync — apply all pending migrations
Brings the schema to the current head revision. This is the standard command for initial setup and upgrades.
protector-manage db sync
On a fresh database with no alembic_version table (created via CREATE DATABASE but never migrated), db sync stamps the schema at the bootstrap revision 012_add_activedr_columns and then runs all newer migrations. This handles the case where the schema was created by SQLAlchemy.create_all() before Alembic tracking was added.
Important: When upgrading across migration
022_add_reconcile_operation_type, rundb preflightfirst on Kolla and bare-metal deployments. The Juju charm'sdb-syncaction does this automatically.
db preflight — validate the schema before migrating
Checks that the dr_operations.operation_type ENUM column holds the correct token set before migration 022 is applied. Exits non-zero if the column contains tokens the ORM does not recognise as member names, which would cause data corruption if MODIFY COLUMN ran against them.
protector-manage db preflight
Run this before db sync on every Kolla and bare-metal node when upgrading to a release that includes migration 022 or later. If the preflight exits non-zero, do not run db sync — contact Trilio support.
The preflight is a no-op on databases other than MySQL and MariaDB (which have a native ENUM type). On those backends it always exits 0.
db current — show the current schema revision
Prints the Alembic revision currently recorded in the database.
protector-manage db current
The current head revision is 025_add_member_removing. If db current returns anything earlier, pending migrations exist.
db stamp — record a revision without running migrations
Sets the alembic_version row to a specific revision without executing any migration scripts. Use this only when you have applied schema changes by another means and need Alembic to reflect the state.
# Stamp at the current head
protector-manage db stamp head
# Stamp at a specific revision
protector-manage db stamp 022_add_reconcile_operation_type
Caution: Stamping at the wrong revision causes subsequent
db synccalls to skip or re-apply migrations. Usedb currentto verify the result.
Verifying schema state with schema_revision.py
The tools/schema_revision.py script compares the database's recorded revision against what the installed code expects, and lists any pending migrations with the columns they add:
python3 tools/schema_revision.py --config-file /etc/protector/protector.conf
Use --check for a terse one-line output suitable for scripts:
python3 tools/schema_revision.py --check
# Exit 0: in step
# Exit 2: database behind the code
# Exit 3: database at an unknown (newer) revision
# Exit 1: could not determine
This script is particularly useful before restarting the service after an upgrade, to confirm migrations have been applied before the new code starts reading columns it now declares.
Purging the database (Juju)
The purge-database Juju action drops all tables from the protector database (keeping the database itself, since it was created by the shared-db relation):
juju run trilio-site-recovery-for-openstack/leader purge-database
After purging, run db-sync to recreate the schema:
juju run trilio-site-recovery-for-openstack/leader db-sync
To drop the database itself (not just the tables), pass drop_schema=true when invoking the underlying db_purge.py script directly — but note this is not exposed as a Juju action parameter and requires manual invocation.
Check the current schema revision
protector-manage --config-file /etc/protector/protector.conf db current
Run the preflight check then apply migrations
# Step 1: preflight (required when crossing migration 022)
protector-manage --config-file /etc/protector/protector.conf db preflight
# Step 2: apply migrations (only if preflight exits 0)
protector-manage --config-file /etc/protector/protector.conf db sync
Apply migrations inside a Kolla container
docker exec protector_api protector-manage db preflight
docker exec protector_api protector-manage db sync
Run the Juju db-sync action
juju run trilio-site-recovery-for-openstack/leader db-sync
The charm runs db preflight automatically before db sync.
Stamp the database at the bootstrap revision (fresh schema)
Use this when a schema was created by create_all() before Alembic tracking was introduced and db sync complains that it cannot find the alembic_version table:
protector-manage db stamp 012_add_activedr_columns
protector-manage db sync
Check whether the schema is in step with the installed code
python3 tools/schema_revision.py --config-file /etc/protector/protector.conf --check
Create the protector database and user (SQL)
CREATE DATABASE IF NOT EXISTS protector CHARACTER SET utf8;
GRANT ALL PRIVILEGES ON protector.* TO 'protector'@'localhost' IDENTIFIED BY 'your-password';
GRANT ALL PRIVILEGES ON protector.* TO 'protector'@'%' IDENTIFIED BY 'your-password';
FLUSH PRIVILEGES;
Purge and recreate the schema (Juju)
juju run trilio-site-recovery-for-openstack/leader purge-database
juju run trilio-site-recovery-for-openstack/leader db-sync
Service fails to start: Unknown column errors in logs
Symptom: The protector-api or protector-engine log shows Unknown column 'X' in 'field list' or similar SQLAlchemy errors immediately after an upgrade.
Cause: The service was started before db sync completed. The SQLAlchemy models declare columns that do not yet exist in the database. Every read of the affected table fails until the migration runs.
Fix:
- Stop the service.
- Run
protector-manage db preflight(required if crossing migration022). - Run
protector-manage db sync. - Confirm with
protector-manage db currentthat the revision matches025_add_member_removing. - Restart the service.
On Juju: juju run trilio-site-recovery-for-openstack/leader db-sync, then juju run trilio-site-recovery-for-openstack/leader health-check.
db preflight exits non-zero before migration 022
Symptom: protector-manage db preflight prints a message about unexpected tokens in dr_operations.operation_type and exits with status 1.
Cause: The operation_type ENUM column on disk holds tokens that do not match the ORM's member names (for example, lowercase values like 'failover' instead of 'FAILOVER'). Running db sync in this state would cause migration 022 to rewrite the ENUM and corrupt every existing operation row's label.
Fix: Do not run db sync. Contact Trilio support with the output of:
SHOW COLUMNS FROM dr_operations LIKE 'operation_type';
db sync reports: Could not find alembic.ini
Symptom: protector-manage db sync exits with RuntimeError: Could not find alembic.ini in: [...].
Cause: The trilio-site-recovery package is not installed, or is installed in an unexpected location. The command searches /opt/openstack-protector/alembic.ini and /usr/share/trilio-site-recovery/alembic.ini.
Fix: Verify the package is installed:
dpkg -l trilio-site-recovery
If missing, install it from the Trilio apt repository configured at /etc/apt/sources.list.d/trilio-site-recovery.list:
apt-get install trilio-site-recovery
Do not place alembic.ini under /etc/protector/ — it is not installed there.
db sync fails: Access denied for user 'protector'
Symptom: db sync exits with a SQLAlchemy OperationalError containing Access denied.
Cause: The protector database user does not have the required privileges, or the password in protector.conf does not match the one set in MySQL.
Fix: On the MySQL host:
GRANT ALL PRIVILEGES ON protector.* TO 'protector'@'%' IDENTIFIED BY 'your-password';
FLUSH PRIVILEGES;
Verify the connection string in [database] connection matches the credentials you granted.
Schema revision check shows database ahead of the code
Symptom: tools/schema_revision.py exits with status 3: "the database is at X, which this code does not know about."
Cause: A newer version of the service has previously run db sync on this database, and the installed code is older than the schema.
Fix: Upgrade the trilio-site-recovery package to the version that introduced the recorded revision before starting the service. Do not run db sync with the older code against the newer schema.
Juju unit in BLOCKED state after upgrade: set local-site, pure-primary-site-name, pure-secondary-site-name
Symptom: After upgrading the charm to revision 16, the unit enters BLOCKED with the message set local-site, pure-primary-site-name, pure-secondary-site-name.
Cause: This is expected behaviour in charm revision 16 (1.0.24). The charm requires local-site to be explicitly set — the service no longer infers which site it is. When a Pure storage array is configured, the two site names are also required.
Fix:
juju config trilio-site-recovery-for-openstack local-site=<your-site-name>
# If using Pure storage:
juju config trilio-site-recovery-for-openstack \
pure-primary-site-name=<primary-site-name> \
pure-secondary-site-name=<secondary-site-name>
After setting these, the unit will leave BLOCKED and re-run db-sync automatically.
protector-manage db sync on OpenShift applies migrations incorrectly
Symptom: Migrations appear to run but the service cannot authenticate tokens or reach the database after an OpenShift deployment.
Cause: The OpenShift deployment requires twelve manifests applied in a specific order, including init Jobs (job-db-init, job-rabbitmq-init, job-keystone-init, job-db-sync). Running protector-manage db sync manually against an incomplete OpenShift deployment skips the database creation, RabbitMQ, and Keystone registration steps.
Fix: Use the installer script, which applies all manifests in the correct order and gates each init Job on its completion:
bash deploy/openshift/scripts/install.sh
Do not apply individual manifests manually for a new OpenShift deployment.