Lesson 7 of 7 · Automation

Automating Safely

Staged rollouts, dry runs, safety nets, secrets and logging, where automation runs, testing it, and the skills DBAs need.

Beginner 9 sections 5 min read

Automation multiplies everything

Automation makes good changes fast and consistent, and it does the same to bad ones. A typo a DBA would make on one server, automation can make on three hundred in a minute. Safe automation is built to preview changes, roll out gradually, stop when something's wrong, and leave a clear record.

This is especially true for databases, which hold data that can't be rebuilt from code. These practices are what make DBAs, and the auditors and managers they report to, comfortable letting automation touch production.

Roll out in stages

Dry runTest DBsOne server25% wave All servers preview whatwould changedev and testfirsta productioncanarya batch ata time the rest ofproduction checkcheckcheckcheck any check fails: stop, alert, and roll back
Dry runs
Preview every change before making it: terraform plan, Ansible's --check --diff, or a migration tool's preview of the SQL it would run. Review the preview, not just the code.
Test first
Run new automation on development and test databases before production, ideally automatically in the pipeline.
Canaries and waves
Apply to one production database first, the canary, then in batches. Ansible's serial setting, for example, limits how many servers change at once.
Checks between stages
After each stage, verify automatically: is the database up, can the application connect, are key queries still fast? If not, stop.

Safety nets

  • Prechecks. Check conditions before changing anything: enough disk space, a recent backup, the right version, no blocking sessions.
  • A backup or restore point first. Before risky changes, take a backup or create a guaranteed restore point, so there's always a way back.
  • Rollback built in. Every change should have a tested way to undo it, written at the same time as the change.
  • Fail fast. Stop at the first error, rather than carrying on and making things worse.
  • Limits and guardrails. Automatic fixes should act only within agreed limits, such as never growing a tablespace past a set size, and call a person otherwise.
  • Approvals for production. Pipelines pause for a person to approve production changes, with the preview in front of them.

Secrets, access, and logs

Secrets
Passwords and keys come from a vault, such as HashiCorp Vault, Ansible Vault, or a cloud secret manager, at run time. Never in the code, never in the logs.
Least privilege
Automation accounts get only the access they need, and production access is separate from test.
Logging
Every run records who started it, what changed, where, and the result. Pipelines and tools such as AWX keep this history automatically, which is exactly what auditors want.

Where automation runs

Way to run itExamplesGood for
Schedulerscron, Windows Task Scheduler, enterprise schedulers such as Control-MRecurring jobs, such as nightly checks
CI/CD pipelinesGitHub Actions, GitLab CI, JenkinsChanges triggered by Git, with tests and approvals
Automation platformsAWX and Red Hat Ansible Automation PlatformRunning Ansible with a web interface, permissions, schedules, and logs
Event-driven automationEvent-Driven Ansible, monitoring tools' runbook actionsResponding to alerts automatically
Self-service portalsJira Service Management, ServiceNow, internal portalsLetting other teams request databases, refreshes, and access

Testing the automation itself

Automation is code, and it needs tests like any other code:

  • Linting: tools such as ansible-lint, terraform validate, and sqlfluff catch mistakes and bad practices.
  • Test environments: throwaway servers or containers, such as Molecule for Ansible roles, where the automation runs for real and the result is checked.
  • Idempotency tests: run the automation twice; the second run should change nothing.

Skills DBAs need for automation

SkillWhy
SQL and PL/SQL (or T-SQL)Still the heart of database automation: checks, fixes, and reports
Bash, and PowerShell for WindowsGluing steps together, and running tasks on servers
PythonThe most common language for automation beyond shell scripts, and for calling APIs
YAML and JSONThe formats of Ansible playbooks, pipelines, Kubernetes files, and API responses
REST APIsHow automation talks to clouds, monitoring tools, and ticketing systems
GitWhere all automation code lives
Terraform and AnsibleThe main infrastructure and configuration tools, covered next in this path

In practice: the patch run that stopped itself

Kofi's playbook applies a quarterly patch to 120 Oracle databases. The test databases pass. The production canary, one database, also patches cleanly, but the post-check finds that a key application connection now fails, because the patch changed a network encryption default the application relies on.

Because the rollout runs in stages with checks, the pipeline stops after one production database instead of 120. Kofi rolls back the canary, adds the setting to the playbook, adds a connection test to the post-checks, and reruns. The patch goes out the next night without incident. Without the staging and checks, the same problem would have hit every production database at once.

Key takeaways

  • Automation multiplies mistakes as well as good changes, so it must be built for safety.
  • Roll out in stages: dry run, test databases, one production canary, waves, then everything, with checks between stages.
  • Build in prechecks, a backup or restore point, rollback, fail-fast behavior, limits, and approvals.
  • Keep secrets in vaults, give automation least privilege, and log every run.
  • Run automation from schedulers, pipelines, platforms such as AWX, events, or self-service portals, and test it like any other code.
  • SQL, Bash or PowerShell, Python, YAML, APIs, Git, Terraform, and Ansible are the core automation skills for DBAs.