tidb查询报错

为提高效率,提问时请提供以下信息,问题描述清晰可优先响应。

  • 【TiDB 版本】:4.0.7
  • 【问题描述】:执行sql时报错:failed Error 1105: other error: Memory limit (for query) exceeded: would use 9.31 GiB (attempt to allocate chunk of 1048576 bytes), maximum: 9.31 GiB
    execute run failed, err execute query
    tidb配置里已设置如下参数:
    mem-quota-query = 10737418240

若提问为性能优化、故障排查类问题,请下载脚本运行。终端输出的打印结果,请务必全选并复制粘贴上传。

你好,

此报错含义为,该 sql 运行占用内存超出了 mem-quota-query 的阈值,对应参数 oom-action 应该设置为 cancel。

解决此问题可以从 sql 入手,将 sql 反馈条数减少,降低对 tidb-server 内存的占用,或者将 mem-quota-query 继续调大,或者将 oom-action 设置为 log,告诉 tidb-server 对超出 mem- 的 sql 不作处理,

tidb v4.0 可以对 sql 超过 mem- 的 sql 是否磁盘进行缓存,具体看下 tidb-server 的配置文件设置。
其中涉及多个参数请参照完整
https://docs.pingcap.com/zh/tidb/stable/tidb-configuration-file#tmp-storage-path

MySQL [(none)]> show config where name like ‘%oom-action%’;
±-----±-------------------±-----------±------+
| Type | Instance | Name | Value |
±-----±-------------------±-----------±------+
| tidb | 10.10.xx.xx2:4001 | oom-action | log |
| tidb | 10.10.xx.xx3:4000 | oom-action | log |
| tidb | 10.10.xx.xx3:4001 | oom-action | log |
| tidb | 10.10.xx.xx4:4000 | oom-action | log |
| tidb | 10.10.xx.xx2:4000 | oom-action | log |
| tidb | 10.10.xx.xx1:4000 | oom-action | log |
| tidb | 10.10.xx.xx1:4001 | oom-action | log |
| tidb | 10.10.xx.xx4:4001 | oom-action | log |
±-----±-------------------±-----------±------+
8 rows in set, 18 warnings (0.02 sec)

MySQL [(none)]> show warnings;
±--------±-----±-------------------------------------------------------------------------------------+
| Level | Code | Message |
±--------±-----±-------------------------------------------------------------------------------------+
| Warning | 1105 | unknown node type: tiflash(10.10.xx.xx9:3930) |
| Warning | 1105 | unknown node type: tiflash(10.10.xx.x50:3930) |
| Warning | 1105 | Get http://0.0.0.0:20180/config: dial tcp 0.0.0.0:20180: connect: connection refused |
| Warning | 1105 | Get http://0.0.0.0:20180/config: dial tcp 0.0.0.0:20180: connect: connection refused |
| Warning | 1105 | Get http://0.0.0.0:20180/config: dial tcp 0.0.0.0:20180: connect: connection refused |
| Warning | 1105 | Get http://0.0.0.0:20183/config: dial tcp 0.0.0.0:20183: connect: connection refused |
| Warning | 1105 | Get http://0.0.0.0:20183/config: dial tcp 0.0.0.0:20183: connect: connection refused |
| Warning | 1105 | Get http://0.0.0.0:20182/config: dial tcp 0.0.0.0:20182: connect: connection refused |
| Warning | 1105 | Get http://0.0.0.0:20181/config: dial tcp 0.0.0.0:20181: connect: connection refused |
| Warning | 1105 | Get http://0.0.0.0:20182/config: dial tcp 0.0.0.0:20182: connect: connection refused |
| Warning | 1105 | Get http://0.0.0.0:20181/config: dial tcp 0.0.0.0:20181: connect: connection refused |
| Warning | 1105 | Get http://0.0.0.0:20181/config: dial tcp 0.0.0.0:20181: connect: connection refused |
| Warning | 1105 | Get http://0.0.0.0:20182/config: dial tcp 0.0.0.0:20182: connect: connection refused |
| Warning | 1105 | Get http://0.0.0.0:20181/config: dial tcp 0.0.0.0:20181: connect: connection refused |
| Warning | 1105 | Get http://0.0.0.0:20183/config: dial tcp 0.0.0.0:20183: connect: connection refused |
| Warning | 1105 | Get http://0.0.0.0:20180/config: dial tcp 0.0.0.0:20180: connect: connection refused |
| Warning | 1105 | Get http://0.0.0.0:20183/config: dial tcp 0.0.0.0:20183: connect: connection refused |
| Warning | 1105 | Get http://0.0.0.0:20182/config: dial tcp 0.0.0.0:20182: connect: connection refused |
±--------±-----±-------------------------------------------------------------------------------------+
18 rows in set (0.00 sec)

oom-action已经配置为log了,另外还有个疑问,show config为什么获取不到tikv的配置参数呢?

辛苦检查下 tidb 集群的所有服务器的防火墙是否已经关闭(或者看下对应端口是否放开,)
可以反馈下当前集群的状态

防火墙均已关闭,当前集群状态如下:

  1. 有配置resource_limit 吗?
    image

  2. 在 tidb-server 主机的systemd 目录下看看对应的 service 里有配置操作系统限定的参数吗?

  3. 修改配置参数后,有 reload 过 tidb 吗? 是在 service_onfig 下配置的还是 具体某个 tidb-server 配置的?

1、没有设置resource_limit
2、tidb-service配置是默认的,如下:
[root@tidb04 system]# cat tidb-4000.service
[Unit]
Description=tidb service
After=syslog.target network.target remote-fs.target nss-lookup.target

[Service]
LimitNOFILE=1000000
LimitSTACK=10485760

User=tidb
ExecStart=/data/tidb-deploy/tidb-4000/scripts/run_tidb.sh
Restart=always

RestartSec=15s

[Install]
WantedBy=multi-user.target
3、有reload tidb

ps:主题贴中的问题解决了,通过调大tiflash的参数解决:
** tiflash:**
** profiles.default.max_memory_usage: 143881404416**

目前比较奇怪的是,show config获取不到tikv的配置

直接 show config 看下是否可以,我这边可以看到

show config只有type为tidb和pd的数据。
我直接在主机上curl http://10.10.xx.xx:20180/config是可以正常获取到数据的。是不是和在一台物理机上部署了多个tikv实例有关,在哪里需要指定一下ip?上面报错的地方都显示0.0.0.0

附上tikv的启动脚本
cat run_tikv.sh

#!/bin/bash
set -e

# WARNING: This file was auto-generated. Do not edit!
#          All your edit might be overwritten!
cd "/data/tidb-deploy/tikv-20160" || exit 1

echo -n 'sync ... '
stat=$(time sync || sync)
echo ok
echo $stat
exec numactl --cpunodebind=0 --membind=0 bin/tikv-server \
    --addr "0.0.0.0:20160" \
    --advertise-addr "10.10.xx.45:20160" \
    --status-addr "0.0.0.0:20180" \
    --pd "10.10.xx.41:2379,10.10.xx.42:2379,10.10.xx.43:2379" \
    --data-dir "/data1/tidb-data/tikv-20160" \
    --config conf/tikv.toml \
    --log-file "/data/tidb-deploy/tikv-20160/log/tikv.log" 2>> "/data/tidb-deploy/tikv-20160/log/tikv_stderr.log"

这个脚本是自动生成的,是在tiup cluster edit-config 里要显示指定status-addr吗?如何指定呢?

默认是这个,没问题, 还是看下是不是所有节点都关闭防火墙了。

防火墙都关了,端口也是正常的,看下面这个报错提示:Warning | 1105 | Get http://0.0.0.0:20180/config: dial tcp 0.0.0.0:20180: connect: connection refused
我怀疑是获取这个url的时候,没有符合预期。应该是Get http://[ip]:20180/config,而不是Get http://0.0.0.0:20180/config

请问下,有 tikv 和 tiflash 配置在一个主机吗?

tiflash和tikv处于不同物理机上。2台tiflash物理机,每台部署一个tiflash节点,4台tikv物理机,每台部署4个tikv节点。下面这个是原图:

  1. 看了下,这里确实是因为 status-addr 没有配置的原因造成的,所以使用了默认的 ListenHost(0.0.0.0) 进行访问
  2. 这里要修改实例的 status-addr 较为麻烦,需要先下线节点,修改完配置再上线的方式进行
  3. 建了一个对应的 issue 来记录这个问题 https://github.com/pingcap/tidb/issues/20528 我们会尽快修复

需要给您提供 hotfix 的 tidb 版本,来做下替换,解决这个问题吗?
@tao7

感谢跟踪。这个暂时不影响使用,后续正式版本能修复即可。

:+1:,可以继续关注这个 pr,

这个问题pr说合并到4.0.8了,但升级到4.0.8后,似乎还是没有解决?

请问,哪里写合并到 4.0.8 了? 应该还没有吧