Schedule icon
Query icon
If icon
SlackIncomingWebhook icon
Log icon

Audit MySQL Long-Running Uncommitted Transactions

Audit MySQL InnoDB transactions to detect long-running uncommitted queries, row lock contention, and idle client sessions with Slack alerts.

Categories
DataInfrastructure

How it works

This sentinel workflow automates Day 2 operational observability for MySQL and MariaDB database clusters:

  1. Scheduled Audit Trigger: Wakes up periodically on a configurable cron schedule (0 */2 * * *, shipped disabled for safe initial onboarding) to inspect running workloads.
  2. InnoDB Catalog Probe: Uses native io.kestra.plugin.jdbc.mysql.Query to inspect information_schema.innodb_trx joined with information_schema.processlist, extracting active transactions, locked rows, client hostnames, and process IDs.
  3. Threshold Filtering: Filters for transactions that have remained open without committing for longer than max_trx_seconds_threshold (default 60 seconds).
  4. Flow Control & Slack Alerting: Evaluates query results using Kestra's native io.kestra.plugin.core.flow.If task. If stuck transactions are found, it dispatches an actionable Slack notification with the offending process ID and exact KILL <process_id>; remediation command.
  5. Failure Resilience: A top-level errors handler catches database unreachable states or authentication issues and alerts on-call engineers.

What you get

  • Immediate detection of dangling transactions holding exclusive row locks.
  • Early warning before connection pool starvation cascades into 504 Gateway Timeouts across application services.
  • Full transaction execution telemetry preserved in Kestra audit lineage.
  • Actionable Slack notifications including client IP, user, and direct KILL command runbooks.

Who it's for

  • Database Administrators (DBAs): Protecting MySQL and MariaDB clusters against lock contention and undo log bloat.
  • Backend & DevOps Engineers: Diagnosing uncommitted database transactions leaking from web worker pools.
  • Site Reliability Engineers (SREs): Enforcing database SLA guardrails and preventing cluster deadlocks.

Why orchestrate this with Kestra

  • Native Declarative SQL Tasks: Execute queries using io.kestra.plugin.jdbc.mysql.Query with built-in connection management and encrypted credential injection.
  • Zero External Infrastructure: Run scheduled database monitors without configuring custom Python cron daemons or Nagios plugins.
  • Encrypted Credential Isolation: Mask MySQL passwords and Slack webhooks with Kestra's native secrets engine ({{ secret('...') }}).
  • Audit History & Logs: Access complete visual execution history, query outputs, and error logs directly in the Kestra UI.

Prerequisites

  • An accessible MySQL (5.7+ / 8.0+) or MariaDB instance with network connectivity from the Kestra worker.
  • A database user with PROCESS and SELECT privileges on information_schema.
  • A Slack Incoming Webhook URL.

Secrets

Configure the following secrets in your Kestra namespace or instance settings:

  • MYSQL_USERNAME: Username for authenticating with the MySQL server.
  • MYSQL_PASSWORD: Password for the MySQL user.
  • SLACK_WEBHOOK_URL: The incoming webhook URL for your designated database alerts channel.

Quick start

  1. Click Use Blueprint to install this flow in your Kestra workspace.
  2. Add MYSQL_USERNAME, MYSQL_PASSWORD, and SLACK_WEBHOOK_URL to your Kestra secrets store.
  3. Adjust mysql_host, mysql_port, and max_trx_seconds_threshold to match your cluster requirements.
  4. Execute a manual test run, then enable the schedule trigger.

How to extend

  • Automated Connection Termination: Add an approval gate or conditional task to automatically execute KILL <process_id>; if transactions exceed 15 minutes.
  • Lock Wait Graph Analysis: Correlate long transactions with sys.innodb_lock_waits to map out blocking and blocked transaction dependency graphs.
  • Datadog / Prometheus Export: Emit long transaction counts to metrics collectors for historical SLA reporting.

Links

See How

New to Kestra?

Use blueprints to kickstart your first workflows.