Clean the database

The Compute service (nova) automatically manages database cleanup by using Kubernetes cron jobs configured in the OpenStackControlPlane CR. It follows a three-step sequence: soft-deleting instances, archiving rows to shadow tables, and purging old data.

Note

Database archiving and purging operations can impact database performance during execution. Schedule manual operations during maintenance windows or low-usage periods.

Configure database management

The Compute service (nova) uses per-cell Kubernetes cron jobs to archive and purge deleted instance records. By default, these jobs run daily at midnight to archive rows older than 30 days and purge rows older than 90 days. You can configure the schedule and retention ages for each cell.

Procedure

  1. Open your openstack_control_plane.yaml file to edit the OpenStackControlPlane CR.
  2. Add the dbPurge parameter to the cellTemplates section for each cell that you want to configure:
    apiVersion: core.openstack.org/v1beta1
    kind: OpenStackControlPlane
    metadata:
      name: openstack
    spec:
      nova:
        template:
          cellTemplates:
            cell0:
              dbPurge:
                archiveAge: 30
                purgeAge: 90
                schedule: 0 0 * * *
            cell1:
              dbPurge:
                archiveAge: 90
                purgeAge: 120
                schedule: 15 0 * * *
    • archiveAge: The number of days before a deleted row is archived. The default value is 30.
    • purgeAge: The number of days before an archived row is purged from the shadow tables. The default value is 90.
    • schedule: When to run the cron job in crontab format. The default value is 0 0 * * * (midnight daily).
  3. Save and close openstack_control_plane.yaml.
  4. Update the control plane:
    $ oc apply -f openstack_control_plane.yaml

Results

  • Check the status of the database management cron job for a cell:
    $ oc events --for=cronjob/nova-<cellname>-db-purge

    Replace <cellname> with the name of the cell, for example cell0 or cell1.

Manual database management commands

You can manually manage the Compute database by using nova-manage commands inside a nova-conductor pod. Run commands within a cell-specific pod to target an individual cell, or use the --all-cells option from the cell0 conductor pod to target the entire deployment.

Examples
  • Archive deleted rows
$ oc exec nova-cell0-conductor-0 -- nova-manage db archive_deleted_rows \
  --max_rows <number> \
  --before <date> \
  --verbose
  • Purge archived rows from shadow tables
$ oc exec nova-cell0-conductor-0 -- nova-manage db purge \
  --before <date> \
  --verbose \
  --all-cells
  • Archive and purge in one operation
$ oc exec nova-cell0-conductor-0 -- nova-manage db archive_deleted_rows \
  --max_rows <number> \
  --purge \
  --verbose