Home›Learn›MySQL failover with Orchestrator
MySQL · High availability · Tools

Orchestrator: failover for MySQL replication

Who promotes a replica when the source dies, and how do they know it is really dead?

Orchestrator is a service that reads your replication tree, judges failures by asking the replicas, and promotes a new source. It works with plain asynchronous replication and GTIDs.

Why this tool exists

Why you need something that watches the whole topology

You run one MySQL source and a few replicas with plain asynchronous replication. The source dies. Somebody has to pick the replica that has the most data, promote it, re-point every other replica to it and tell the app where writes go now. Doing that by hand, under pressure, is slow and easy to get wrong. Orchestrator is the tool that does it for you, and it does it by watching the replicas, not just the source.

What we are protecting

Writes. With async replication the replicas are fine and the data is there, but nobody is accepting writes until a replica is promoted and the app is pointed at it.

What we achieve

A failover decided by the replicas, not by one health check. GitHub reports "between 10 and 13 seconds of total outage time in most cases" with Orchestrator, Consul and a proxy layer (source below).

Planned work too

The same tool does a graceful takeover: make the source read-only, let the chosen replica catch up, promote it, demote the old source. Patching the source becomes a command, not a night shift.

What it is not

Not a proxy and not a backup. It tells your proxy or DNS where the writer is through hooks. A bad DELETE still reaches every replica, so you still need backups and point-in-time recovery.

How companies use it

Status you should know about

The original openark/orchestrator repository was archived on February 18, 2025. On April 9, 2026, ProxySQL announced it is taking over maintenance at github.com/ProxySQL/orchestrator. Release 4.30.0 was the first ProxySQL release (Apache 2.0). It adds Prometheus metrics, Kubernetes health endpoints and ProxySQL hostgroup integration. The latest tag on that repository is v4.32.1, and this page pins to it. Orchestrator was developed at Outbrain, Booking.com and GitHub. Percona says it welcomes the move. Its Operator for MySQL uses Orchestrator to manage asynchronous topologies (see MySQL on Kubernetes).

Not on async replication? InnoDB Cluster has its own failover in Group Replication and does not need Orchestrator. Orchestrator is for the classic source and replicas setup.

How it was done before

The failover by hand

Before tools like MHA and Orchestrator, a failover was a checklist you ran from a terminal. Say the source, db1, loses power. Here is the checklist, with MySQL 8.4 syntax and GTIDs on.

  1. Confirm db1 is really gone. If it is reachable, stop writes on it first: SET GLOBAL super_read_only = ON.
  2. On each replica run SELECT @@global.gtid_executed and compare. The replica whose set contains the most transactions is the furthest ahead.
  3. On that replica run STOP REPLICA; RESET REPLICA ALL; then SET GLOBAL super_read_only = OFF; SET GLOBAL read_only = OFF;.
  4. On every other replica run STOP REPLICA; CHANGE REPLICATION SOURCE TO SOURCE_HOST='db2', SOURCE_AUTO_POSITION=1; START REPLICA;.
  5. Move the writer name: update DNS, a virtual IP or the proxy config. Then check the app is writing.
  6. Later, rebuild or repair db1 before it rejoins. If it comes back with transactions nobody else has, they must not be silently lost.

Why not script all of that? People did, and those scripts are the ancestors of this tool. The hard parts are the decisions: is the source really dead or is the network flaky, which replica to promote when the most advanced one is on old hardware or in the wrong data center, and what to do when a second thing breaks mid-failover.

Step through it:

Explained clearly

What Orchestrator is, in plain words

1

The problem

A health check on the source alone cannot tell "the source is dead" from "my network blinked". Act on a blink and you promote a replica while the old source is still taking writes. That is split brain.

2

What it is

Orchestrator is a service that connects to every MySQL server in your replication topologies, reads their replication status, and draws the tree: who replicates from whom. It can show it, move replicas around the tree, and fail over. Its failure detection asks the replicas too. A dead source means the source cannot be reached and its replicas confirm they cannot see it either.

3

Follow one request

  1. The app writes to the writer name, which is a proxy or DNS entry, not a server.
  2. Orchestrator never sits in that path. It only watches and acts when something breaks.
  3. When the source dies, Orchestrator promotes a replica, then runs your hooks, or its built-in ProxySQL hooks, to move the writer name.
  4. The next write from the app lands on the new source.
4

What to watch

  • Orchestrator is itself a service that can fail. Run three or five nodes with raft (below), or accept a single point of failure on the failover side.
  • Recovery is opt in. Out of the box it detects and shows, and does not act.
  • Your proxy, DNS or service discovery is your job. Hooks make it automatic, they do not make it correct.

The moving parts

PartWhat it doesNotes
orchestrator serviceProbes every instance each InstancePollSeconds (5 in the sample config), builds the topology, runs detection every second, runs recoveries.HTTP API and web UI on :3000 by default.
Backend databaseStores what it learned: instances, topology, audit and recovery history.MySQL or the bundled SQLite. SQLite is fine for a lab or for raft nodes, where each node has its own.
orchestrator/raft3 or 5 nodes agree on a leader. Only the leader acts.Solves Orchestrator's own availability and cross-data-center isolation.
orchestrator-clientA shell wrapper over the HTTP API. Finds the leader if you give it every node.Set ORCHESTRATOR_API.
HooksYour commands before and after a recovery, plus built-in Consul KV and ProxySQL support.A non-zero exit from a pre-failover hook aborts the recovery.
Proxy or discovery layerSends the app to the current writer: ProxySQL, HAProxy with Consul, DNS.Not part of Orchestrator.

Step through it:

Step by step

Set it up (one test node, then production)

Pinned versions on this page: Orchestrator v4.32.1 from github.com/ProxySQL/orchestrator (4.30.0 was the release in ProxySQL's April 2026 announcement), MySQL 8.4 LTS. Start with one Orchestrator node and a SQLite backend in a lab. Move to three nodes with raft before production.

  1. Prepare MySQL. Orchestrator needs GTIDs (or Pseudo-GTID) to re-point replicas. Promotable servers need the binary log and log_replica_updates. Set a short replica heartbeat so a replica notices a dead source fast:
# my.cnf on every server
[mysqld]
server_id = 11                      # unique per server
gtid_mode = ON
enforce_gtid_consistency = ON
log_bin = binlog
log_replica_updates = ON
binlog_format = ROW
report_host = db1.example.com       # so Orchestrator finds replicas by name
replica_net_timeout = 4             # heartbeat every 2 s, replica gives up after 4 s

-- on each replica, once
CHANGE REPLICATION SOURCE TO SOURCE_HOST='db1.example.com', SOURCE_USER='repl',
  SOURCE_PASSWORD='...', SOURCE_AUTO_POSITION=1, SOURCE_CONNECT_RETRY=1, SOURCE_RETRY_COUNT=86400;
START REPLICA;
  1. Create the Orchestrator user on every MySQL server (grants from the Orchestrator docs):
CREATE USER 'orchestrator'@'orc_host' IDENTIFIED BY 'a-long-secret';
GRANT SUPER, PROCESS, REPLICATION SLAVE, REPLICATION CLIENT, RELOAD ON *.* TO 'orchestrator'@'orc_host';
GRANT SELECT ON meta.* TO 'orchestrator'@'orc_host';
  1. Install v4.32.1. Download the release for your platform from the releases page of github.com/ProxySQL/orchestrator (tag v4.32.1) and install it.
  2. Write /etc/orchestrator.conf.json. This one detects everything and recovers nothing until you opt a cluster in:
{
  "ListenAddress": ":3000",
  "BackendDB": "sqlite",
  "SQLite3DataFile": "/var/lib/orchestrator/orchestrator.db",
  "MySQLTopologyCredentialsConfigFile": "/etc/mysql/orchestrator-topology.cnf",
  "InstancePollSeconds": 5,
  "DiscoverByShowSlaveHosts": true,
  "ReasonableReplicationLagSeconds": 10,
  "RecoveryPeriodBlockSeconds": 3600,
  "RecoverMasterClusterFilters": [],
  "RecoverIntermediateMasterClusterFilters": [],
  "ApplyMySQLPromotionAfterMasterFailover": true,
  "PreventCrossDataCenterMasterFailover": true,
  "DetachLostReplicasAfterMasterFailover": true,
  "PreFailoverProcesses": ["/usr/local/bin/orc-pre-failover {failureCluster} {failedHost}"],
  "PostMasterFailoverProcesses": ["/usr/local/bin/orc-post-failover {failureCluster} {successorHost}:{successorPort}"]
}

The credentials file is a MySQL option file: [client] with user=orchestrator and password=.... RecoveryPeriodBlockSeconds: 3600 is the anti-flapping block: after a recovery on a cluster, Orchestrator will not auto-recover that cluster again for an hour unless a human acknowledges it. A pre-failover hook that exits non-zero aborts the recovery, so it is a good place for a last safety check.

  1. Start it and discover one server. The service finds the rest of the topology by itself:
systemctl start orchestrator
export ORCHESTRATOR_API=http://orc:3000/api
orchestrator-client -c discover -i db1.example.com:3306
orchestrator-client -c clusters
orchestrator-client -c topology -i db1.example.com:3306
  1. Opt a cluster in to automatic recovery. Do this only after a graceful takeover works in your lab. Use the cluster alias or name from clusters, never "*" on day one:
"RecoverMasterClusterFilters": ["orders"]

Move the writer name for you: ProxySQL hooks

From 4.30.0, Orchestrator can update ProxySQL hostgroups during a failover without custom scripts. It drains the old source, then promotes the new one in the writer hostgroup and runs LOAD MYSQL SERVERS TO RUNTIME and SAVE MYSQL SERVERS TO DISK. A ProxySQL outage does not block the MySQL failover.

"ProxySQLAdminAddress": "127.0.0.1",
"ProxySQLAdminPort": 6032,
"ProxySQLAdminUser": "admin",
"ProxySQLAdminPassword": "...",
"ProxySQLWriterHostgroup": 10,
"ProxySQLReaderHostgroup": 20,
"ProxySQLPreFailoverAction": "offline_soft"

Check it with orchestrator-client -c proxysql-test and -c proxysql-servers. With a ProxySQL Cluster, point Orchestrator at one node and let ProxySQL sync the rest.

Production: three nodes with raft

"RaftEnabled": true,
"RaftDataDir": "/var/lib/orchestrator",
"RaftBind": "orc1.example.com",
"DefaultRaftPort": 10008,
"RaftNodes": ["orc1.example.com", "orc2.example.com", "orc3.example.com"]

Each node keeps its own backend (SQLite is fine). Only the leader acts. Put the three nodes in three failure domains, then set ORCHESTRATOR_API to all three URLs and orchestrator-client will find the leader. For Kubernetes, 4.30.0 adds /health/live, /health/ready and /health/leader endpoints.

When it breaks

One failure, end to end

Three servers. db1 is the source, db2 and db3 replicate from it. Automatic recovery is on for this cluster, ProxySQL hooks are on, and the app writes through ProxySQL.

Step through it:

Planned work uses the same machinery without a crash. graceful-master-takeover-auto sets the source read-only, waits for the chosen replica to catch up, promotes it, turns it writable and makes the old source a replica of the new one. Expect a few seconds of write errors while the source is read-only.

Day to day

The commands you will actually run

All of these go through orchestrator-client against the API. Set ORCHESTRATOR_API first. -alias and --alias both work, and -i takes host:port.

Look

orchestrator-client -c clusters                              # clusters Orchestrator knows
orchestrator-client -c clusters-alias                        # same, with aliases
orchestrator-client -c topology -i db1:3306                  # ASCII tree of that topology
orchestrator-client -c which-master -i db2:3306              # who is the source of this instance
orchestrator-client -c replication-analysis                  # what Orchestrator thinks is broken now
orchestrator-client -c api -path audit-recovery              # recovery history, raw JSON
orchestrator-client -c which-api                             # which API endpoint the client picked

Planned switchover

orchestrator-client -c graceful-master-takeover-auto -alias orders                       # it picks the replica
orchestrator-client -c graceful-master-takeover-auto -alias orders -d db2:3306             # you pick the replica
orchestrator-client -c graceful-master-takeover -alias orders -d db2:3306                  # old source is placed below it, replication not started

Recover

orchestrator-client -c recover -i db1:3306                  # recover a failed instance Orchestrator agrees is failed; ignores the block period
orchestrator-client -c force-master-failover --alias orders   # fail over now, even if Orchestrator sees no problem
orchestrator-client -c ack-cluster-recoveries -alias orders   # acknowledge a recovery, unblocking the next one
orchestrator-client -c ack-all-recoveries

Move replicas (rejoin and rebalance)

orchestrator-client -c relocate -i db3:3306 -d db2:3306        # put db3 below db2; Orchestrator picks the method
orchestrator-client -c relocate-replicas -i db2:3306 -d db4:3306   # move all replicas of db2 below db4
orchestrator-client -c stop-replica -i db3:3306
orchestrator-client -c start-replica -i db3:3306
orchestrator-client -c set-read-only -i db3:3306
orchestrator-client -c register-candidate -i db2:3306 --promotion-rule prefer   # prefer, neutral, prefer_not, must_not; expires after an hour

Pause everything

orchestrator-client -c disable-global-recoveries     # no automatic recovery anywhere
orchestrator-client -c check-global-recoveries       # shows whether recoveries are enabled
orchestrator-client -c enable-global-recoveries

A server that was the old source comes back with data nobody else has, or with a different GTID set. Do not blindly relocate it. Check gtid_executed against the new source first, and rebuild it from a backup if it has errant transactions.

ProxySQL: orchestrator-client -c proxysql-test checks the connection, -c proxysql-servers lists the runtime server table.

What goes wrong

Failures to plan for

SymptomLikely causeFirst checkFix
Source died and nothing happenedThe cluster is not in RecoverMasterClusterFilters, recoveries are disabled globally, the block period is active, or a pre-failover hook exited non-zero.check-global-recoveries, api -path audit-recovery, the Orchestrator log.Fix the cause, then recover -i HOST:PORT. Manual recovery ignores the block and the filters.
Analysis says UnreachableMaster, no failoverReplicas still reach the source. Often a network path problem between Orchestrator and MySQL.Can the replicas replicate? replication-analysis.Fix the path. Do not force a failover while replicas are happy with the source.
Writes block, source is upLockedSemiSyncMaster: semi-sync is on, too few replicas ack, and the timeout is high.replication-analysis, semi-sync status variables on the source.Bring replicas back or relax the timeout. Orchestrator only acts if you set RecoverLockedSemiSyncMaster or EnforceExactSemiSyncReplicas.
Failover aborted: replica too far behindFailMasterPromotionOnLagMinutes or FailMasterPromotionIfSQLThreadNotUpToDate did their job.Lag on the candidate, relay log backlog.Decide: recover the lost transactions from the relay logs or binlogs, or force the promotion.
App still writes to the old sourceThe proxy or DNS hook failed. Post-failover hook errors are logged, and the recovery stays successful unless FailRecoveryOnFailedPostFailoverProcesses is true.Where does the writer name point? proxysql-servers.Fix the hook. Set FailRecoveryOnFailedPostFailoverProcesses if discovery is part of your SLO.
Old source comes back and takes writesSplit brain: nothing stopped it.Is it read-only? Does it have errant GTIDs?Make it read-only at boot, fence it, rebuild it. GitHub says this gap exists for apps inside an isolated data center and they work on a STONITH approach.
Orchestrator itself is goneSingle node, or shared backend that failed./health/ready, /health/leader.Run raft with 3 or 5 nodes in separate failure domains.
Replica cannot be re-pointedNo GTID auto-position, no log_replica_updates, or replication filters.The replica's settings against the requirements list.Fix the settings. Orchestrator needs GTID, Pseudo-GTID or binlog servers.
Monitoring

What to watch, and from where

From 4.30.0, Orchestrator serves Prometheus metrics at /metrics (on by default, PrometheusEnabled). The metric names in the docs:

SignalWhereAlert when
orchestrator_recoveries_total (labels type, result)Prometheus, scrape orc:3000/metricsAny failed result, or any recovery at all, if you want a page for each failover.
orchestrator_recovery_duration_secondsPrometheusLonger than your RTO budget.
orchestrator_discovery_errors_totalPrometheusRising: a server cannot be probed.
orchestrator_instances_total, orchestrator_clusters_totalPrometheusDrops: a cluster fell out of discovery.
/health/leader, /health/readyLoad balancer or Kubernetes probeNot exactly one leader.
replication-analysisCLI or /api/replication-analysisAnything other than empty.
Replication lag and heartbeatpt-heartbeat or your metrics, plus ReplicationLagQueryLag above ReasonableReplicationLagSeconds. Lag drives promotion decisions.

Also keep the recovery audit page (/web/audit-recovery) in the runbook. Related playbooks: Something is slow or broken, Synchronous replication and failover.

Hands off

Let the agent do it

Every change is shown to you first and runs only after you type an approval. Reads run straight away.

python3 -m dbagent.ha orc status --api http://orc:3000
python3 -m dbagent.ha orc takeover --cluster ALIAS [--to HOST:PORT]
python3 -m dbagent.ha orc recover --instance HOST:PORT
python3 -m dbagent.ha orc relocate --instance HOST:PORT --below HOST:PORT
python3 -m dbagent.ha orc ack --cluster ALIAS
python3 -m dbagent.ha orc pause
python3 -m dbagent.ha orc resume

takeover is the planned switchover. pause and resume turn global recoveries off and on. recover, relocate and ack match the client commands above.

Where this came from

Sources

Part 1 of 4 · Learn · 56 pagesAll pages

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.

Start 1: the basicsStart 2: ten conceptsStart 3: how a query travelsStart 4: napkin mathThe courseShort videosPostgreSQL 1: why PostgreSQLPostgreSQL 2: how it stores your dataPostgreSQL 3: what happens on every writePostgreSQL 4: high availability with PatroniPostgreSQL 5: running it as a DBREPostgreSQL 6: when it breaksPostgreSQL on Kubernetes: CloudNativePGMySQL 1: why MySQLMySQL 2: how it stores your dataMySQL 3: what happens on every writeMySQL 4: high availability with InnoDB ClusterMySQL 5: running it as a DBREMySQL 6: when it breaksMySQL failover with OrchestratorMySQL on Kubernetes: the Percona operatorsMongoDB 1: why MongoDBMongoDB 2: how it stores your dataMongoDB 3: what happens on every writeMongoDB 4: high availability with replica setsMongoDB 5: running it as a DBREMongoDB 6: when it breaksMongoDB on Kubernetes: the Percona operatorB-tree and LSM treeRedis 1: why RedisRedis 2: how it stores your dataRedis 3: high availabilityRedis 4: running it as a DBRERedis 5: when it breaksCassandra 1: why CassandraCassandra 2: how it stores your dataCassandra 3: high availabilityCassandra 4: running it as a DBRECassandra 5: when it breaksVector databases 1: why vector searchVector databases 2: how it stores your dataVector databases 3: high availabilityVector databases 4: running it as a DBREVector databases 5: when it breaksDatabase familiesEngines side by sideQueries that look fine and are notLost updates and write skewMany servers 1: keep a copy runningMany servers 2: who is the leaderMany servers 3: CAP as settingsMany servers 4: unique IDsMany servers 5: split the dataMany servers 6: across servicesMany servers 7: a thousand databasesStaff path, zero to architect