ParatuTech
Database journalMySQL

MySQL · Bounded observability

MySQL slow query logs with clear collection limits

Plan a short, protected collection window, verify what is recorded, and avoid confusing slow-query evidence with complete request timing.

A useful slow-query sample starts with a specific question and a stop condition. For MySQL 8.4, plan how much evidence you need, where it will live, and who can read it before expanding collection.

01 Treat query text as data
Redacted example onlySELECT idFROM customersWHERE email = '[REDACTED]';Raw logs may contain literals
02 Control its path
Window • size • expiryBounded collectionSet scope and an end conditionRestricted raw logLimit access and retentionReview + redactReviewed analysis copy
Sanitized illustrative query; no real email, token or customer data is shown. Slow query logging can capture sensitive statement text. Collection scope, storage growth, access, retention and redaction should be approved before collection or sharing. Review the redacted copy; masking is not automatically comprehensive.

The short version

What to take away

  • Define the question, collection window, storage limit and stop conditions before enabling more logging.
  • Check log destinations and session thresholds; slow-query logging is not complete request tracing.
  • Treat SQL text as sensitive and restore approved settings when collection ends.

Define the collection window

Suppose a report slows during a known busy period. An illustrative plan could collect a short sample covering that period, with an owner watching disk growth and service latency. Choose thresholds and duration for the actual workload; there is no universally safe value.

Record the original settings, the approved changes, a storage budget and early-stop conditions. Include an automatic or clearly assigned end-of-window restoration step. A logging change that outlives the investigation becomes an ongoing operational and privacy decision.

Verify what reaches the log

The slow query log uses long_query_time and min_examined_row_limit to select statements. Initial lock acquisition time is excluded from the execution time used by this mechanism, and entries are written after execution and lock release. Log order may therefore differ from execution order. See the slow query log documentation.

Check both slow_query_log and log_output. Enabling the log does not guarantee query records reach a file: the destination can be TABLE, FILE or NONE. Changing log_output also affects the general query log's destination. Verify a representative sample reaches the intended restricted location using the log destination guidance.

Check effective thresholds on application sessions as well as global values. Existing pooled connections may retain their session settings; check the system-variable scope rules. Avoid casually enabling logging for every query without an index; it can generate substantial volume, including fast queries. Its dedicated throttle is not a general cap on all slow-log entries.

Protect the evidence and close the window

SQL text can contain customer values or secrets. MySQL rewrites passwords for certain recognized statements, but this is not general-purpose sanitization. The password logging documentation describes those limits and recommends restricted access.

Keep raw records in the approved location. Share only reviewed, appropriately redacted extracts with authorized recipients. Summarize recurring query shapes, timing and examined rows, then compare with application timing before assigning a cause.

At the stop point, restore the recorded settings, verify collection has ended as intended, and apply the agreed retention policy. Keep the conclusions and configuration record; retain raw SQL only as long as approved.

Discuss MySQL observability with ParatuTech.

A considered next step

Bring the workload, the symptoms and the evidence. We’ll help you frame the next decision.

Discuss your database