Note:
This topic has been translated from a Chinese forum by GPT and might contain errors.
Original topic: 有没有什么视图可以查出哪些会话占用内存很高
[TiDB Usage Environment] Production Environment
[TiDB Version]
4.0.13
[Reproduction Path] What operations were performed that caused the issue
Performed a large number of insert and update operations, resulting in particularly high memory usage, but CPU usage is no longer high, and memory release is very slow.
[Encountered Issue: Problem Phenomenon and Impact]
How to find sessions with high memory usage? I checked the documentation but did not find such a view.
In TiDB, you can view which sessions are consuming high memory by querying the views in the information_schema
database. Here are some relevant views:
-
information_schema.SESSION_VARIABLES
: This view contains all the variables of the current session and their corresponding values. You can use this view to check memory-related variables for the session, such as memory_max_usage
, memory_current_usage
, etc.
-
information_schema.PROCESSLIST
: This view contains information about the currently active sessions, including the session ID, user, host, status, etc. You can use this view to check the memory usage of sessions by looking at the memory_used
field.
You can execute the following query to see which sessions are consuming high memory:
SELECT * FROM information_schema.PROCESSLIST WHERE memory_used > 1000000;
The above query will return information about sessions that are using more than 1,000,000 bytes of memory.
Please note that these views provide some information about session memory usage, but they are not real-time. If you need more detailed and accurate session memory usage information, consider using performance monitoring tools like Prometheus + Grafana to monitor the performance metrics of the TiDB cluster in real-time, including session memory usage.
I hope this information is helpful! If you have any other questions, feel free to ask.
My cousin’s reply is so standard, it looks like it was written by AI. 
SELECT ID, USER, HOST, MEM/1024/1024, INFO FROM information_schema.PROCESSLIST WHERE mem > 1000000; Version 4.0.13 does not have the memory_used field.
Moreover, this mem seems inaccurate and can return a huge value. Could it be a bug?
View slow queries or top SQL in the dashboard.
The database currently has no business operations; it executed a large number of DML and some queries in the past ten minutes, which have already been completed. It’s just that the sessions have not been released, so there’s no need to look at slow SQL and top SQL.
select INSTANCE,SESSION_ID,START_TIME,STATE from information_schema.CLUSTER_TIDB_TRX;
Check if there are any large transactions that haven’t been released yet?
The version is low. This view is not available.
4.0.13 is indeed very low…
Memory control in version 6.5 is much better, I recommend upgrading.
Alright. The upgrade can’t be done immediately.
This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.