Error When Running SQL File

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

Original topic: 在运行SQL文件时报错

| username: TiDBer_TVKpabeM

[TiDB Usage Environment] Production Environment / Testing / PoC
[TiDB Version]
[Reproduction Path] What operations were performed to encounter the issue
Running insert statement SQL file
[Encountered Issue: Issue Phenomenon and Impact]
Error occurred
Your query has been cancelled due to exceeding the allowed memory limit for a single SQL query. Please try narrowing your query scope or increase the tidb_mem_quota_query limit and try again.
Due to exceeding the allowed memory limit, your query has been cancelled
[Resource Configuration] Go to TiDB Dashboard - Cluster Info - Hosts and take a screenshot of this page
[Attachments: Screenshots / Logs / Monitoring]

| username: tidb菜鸟一只 | Original post link

Increase the parameter a bit.

| username: 啦啦啦啦啦 | Original post link

The SQL query exceeded the memory limit. If resources are sufficient, try adjusting the tidb_mem_quota_query.

| username: Kongdom | Original post link

:thinking: Why am I not getting this prompt when a single statement exceeds memory?
But the reason is the same, the memory used by the statement exceeds the limit set by tidb_mem_quota_query.

| username: redgame | Original post link

Increase the value of the tidb_mem_quota_query parameter in the TiDB configuration file to expand the memory limit available for a single query.

| username: zhanggame1 | Original post link

The default tidb_mem_quota_query is 1g. If it’s not enough, try increasing it to 4g or 8g.

| username: TiDBer_TVKpabeM | Original post link

Why doesn’t it take effect after adding it?

| username: zhanggame1 | Original post link

Use set

SET GLOBAL tidb_server_memory_limit = “32GB”;

| username: 我是咖啡哥 | Original post link

How to Configure the Memory Usage Threshold for a SQL Execution

Use the system variable tidb_mem_quota_query to configure the memory usage threshold for a SQL execution, with the unit in bytes. For example:

Configure the memory usage threshold for the entire SQL to 8GB:

SET tidb_mem_quota_query = 8 << 30;

Configure the memory usage threshold for the entire SQL to 8MB:

SET tidb_mem_quota_query = 8 << 20;

Configure the memory usage threshold for the entire SQL to 8KB:

SET tidb_mem_quota_query = 8 << 10;
| username: Kongdom | Original post link

:joy: That 8KB is somewhat risky. I remember a classmate set it like this before, and as a result, the cluster couldn’t even start because internal SQL was also restricted~~~

| username: zhanggame1 | Original post link

So it can be more reliable with the unit.

| username: Kongdom | Original post link

No, it was a classmate who saw that it could be set so small and wanted to see what effect it would have after setting it small. Fortunately, it was tested in a personal test environment at that time.

| username: zhanggame1 | Original post link

I’ll try it later as well. At what setting did you encounter the issue?

| username: Kongdom | Original post link

It’s not me, it’s a community member. You can try setting it to 8KB. :stuck_out_tongue_winking_eye:

| username: system | Original post link

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