Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Sovereign, high-performance data protection

Database Migrations

When you start a newer KMS binary against an existing database, the server checks the stored database version and applies any required schema or data updates automatically before opening its HTTP and KMIP ports. Once the update completes, the server records the new version and begins serving requests. Subsequent restarts at the same version start immediately without re-running completed steps.

For KMIP protocol and client behavior changes when upgrading to 5.30, see Upgrading to 5.30.

KMS startup: the stored database version decides what happens

Supported source versions

You can upgrade directly to the current release without installing intermediate versions in between, subject to the version boundaries below:

BackendSupported in-place upgradeEarlier versions
SQLite, PostgreSQL, MySQL, MariaDB, Percona XtraDB Cluster5.0.0 or later: automatic in-place upgrade at startup.< 5.0.0: startup is refused when db_version is below 5.0.0. Export all objects from the old KMS, initialize an empty database on the new KMS, and import them.
Redis with Findex (non-FIPS only)5.12.0 or later: automatic in-place upgrade at startup.< 5.12.0 (or unversioned): startup is refused. Export all objects from the old KMS, initialize an empty Redis database on the new KMS, and import them.

On large databases, the first startup after an upgrade takes longer than a normal boot while new indexes or data backfills run.

Upgrading to 5.30.0: stored state synchronization

The lifecycle column is the source of truth for an object's state; the State inside the stored attributes and key block can lag it after a state change. KMS always reports the column, so clients see the right state. The 5.30.0 upgrade writes that reported state into the stored attributes (and, except for destroyed objects, the key-block attributes) of every object once. API responses do not change; rows whose stored JSON cannot be parsed are skipped with a warning. Because this step rewrites rows, it adds to the first startup time on large databases.

Before you upgrade

  1. Stop running instances of the previous version. Starting a new KMS binary does not stop older KMS nodes that are already connected to the database. Shut down the older instances before starting the new release so they do not write stale records during the upgrade.
  2. Back up the database while the KMS is stopped. For SQLite, copy the entire sqlite_path directory (cp -a). For PostgreSQL, MySQL, MariaDB, Percona XtraDB Cluster, and Redis, take a cold dump or snapshot with your database's backup tool.

Multiple instances and high availability

If several KMS instances of the new version start concurrently against the same database, one instance runs the migration while the others wait before opening their HTTP and KMIP listeners (retrying for up to 31 minutes). As soon as the first instance finishes, the waiting instances observe the updated database version and start serving traffic.

Concurrent KMS instances: one migrates, the others wait

Deployment requirements during upgrades

  • PostgreSQL behind PgBouncer: connect to PostgreSQL directly or use session pool mode. transaction pool mode cannot hold the startup coordination lock across statements.
  • MySQL Galera and Percona XtraDB Cluster: point all starting KMS instances at the same database node during the upgrade. Startup coordination on MySQL-family clusters is local to a single node.
  • SQLite: leave <sqlite_path>/kms.db.migration.lock in place on disk. Sharing a SQLite database across processes requires a filesystem that supports OS file locks.
  • Redis with Findex (non-FIPS only): if a migrating KMS process is terminated with SIGKILL mid-upgrade, newly started instances wait up to 30 minutes for the previous startup lease to expire unless kms_db_migration_lock is deleted after confirming no other KMS instance is running.

Interrupted upgrades

Every migration step is safe to resume. If the KMS process or database stops before an upgrade finishes, start the new KMS binary again; it detects the unfinished run, skips steps that already completed, and finishes the remaining work.

A failed 5.30 start on PostgreSQL is not a clean slate

A 5.30 start that fails after it touched the database has already installed the triggers trg_objects_state_derive, trg_object_state_events_apply and trg_object_state_event_tombstones_apply (ENABLE ALWAYS). Either resume 5.30 forward, or restore the cold pre-upgrade backup before starting 5.29.x or earlier. Never point 5.29.x or earlier at the touched database unless the three triggers are dropped as described in Deliberate PostgreSQL downgrade and return: otherwise the older release silently loses Activate, Revoke and Destroy state changes.

Downgrades and recovery

KMS binaries using the version-sequenced migration runner refuse startup when the database requires a newer release than the binary (see db_version and min_compatible_version), before applying application schema or data migrations:

Database version X is newer than this KMS server version Y: refusing to start. Upgrade the KMS server to X or later.

Older releases without the version-sequenced runner do not necessarily enforce this check. Do not treat an older binary starting successfully as proof that it can safely use an upgraded database.

To revert to a previous KMS release, stop the new KMS instances, restore your pre-upgrade database backup, and start the previous KMS binary. Restoring that backup restores its earlier state: keys and other changes made after the backup are not retained. In-place down-migration is not currently supported.

Restoring after live traffic

Keys that were revoked (including as compromised) or destroyed after the backup was taken come back Active when you restore it. Before reopening client traffic, replay the Revoke and Destroy operations recorded in the audit log after the backup time.

Keep the audit events in a dedicated audit database, so that restoring the object store never rewinds the audit trail: the PostgreSQL audit backend refuses to start when --audit-postgres-url points at the object database.

Resetting a test database

Starting the server with --clear-database (or clear_database = true under [db] in kms.toml) deletes all stored objects and resets the recorded database version to the running binary. Never use --clear-database on production data you intend to keep.

db_version and min_compatible_version

The database records two versions. db_version is the newest KMS that wrote it and never decreases. min_compatible_version is the oldest KMS able to serve it: it is the compatibility floor of the release that last wrote the database (5.30.0 for every 5.30.x), and only a release that makes an intentional breaking storage change raises it.

Startup is refused only when min_compatible_version is newer than the binary. A database without min_compatible_version (written before it existed) is refused whenever db_version is newer, exactly as before. A 5.30.x patch rollback, or any rollback to a release inside the compatibility window, therefore starts: db_version stays at the newer release and the older binary leaves the newer schema untouched (no DDL, no purge).

A newer release that stopped in the middle of a migration (state upgrading) is always refused by an older binary, even inside the compatibility window: resume the migration with the newer release, or restore the pre-upgrade backup.

Clustered MySQL databases created before 5.14.0

Databases created on MySQL before KMS 5.14.0 declared UNIQUE indexes rather than PRIMARY KEY constraints on tags and read_access. New installations on 5.14.0 or later already have primary keys. If you are upgrading a pre-5.14.0 database onto a cluster that enforces primary keys (such as Percona XtraDB Cluster with pxc_strict_mode=ENFORCING or MariaDB Galera), run the following statements as a privileged MySQL user while KMS traffic is stopped before starting the new server:

ALTER TABLE tags
    DROP INDEX id,
    MODIFY id VARCHAR(128) NOT NULL,
    MODIFY tag VARCHAR(255) NOT NULL,
    ADD PRIMARY KEY (id, tag);

ALTER TABLE read_access
    DROP INDEX id,
    MODIFY id VARCHAR(128) NOT NULL,
    MODIFY userid VARCHAR(255) NOT NULL,
    ADD PRIMARY KEY (id, userid);