Question

I would like to know if it is possible to log (or detect in another way) a query that is taking too much time to execute as soon as it reached the long_query_time. Because MySQL only logs slow queries when they finished executing.

I know I can see slow queries before they finished by checking the "Server Connections" tab of MySQL Administrator, but I would like to be automatically notified when it happens (it's easier with logs).

Was it helpful?

Solution

If you are willing to poll the database to check if a query is running for longer than x seconds, you can use show processlist, or go directly to the process list table.

select * from INFORMATION_SCHEMA.PROCESSLIST where time > TIME_IN_SECS

This will add more load to the database, so i would not recommend doing it every second. But that would mean that you wouldn't get the information "as soon as it reached the long_query_time".

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top