Pcornel
Databases · Performance & Capacity

Slow Query Log

Cheat sheet · https://pcornel.dk/topic.php?topic=6190

Back to the Topic

Answer

The slow query log records queries slower than a threshold (MySQL slow_query_log/long_query_time; PostgreSQL log_min_duration_statement; SQL Server via Query Store/Extended Events).

Remember

Aggregate the log (pt-query-digest, pgBadger) rather than reading raw lines; optimise by total time. Avoid too-low thresholds on busy servers.

First checks

  • pt-query-digest slow.log — first check for this topic
  • psql -c "SELECT now(), version();" — PostgreSQL reachable and version
  • mysql -e "SELECT NOW(), VERSION();" — MariaDB/MySQL reachable and version
  • sqlcmd -S <server> -Q "SELECT @@VERSION" — SQL Server reachable and version

Verify in this order

query exceeds threshold → logged → aggregated → optimised

Where it usually breaks

A threshold of 0 on a busy server floods the log.

Read-only verification commands unless stated otherwise. Confirm syntax for your platform and release. Full reference: https://pcornel.dk/topic.php?topic=6190

Confirmation

Confirm action

Continue?