Are there any views to check which sessions are consuming a lot of memory?

Note:
This topic has been translated from a Chinese forum by GPT and might contain errors.

Original topic: 有没有什么视图可以查出哪些会话占用内存很高

| username: 路在何chu

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

| username: Billmay表妹 | Original post link

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:

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

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

| username: Miracle | Original post link

My cousin’s reply is so standard, it looks like it was written by AI. :joy:

| username: 路在何chu | Original post link

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.

| username: 路在何chu | Original post link

Moreover, this mem seems inaccurate and can return a huge value. Could it be a bug?

| username: Fly-bird | Original post link

View slow queries or top SQL in the dashboard.

| username: 路在何chu | Original post link

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.

| username: dba-kit | Original post link

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?

| username: 路在何chu | Original post link

The version is low. This view is not available.

| username: dba-kit | Original post link

:rofl: 4.0.13 is indeed very low…

| username: 像风一样的男子 | Original post link

Memory control in version 6.5 is much better, I recommend upgrading.

| username: 路在何chu | Original post link

Alright. The upgrade can’t be done immediately.

| username: system | Original post link

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.