Automating Safely
Staged rollouts, dry runs, safety nets, secrets and logging, where automation runs, testing it, and the skills DBAs need.
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 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
serialsetting, 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 it | Examples | Good for |
|---|---|---|
| Schedulers | cron, Windows Task Scheduler, enterprise schedulers such as Control-M | Recurring jobs, such as nightly checks |
| CI/CD pipelines | GitHub Actions, GitLab CI, Jenkins | Changes triggered by Git, with tests and approvals |
| Automation platforms | AWX and Red Hat Ansible Automation Platform | Running Ansible with a web interface, permissions, schedules, and logs |
| Event-driven automation | Event-Driven Ansible, monitoring tools' runbook actions | Responding to alerts automatically |
| Self-service portals | Jira Service Management, ServiceNow, internal portals | Letting 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, andsqlfluffcatch 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
| Skill | Why |
|---|---|
| SQL and PL/SQL (or T-SQL) | Still the heart of database automation: checks, fixes, and reports |
| Bash, and PowerShell for Windows | Gluing steps together, and running tasks on servers |
| Python | The most common language for automation beyond shell scripts, and for calling APIs |
| YAML and JSON | The formats of Ansible playbooks, pipelines, Kubernetes files, and API responses |
| REST APIs | How automation talks to clouds, monitoring tools, and ticketing systems |
| Git | Where all automation code lives |
| Terraform and Ansible | The 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.