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.
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.