You see status=SHUNNED on a backend in stats_mysql_connection_pool or runtime_mysql_servers. The backend itself looks healthy when you connect directly. Queries may be failing or routing to fewer backends than expected, but the MySQL server is up and accepting connections.
SHUNNED is ProxySQL’s protection mechanism, not a bug. When a backend generates more than mysql-shun_on_failures connection errors within one second, or when its replication lag exceeds the configured max_replication_lag, ProxySQL temporarily removes it from rotation. The backend typically returns to ONLINE on its own within mysql-shun_recovery_time_sec (default 10 seconds), provided there is activity in the connection pool for that hostgroup.
The operational question is not “why is it SHUNNED?” but “is this transient protection, or is something repeatedly triggering it?” A single SHUNNED backend is a TICKET. Zero ONLINE backends in a hostgroup is a PAGE.
What this means
ProxySQL’s monitor module continuously health-checks backends via connect, ping, read-only, and replication lag probes. The results drive status transitions in the hostgroup manager. When the monitor detects that a backend has accumulated too many failures or is too far behind on replication, it flips that backend’s status to SHUNNED.
The two triggers are distinct:
Connection error threshold: If more than
mysql-shun_on_failures(default 5) errors occur within one second, the backend is shunned. These errors come fromConnERRinstats_mysql_connection_pool: failedconnect()calls, authentication failures, backendmax_connectionsexhaustion, or network unreachability.Replication lag threshold: If
max_replication_lagis set to a non-zero value inmysql_serversfor a backend (default is 0, meaning disabled), and the monitor detectsSeconds_Behind_Masterexceeding that value, the backend is shunned until replication catches up.
Recovery is not purely timer-based. The backend is brought back ONLINE only after mysql-shun_recovery_time_sec has elapsed AND there is activity in the connection pool for the specific hostgroup. A hostgroup with no client traffic will not recover shunned nodes automatically.
flowchart TD
A["Backend ONLINE"] -->|"ConnERR > shun_on_failures\nwithin 1 second"| B["Backend SHUNNED"]
A -->|"replication lag >\nmax_replication_lag"| B
B -->|"recovery_time elapsed\nAND pool activity exists"| A
B -->|"no pool activity\nfor hostgroup"| C["Stays SHUNNED"]
C -->|"client traffic resumes"| ASHUNNED prevents new connections but does NOT kill existing ones. Queries already in flight on a shunned backend continue to execute. Only the SHUNNED_REPLICATION_LAG state (Group Replication, v2.3.0+) terminates existing connections. If you see ConnUsed > 0 on a SHUNNED backend, those are queries that were routed before the status change.
Common causes
| Cause | What it looks like | First thing to check |
|---|---|---|
| Connection errors exceeding threshold | ConnERR rising rapidly, then status flips to SHUNNED | monitor.mysql_server_connect_log and monitor.mysql_server_ping_log |
| Replication lag exceeding max_replication_lag | Only replicas shunned, writer stays ONLINE | SHOW SLAVE STATUS on the affected backend |
| Monitor-induced flapping | Rapid ONLINE to SHUNNED cycling, backend healthy when checked directly | Monitor ping log for alternating success/failure pattern |
| MySQL wait_timeout closing pooled connections | Periodic ConnERR spikes matching the wait_timeout interval | Backend wait_timeout vs ProxySQL mysql-connection_max_age_ms |
| Stale backend entries after orchestration churn | ConnERR on backends that no longer exist | runtime_mysql_servers for entries pointing to removed hosts |
| Galera max_writers shunning (Issue #3618) | Nodes SHUNNED due to max_writers, never auto-recover | shunned_automatic flag in runtime_mysql_servers |
Quick checks
Run these against the admin interface (default port 6032). All are read-only.
# Check current backend statuses in the connection pool
mysql -u admin -padmin -h 127.0.0.1 -P 6032 \
-e "SELECT hostgroup, srv_host, srv_port, status, ConnUsed, ConnFree, ConnOK, ConnERR FROM stats_mysql_connection_pool;"
# Check runtime server configuration including max_replication_lag
mysql -u admin -padmin -h 127.0.0.1 -P 6032 \
-e "SELECT hostgroup_id, hostname, port, status, max_connections, max_replication_lag FROM runtime_mysql_servers;"
# Check monitor ping and connect results for recent failures
mysql -u admin -padmin -h 127.0.0.1 -P 6032 \
-e "SELECT * FROM monitor.mysql_server_ping_log ORDER BY time_start_us DESC LIMIT 50;"
mysql -u admin -padmin -h 127.0.0.1 -P 6032 \
-e "SELECT * FROM monitor.mysql_server_connect_log ORDER BY time_start_us DESC LIMIT 50;"
# Check replication lag readings from the monitor
mysql -u admin -padmin -h 127.0.0.1 -P 6032 \
-e "SELECT * FROM monitor.mysql_server_replication_lag_log ORDER BY time_start_us DESC LIMIT 20;"
# Check monitor check counters (OK vs ERR rates)
mysql -u admin -padmin -h 127.0.0.1 -P 6032 \
-e "SELECT Variable_Name, Variable_Value FROM stats_mysql_global WHERE Variable_Name LIKE 'MySQL_Monitor_%check%';"
# Check current shun-related variables
mysql -u admin -padmin -h 127.0.0.1 -P 6032 \
-e "SELECT variable_name, variable_value FROM global_variables WHERE variable_name IN ('mysql-shun_on_failures','mysql-shun_recovery_time_sec');"
# Check queries affected by mid-flight status changes
mysql -u admin -padmin -h 127.0.0.1 -P 6032 \
-e "SELECT Variable_Name, Variable_Value FROM stats_mysql_global WHERE Variable_Name IN ('backend_lagging_during_query','backend_offline_during_query');"
How to diagnose it
Identify which backends are SHUNNED and in which hostgroups. A backend can be SHUNNED in one hostgroup but ONLINE in another if the
max_replication_lagthreshold differs per entry inmysql_servers. Querystats_mysql_connection_poolfor the full picture, not justruntime_mysql_servers.Check whether ConnERR is the trigger. Look at
ConnERRinstats_mysql_connection_poolfor the affected backend. If it is rising, the shunning is error-driven. Cross-reference withmonitor.mysql_server_connect_logandmonitor.mysql_server_ping_logto find the specific error type: connection refused, timeout, auth failure.Check whether replication lag is the trigger. If only reader hostgroup members are SHUNNED and the writer is fine, look at
monitor.mysql_server_replication_lag_log. Verify thatmax_replication_lagis set to a non-zero value for those backends inruntime_mysql_servers. Ifmax_replication_lag = 0, lag checking is disabled and this is not the cause.Determine if the backend is actually unhealthy. Connect directly to the backend MySQL, bypassing ProxySQL. Run
SHOW SLAVE STATUS, checkSHOW PROCESSLIST, and verify the backend is accepting connections. If the backend is healthy when accessed directly but SHUNNED in ProxySQL, the issue is in the monitor path: network between proxy and backend, monitor credentials, or aggressive thresholds.Check for flapping. If the backend cycles between ONLINE and SHUNNED rapidly (more than 3 transitions in 10 minutes), look at the monitor log timestamps. Flapping indicates the monitor intervals or
shun_on_failuresthreshold are too aggressive for the network conditions, or the backend is intermittently unresponsive to health checks while serving queries normally.Verify pool activity exists for recovery. If a backend is stuck SHUNNED longer than
mysql-shun_recovery_time_sec, check whether there is actual client traffic to that hostgroup.ConnUsed == 0andConnFree == 0instats_mysql_connection_poolfor that hostgroup means no traffic is reaching it, so recovery will not trigger.Check self-tuning for single-backend hostgroups.
mysql-shun_recovery_time_secself-tunes to 1 second when only one backend exists in a hostgroup and the configured value is greater than 1. If this does not work in your version, a single-writer hostgroup can experience repeated 10-second outages.
Metrics and signals to monitor
| Signal | Why it matters | Warning sign |
|---|---|---|
status in stats_mysql_connection_pool | The actual SHUNNED state per backend | Any backend not ONLINE; zero ONLINE in a hostgroup |
ConnERR per backend | Cumulative failed connection attempts; drives error-based shunning | Rising rate preceding a SHUNNED transition |
MySQL_Monitor_ping_check_ERR | Monitor detecting backend as unresponsive | Sustained increase or spikes correlating with SHUNNED events |
MySQL_Monitor_connect_check_ERR | Monitor cannot establish connections to backend | Any sustained failures |
MySQL_Monitor_replication_lag_check_ERR | Replication lag check failing or timing out | Correlates with lag-based shunning |
backend_lagging_during_query | Queries that hit a backend detected as lagging after routing | Non-zero values indicate stale reads may have occurred |
backend_offline_during_query | Queries that failed because backend went offline mid-execution | Non-zero values mean queries were killed by status changes |
ConnPool_get_conn_failure | Pool could not provide a backend connection | Indicates pool starvation beyond a single SHUNNED backend |
Questions rate | Overall query throughput | Sudden drop may indicate capacity loss from shunning |
Fixes
When connection errors are the trigger
If ConnERR is rising, the backend is rejecting connections from ProxySQL. Common causes:
- Backend
max_connectionsexhausted: ProxySQL competes with direct connections, replication threads, and other proxy instances for backend MySQL connections. CheckSHOW GLOBAL STATUS LIKE 'Threads_connected'on the backend against itsmax_connections. Adjust ProxySQL’s per-backendmax_connectionsinmysql_serversto leave headroom. - Monitor credentials expired: If
mysql-monitor_usernameormysql-monitor_passwordare invalid on the backend, monitor checks fail and ProxySQL shuns the backend. Update credentials, then runLOAD MYSQL VARIABLES TO RUNTIME; SAVE MYSQL VARIABLES TO DISK;. - Network partition: Check connectivity from the ProxySQL host to the backend with
mtror a directmysqlclient connection. Cloud networking can introduce intermittent packet loss or latency spikes that cross theshun_on_failuresthreshold. - MySQL
wait_timeoutclosing pooled connections: If the backend closes idle connections afterwait_timeoutand ProxySQL tries to reuse them, the failed reuse counts as aConnERR. Setmysql-connection_max_age_msin ProxySQL to a value shorter than the backend’swait_timeout(converted to milliseconds). The default of 0 means no age-based recycling.
When replication lag is the trigger
If replicas are being shunned due to lag:
- Verify
max_replication_lagis set appropriately inmysql_servers. The default of 0 disables lag checking. A value too low for your workload causes constant shunning during normal replication delay spikes. - Check
SHOW SLAVE STATUSon the affected replica. IfSeconds_Behind_Masteris genuinely high, the replica cannot keep up with the write workload. This is a backend capacity issue, not a ProxySQL issue. - Note that
Seconds_Behind_Masteris unreliable during large transactions (shows 0, then jumps). If you see replicas shunned immediately after a large batch write, the lag may have been masked during the transaction. - For Group Replication, shunning uses
max_transactions_behind. A two-stage process applies: first SHUNNED (graceful, connections preserved), thenSHUNNED_REPLICATION_LAG(connections terminated) if lag persists.
When the backend flaps between ONLINE and SHUNNED
Flapping means the monitor is too sensitive relative to actual backend stability:
- Increase
mysql-monitor_ping_interval(default 1000ms) to reduce check frequency. Aggressive intervals (e.g., 500ms) on a network with jitter will produce enough transient failures to crossshun_on_failures. - Increase
mysql-shun_on_failuresfrom the default of 5. This variable cannot be disabled by setting it to a special value. To effectively disable shunning, set it to a very large number (e.g., 10000000), but this removes the protection entirely. - Check whether the backend is under resource pressure during health checks. A backup, large analytical query, or
ANALYZE TABLEcan make the backend briefly unresponsive tomysql_ping()while still serving other queries.
When a single-backend hostgroup gets stuck
A hostgroup with only one backend is the most dangerous shunning scenario because there is nowhere to redirect traffic:
mysql-shun_recovery_time_secshould self-tune to 1 second for single-backend hostgroups. If this does not work in your version, a single writer can be shunned for the full 10 seconds repeatedly, causing cascading “Too many connections” errors.- Recovery requires pool activity. If the hostgroup has no traffic (e.g., a standby writer hostgroup), the shunned backend will not recover automatically. Consider routing a lightweight health-check query through the hostgroup periodically.
- For Galera setups using
mysql_galera_hostgroupswithmax_writers: nodes SHUNNED due tomax_writersmay not set theshunned_automaticflag. When the primary writer fails, ProxySQL only attempts recovery on nodes withshunned_automatic=true. Backup writers remain SHUNNED indefinitely and all writes are blocked.
When you need to force a backend back online
Toggle the backend status through mysql_servers to force a runtime reload that resets the monitor state:
UPDATE mysql_servers SET status='OFFLINE_SOFT'
WHERE hostgroup_id=<hg> AND hostname='<host>' AND port=<port>;
LOAD MYSQL SERVERS TO RUNTIME;
UPDATE mysql_servers SET status='ONLINE'
WHERE hostgroup_id=<hg> AND hostname='<host>' AND port=<port>;
LOAD MYSQL SERVERS TO RUNTIME;
WARNING: This is a temporary fix. If the underlying condition persists, the monitor will re-shun the backend on the next check cycle. Always identify and address the root cause.
Prevention
- Tune
mysql-shun_on_failuresbased on your network characteristics. The default of 5 failures per second is reasonable for low-latency LANs but too sensitive for cross-AZ or cross-region setups with occasional jitter. - Set
max_replication_lagdeliberately. Leaving it at 0 disables lag-based shunning entirely. Setting it too low causes unnecessary shunning. Base the value on your application’s staleness tolerance. - Track monitor check error rates. Monitor
MySQL_Monitor_connect_check_ERRandMySQL_Monitor_ping_check_ERR. Rising error rates precede SHUNNED transitions and give you early warning. - Verify recovery works under low traffic. In staging environments with sparse traffic, confirm that shunned backends actually recover. If pool activity is too low, recovery never triggers.
- Keep monitor credentials in sync. Credential rotation that updates
mysql_usersbut notmysql-monitor_passwordwill cause monitor check failures and spurious shunning. - Review replication lag check timeout. If the lag check times out before completing, ProxySQL may fail to detect actual lag or produce inconsistent shunning decisions.
How Netdata helps
Netdata’s ProxySQL collector provides per-second visibility into the signals that drive SHUNNED transitions:
- Backend status from
stats_mysql_connection_pool: See exactly when a backend transitions to SHUNNED and how long it stays there, without polling gaps that miss transient events. ConnERRrates per backend: Correlate connection error spikes with SHUNNED transitions to confirm the trigger.- Monitor check counters: Track
MySQL_Monitor_*_check_OKand_ERRrates to detect rising failure rates before they trigger shunning. backend_lagging_during_queryandbackend_offline_during_query: Quantify queries affected by status changes mid-flight, measuring user impact beyond the status flag.- ML anomaly detection: Baselines normal behavior per metric to distinguish transient SHUNNED events from sustained degradation.
Per-second granularity matters because shun and recovery events can complete within a 10-second window, making slower polling intervals miss the full cycle.
Related guides
- ProxySQL zero ONLINE backends in a hostgroup: total outage for that traffic class
- ProxySQL OFFLINE_SOFT vs OFFLINE_HARD vs SHUNNED: what each backend status means
- ProxySQL backend flapping between ONLINE and SHUNNED: monitor-induced oscillation
- ProxySQL monitor check failures: connect, ping, read-only, and replication-lag probes failing
- ProxySQL MySQL_Monitor_Workers is zero: health checks stopped and status is stale
- ProxySQL monitoring checklist: the signals every production proxy needs
- How ProxySQL actually works in production: a mental model for operators
- ProxySQL monitoring maturity model: from survival to expert
- ProxySQL backend connection pool exhausted: queries queuing for a free connection
- ProxySQL error 1040 Too many connections: the backend MySQL rejecting the pool
- ProxySQL error 9001 Max connect timeout reached while reaching hostgroup
- ProxySQL ConnPool_get_conn_failure rising: the most direct pool-starvation signal






