What changes when you stop touching servers one at a time?
At a thousand databases you do not run servers, you run a system that runs them. This page maps the layers of that system and points to the page that explains each one.
Running one database well is a craft. Running a thousand is a different job. You stop touching servers one at a time, and you start designing a system that touches them for you, with brakes. This page is the map of that system, and each part links to a page that goes deep.
A routine 10 minute task on 1,000 servers is 10,000 minutes, about 167 hours (derived). Nobody does that by hand every quarter, so it either gets automated or it does not get done.
With hundreds of clusters, some server is failing somewhere most days. Failover cannot depend on a person being awake.
A bad change hits one cluster, or the whole fleet. You choose which by how you roll it out: in waves, with a stop button.
Not "automate everything". Automation without guardrails moves a mistake to every server at once.
None of these numbers are ours, and none are a promise for your fleet. Read them as proof that the approach works at that size.
The early version of fleet management is a spreadsheet of hostnames and a shell loop. It works for ten servers.
for h in $(cat hosts.txt); do ssh $h ...; done to change a setting.The fix is not a better loop. It is four ideas: a source of truth for what exists, config that is declared and not typed, changes that go in waves with a stop rule, and a way to know the state afterwards.
Step through it:
Think of nine layers. Each answers one question, costs something, and decides what happens to the app's request.
| Layer | The problem it solves | What it costs | What the app sees |
|---|---|---|---|
| 1. Inventory and service discovery | What databases exist, who owns them, what role and version each has, and where the writer is. | Someone must keep it true. Make it generated, not hand-edited: from Terraform state, cloud tags, or the orchestrator itself. | Nothing directly. A stale inventory causes wrong changes. |
| 2. Config management (Ansible, Terraform) | Servers built and configured the same way, from files in version control. | Review discipline and a way to test changes. | Fewer surprises: a replica behaves like the primary. |
| 3. Proxies and poolers (ProxySQL, HAProxy, PgBouncer) | A stable address for the writer, connection reuse, and a place to drain traffic. | One more hop, and one more thing to run and keep in sync. | One name for writes. Failover moves the target, not the app config. |
| 4. Orchestrators and operators | Someone to watch replication or pods and promote a new primary. | You must run them, and understand when they act. See below. | A few seconds of errors, then writes work again. |
| 5. Failover with guardrails | Automatic recovery without automatic mistakes. | Rules to maintain, and some failures that stay manual on purpose. | Fewer long outages, a small risk of a wrong decision. |
| 6. Backups and restore tests | Recovery from the failures failover cannot fix: bad deletes, corruption, a lost region. | Storage, and the discipline to restore on a schedule. | Nothing, until the day it matters. |
| 7. Upgrades in waves | Moving a thousand servers to a new version without one big bang. | Mixed-version fleets for weeks, and a rollback plan. | No outage if replicas go first and the switch is graceful. |
| 8. Observability | Knowing the state of every server, cluster and tool. | Metrics storage and alert tuning. | Problems found before users report them. |
| 9. Runbooks and agents | Making the on-call response the same for everyone, at any hour. | Writing and testing them. | Shorter outages and fewer mistakes under pressure. |
| If you run | Orchestrator or operator | Read |
|---|---|---|
| MySQL, source and replicas | Orchestrator | Orchestrator for MySQL |
| MySQL, Group Replication | Built in, with MySQL Router | InnoDB Cluster |
| MySQL on Kubernetes | Percona operators | MySQL on Kubernetes |
| PostgreSQL on VMs | Patroni with etcd and HAProxy | Patroni |
| PostgreSQL on Kubernetes | CloudNativePG | CloudNativePG |
| MongoDB | Replica set election, Percona operator on Kubernetes | Replica sets, MongoDB on Kubernetes |
Step through it:
You do not need all nine layers on day one. This order gives you the most safety per hour of work.
# one record (YAML, stored in version control or generated from Terraform state) - cluster: orders engine: mysql version: "8.4" tier: 1 # 0 = most critical, 5 = least zone: us-west-2a role: primary # primary | replica owner: team-payments
serial and max_fail_percentage: change one host, then 10 percent, then the rest, and stop if too many fail.# site.yml
- hosts: mysql_replicas
serial: [1, "10%", "50%"] # canary, then a tenth, then half
max_fail_percentage: 10 # abort the play if more than 10 percent of a batch fails
tasks:
- name: apply my.cnf
ansible.builtin.template: {src: my.cnf.j2, dest: /etc/mysql/conf.d/fleet.cnf}
notify: restart mysqlterraform plan -out=tfplan # always read the plan terraform apply tfplan # apply exactly what you read
Keep one Terraform state per cluster or per tier, not one for the fleet, so a bad apply cannot touch everything.
INSERT INTO mysql_servers (hostgroup_id, hostname, port) VALUES (10, 'db1.example.com', 3306); INSERT INTO mysql_servers (hostgroup_id, hostname, port) VALUES (20, 'db2.example.com', 3306); LOAD MYSQL SERVERS TO RUNTIME; SAVE MYSQL SERVERS TO DISK;
For PostgreSQL on VMs, HAProxy checks Patroni's REST API (/primary), as on the Patroni page. For connection reuse, PgBouncer in transaction mode assigns a server connection only for the length of a transaction, which breaks features that depend on session state, so check your app first (see connection pooling).
[databases] orders = host=orders-rw port=5432 dbname=orders [pgbouncer] listen_port = 6432 pool_mode = transaction default_pool_size = 20 max_client_conn = 1000 auth_type = scram-sha-256 auth_file = /etc/pgbouncer/userlist.txt
Automatic failover is a decision made by software while you sleep. Three kinds of guardrail keep it from making things worse: evidence (more than one observer agrees), limits (not again within an hour, not across regions) and escape hatches (a pause switch and a manual path). Every tool in this section has them.
| Guardrail | Where it shows up |
|---|---|
| Several observers must agree | Orchestrator asks the replicas, not just the source. Patroni needs the leader key in etcd. Group Replication needs a majority. CloudNativePG checks a lease and, with quorum failover, that the replica cannot miss a synchronous commit. |
| No flapping | Orchestrator's RecoveryPeriodBlockSeconds: one automatic recovery per cluster per period, unless a human acknowledges it. |
| Opt in per cluster | Orchestrator recovers only clusters in RecoverMasterClusterFilters. |
| Stay in the region | Orchestrator PreventCrossDataCenterMasterFailover and PreventCrossRegionMasterFailover. |
| A pre-failover veto | A non-zero exit from an Orchestrator pre-failover hook aborts the recovery. |
| A global pause | Orchestrator disable-global-recoveries. Percona operators: spec.pause. |
| Fence the old primary | Make it read-only at boot, or fence it. GitHub notes a gap for apps inside an isolated data center and says it is working on a STONITH approach. |
Step through it:
Both GitHub and Uber describe the same shape: replicas first, a small canary, then tiers or batches, a soak period, and a point of no return you cross on purpose. The primary is moved by a graceful failover to an upgraded replica, not upgraded in place.
Step through it:
These are patterns, with the exact commands on the engine pages.
| Task | How | Where |
|---|---|---|
| See every cluster and its topology | orchestrator-client -c clusters and -c topology -i HOST:PORT (MySQL). kubectl cnpg status CLUSTER (CNPG). kubectl get pxc,ps,psmdb -A (Percona operators). | Orchestrator, CNPG |
| Pause automation | orchestrator-client -c disable-global-recoveries. Percona operators: set spec.pause. | Orchestrator, MySQL on Kubernetes |
| Planned switchover | orchestrator-client -c graceful-master-takeover-auto -alias CLUSTER, kubectl cnpg promote CLUSTER INSTANCE, patronictl switchover. | Engine pages |
| Roll a config change in waves | Ansible serial and max_fail_percentage, one batch per tier. | This page |
| Prove a backup | A scheduled restore into a scratch cluster, then a checksum or row-count check. | Backup and restore |
| Plan a major upgrade | Replicas first, canary, tiers, soak, graceful switchover. | Major upgrades |
| Symptom | Likely cause | First check | Fix |
|---|---|---|---|
| A change hit hosts it should not have | Stale or hand-edited inventory. | Compare inventory with what the cloud or Terraform says exists. | Generate the inventory. Run changes with --check or a plan first. |
| A bad config reached the whole fleet | No waves, no stop rule. | Which hosts changed, and when. | Use serial and a failure threshold. Roll back with the same pipeline. |
| Automation failed over twice, then stopped | The anti-flapping block did its job. | Orchestrator audit, why the first failover happened. | Find the root cause before you acknowledge and unblock. |
| The app still writes to the old primary | Proxy or discovery not updated. | Where the writer name points. | Make the proxy update part of the recovery, and alert when it fails. |
| Backups exist, restore fails | Never tested, or the key or bucket changed. | The last restore test result. | Schedule restore tests. Page on a failed test, not just a failed backup. |
| Orchestrator or operator is down | It is a single service. | Health endpoints. | Run it with raft or several replicas. Databases keep running without it, but nobody heals them. |
| Upgrade wave stuck | A client or query that works on the old version only. | Error logs for the new version, query plan changes. | Fix and re-run the wave. Uber and GitHub both report client library and query issues. |
| Alert noise at scale | Per-host alerts instead of per-cluster. | Alert volume by rule. | Alert on cluster health. Link each alert to one runbook. |
| Signal | Where | Alert when |
|---|---|---|
| Clusters with no healthy primary | Orchestrator, operators, Patroni | Any, at once. |
| Failovers and recoveries per day, per cluster | Orchestrator /metrics, Kubernetes events | More than one on a cluster in a day. |
| Replication lag per cluster | Engine metrics | Lag above the RPO for that tier. |
| Last good backup and last good restore test | Backup tool and test job | Older than the window. |
| Version and config drift | Inventory against reality | Any host off its declared version. |
| Wave progress and failure rate | The upgrade pipeline | Failure rate over the stop rule. |
| The control plane itself | Orchestrator health, operator deployments, proxy health | Any down. |
Each alert needs an owner and a runbook. See on-call and symptoms.
The agent can run the tool commands from the pages above. Every change is shown to you first and runs only after you type an approval. Reads run straight away. The commands are listed on each tool page:
python3 -m dbagent.ha orc ..., see Orchestrator.python3 -m dbagent.ha k8s ... --kind cnpg, see CloudNativePG.python3 -m dbagent.ha k8s ... --kind pxc|ps|psmdb, see MySQL on Kubernetes and MongoDB on Kubernetes.More on the agent is on the agent page. A runbook is the same thing for a human: the exact commands, in order, with the check after each one.
How do databases actually work? From one row on disk to transactions: the words you need, PostgreSQL, MySQL and MongoDB from the files up, then Redis, Cassandra and vector search, side by side, and the query and concurrency traps.