How to View Currently Executing SQL in a Database?
In the use of databases, we often need to perform performance optimization, troubleshooting, and other tasks. Conveniently viewing the SQL currently being executed by the database can greatly simplify these tasks. In MySQL, you can obtain the currently connected threads and see the running SQL by using SHOW PROCESSLIST
or SHOW FULL PROCESSLIST
. Recently, NineData released the View Sessions feature, which can help developers and DBAs perform this operation more easily.
Using the View Sessions feature, you can discover currently running slow SQL, and you can also see some "high-frequency" running SQL to optimize and troubleshoot database performance. Specifically, it can help us solve the following problems:
Trace long-running SQL: Sometimes some queries may run for a long time, occupying database resources and thus affecting overall performance. If there is no way to detect these queries, it is impossible to take timely measures to optimize them.
Discover blocking SQL: In a multi-user database environment, blocking issues may occur due to reasons such as locking or long-running queries. If there is no way to view the running processes, it will be impossible to accurately diagnose and solve these problems.
View current database connections of users and hosts: Obtain a list of all current active connections, including connection status, runtime, and other information, which helps to monitor database activity.
KILL problematic SQL processes: When problematic queries or processes are detected, you can terminate them by ending the session button to release resources and restore normal database operation. You can batch terminate problematic processes by selecting multiple.
Diagnose performance issues: If the database becomes slow, you can use the view session feature to see if there are too many connections waiting or running to find the root cause of the performance issue.
Using NineData to View SQL Currently Being Executed in the Database
In NineData, you can easily and visually complete the above operations by entering the SQL Console and clicking View Sessions. For detailed operations, you can refer to the following animated image: