Precautions
TiDB not allowed to modify the operating system memory allocation strategy is only allowed to be 2
0
or1
TUG modifies the memory usage strategy and TiDB automatically goes offline
What is the operating system memory allocation strategy?
Adjust the upper limit of TiDB-Server memory usage tidb3.0
1 modification inventory.ini
inventory.ini
Add MemoryLimit=25G at the end of the configuration file
- Set according to the actual memory of your machine
- When TiDB-Server process
常驻内存
exceeds this limit, the process will be killed - And throw OOM exception in TiDB-Server log
[root@test ~]# cat /etc/systemd/system/tidb-4000.service
[Unit]
Description=tidb-4000 service
After=syslog.target network.target remote-fs.target nss-lookup.target
[Service]
# 常驻内存上限
MemoryLimit=25G
LimitNOFILE=1000000
#LimitCORE=infinity
LimitSTACK=10485760
User=tidb
ExecStart=/home/tidb/deploy/scripts/run_tidb.sh
Restart=always
RestartSec=15s
[Install]
WantedBy=multi-user.target
[root@dev11 ~]#
Note: This operation is to change the /etc/systemd/system/tidb-4000.service
configuration in the file
[root@hostname ~]# cat /etc/systemd/system/tidb-4000.service | grep MemoryLimit
MemoryLimit=25G
[root@hostname ~]#
The resident memory of TiDB Server differs greatly from the actual heap memory
2 Roll update tidb (you must update the configuration after modifying the configuration file)
[root@hostname ~]# ansible-playbook rolling_update.yml --tags=tidb
Modify the number of days to save logs and set the maximum index length
To modify tidb.yml, you must configure the configuration of the corresponding version to configure
tidb3.0 modification
设置日志保留天数
max-days: 10
以字节为单位设置查询的内存配额。默认32G
mem-quota-query: 1073741824
设置最大索引长度
max-index-length: 12288
[root@hostname ~]# ansible-playbook rolling_update.yml --tags=tidb
Modification of tidb4.0
Implementation:
tiup cluster edit-config test-cluster
Add the following configuration
server_configs:
tidb:
# 以字节为单位设置查询的内存配额。4.0默认1G
mem-quota-query: 1073741824
# 设置最大索引长度
max-index-length: 12288
# 最长的 SQL 输出长度。(变更)4.0需要修改
log.query-log-max-len: 6000
# 设置日志保留天数
log.file.max-days: 10
tikv:
pd:
Reload configuration file
tiup cluster reload tidb-dev -R tidb,tikv
or
tiup cluster reload tidb-dev -N ip:port
mem-quota-query
- The maximum memory threshold that a single SQL statement can occupy, in bytes.
Default value: 1073741824
requests exceeding this value will be processed by the behavior defined by oom-action.
This value is used as the initial value of the system variable tidb_mem_quota_query.