Query icon
IonToCsv icon
If icon
Log icon
SlackIncomingWebhook icon
Pause icon
Set icon
Schedule icon

MySQL Temporary Table Disk Spill and Buffer Sizing Advisor

Monitor MySQL Created_tmp_disk_tables ratios using performance_schema, export CSV diagnostics, and detect sort buffer bottlenecks in Kestra.

Categories
Data

MySQL processes complex intermediate operations—such as GROUP BY, ORDER BY, DISTINCT, and multi-table JOIN queries—using in-memory temporary tables bounded by tmp_table_size and max_heap_table_size. When an execution exceeds these thresholds or queries unindexed BLOB/TEXT columns, MySQL automatically converts the in-memory structure into an on-disk InnoDB table. Disk spills incur significant I/O penalties, resulting in 10x-100x query latency degradations and storage contention. This workflow continuously audits MySQL's performance_schema.global_status and global_variables, evaluates the ratio of Created_tmp_disk_tables to Created_tmp_tables, isolates the top offending query digests from events_statements_summary_by_digest, exports a downloadable CSV diagnostic report, persists telemetry history in Kestra's Key-Value store, alerts to Slack when disk spills breach safe operational limits, and provides an operator-in-the-loop approval gate to dynamically apply recommended buffer sizing adjustments without database restarts.

How it works

  1. The Schedule trigger initiates the workflow hourly, or database administrators can trigger executions on-demand via the UI.
  2. evaluate_tmp_table_metrics queries performance_schema.global_status to compute total temporary table counts, disk spills, and the spill ratio percentage, while cross-joining performance_schema.global_variables to inspect current memory limits.
  3. fetch_offending_digest_queries queries performance_schema.events_statements_summary_by_digest to isolate the SQL statements responsible for the highest volume of on-disk temporary tables (STORE fetch type).
  4. export_diagnostic_csv transforms the raw query digest telemetry into a downloadable CSV artifact using IonToCsv.
  5. check_disk_spill_threshold (If condition) verifies whether the disk spill ratio exceeds the configured threshold (default 15%) after minimum volume requirements are satisfied.
  6. If degraded, notify_slack_alert posts an alert with the spill ratio, configured buffer sizes, recommended target buffer, and the direct CSV report download link for immediate DBA inspection.
  7. When auto_apply_buffer_tuning is enabled, execute_buffer_remediation pauses execution (io.kestra.plugin.core.flow.Pause, pauseDuration: PT30M, behavior: CANCEL) for operator review before executing dynamic buffer reconfiguration (SET GLOBAL tmp_table_size and SET GLOBAL max_heap_table_size), canceling automatically on timeout to prevent unapproved changes, followed by verify_buffer_reconfiguration confirming the updated buffer limits took effect. Note that SET GLOBAL dynamically adjusts runtime limits for new sessions until MySQL restarts; DBAs running MySQL 8.0+ can use SET PERSIST or update my.cnf to persist changes across server reboots.
  8. update_telemetry_watermark updates the mysql_tmp_table_audit_<database> key in Kestra's KV store for trend analysis.
  9. The errors block intercepts connection or query failures and immediately alerts the on-call channel.

What you get

  • Proactive detection of MySQL queries causing severe storage I/O degradation through on-disk table conversion.
  • Visibility into configured tmp_table_size and max_heap_table_size parameters versus actual workload demands.
  • Automated identification of exact query digests and average latencies responsible for disk spills.
  • Automated export of offending SQL statements into downloadable CSV artifacts.
  • Operator-in-the-loop remediation gate pausing for confirmation before dynamically tuning temporary table buffers.
  • Post-remediation verification ensuring new global buffer limits are applied immediately for future client connections.
  • Persistent state tracking via Kestra KV store without third-party monitoring infrastructure.
  • Automated incident alerts and resolution receipts delivered directly to Slack with report links.

Who it's for

  • Database Administrators (DBAs) optimizing MySQL and Percona Server performance.
  • Site Reliability Engineers (SREs) investigating intermittent database CPU and disk I/O latency spikes.
  • Backend Engineers seeking proactive query optimization insights.

Why orchestrate this with Kestra

Monitoring temporary table disk spills directly through declarative Kestra workflows eliminates the need for proprietary APM agents. Kestra natively handles database retries, credential isolation via secrets, conditional branching, human-in-the-loop pauses, artifact generation, and key-value state persistence in a single audited YAML pipeline.

Prerequisites

  • MySQL 5.7, 8.0, or newer (or MariaDB 10.3+) with performance_schema = ON.
  • Database user with SELECT permissions on performance_schema.global_status, performance_schema.global_variables, and performance_schema.events_statements_summary_by_digest, and SYSTEM_VARIABLES_ADMIN (or SUPER) if executing buffer tuning remediation.
  • Incoming Slack Webhook URL for alerting notifications.

Secrets

  • MYSQL_JDBC_URL: JDBC connection string (e.g., jdbc:mysql://mysql.company.internal:3306/production).
  • MYSQL_USERNAME: Database username with read and administration permissions.
  • MYSQL_PASSWORD: Database user password.
  • SLACK_WEBHOOK_URL: Slack Incoming Webhook endpoint for alerting.

Quick start

  1. Configure the MYSQL_JDBC_URL, MYSQL_USERNAME, MYSQL_PASSWORD, and SLACK_WEBHOOK_URL secrets in your Kestra namespace.
  2. Import this blueprint into your Kestra workspace.
  3. Click Execute with default inputs to perform an initial audit.
  4. Verify the generated output logs, download the generated CSV report from the Outputs tab, and inspect the stored record in the KV Store tab.
  5. Enable the hourly schedule trigger for continuous monitoring.

How to extend

  • Add an automated ticket creation task in Jira or GitHub to assign query rewriting tasks to product engineering teams.
  • Archive weekly disk spill audit logs to Amazon S3 or Google Cloud Storage using io.kestra.plugin.aws.s3.Upload.
  • Integrate with PagerDuty or Opsgenie using Kestra's notification plugins for critical disk spill surges.

Links

See How

New to Kestra?

Use blueprints to kickstart your first workflows.