Modify Configuration Dynamically
This document describes how to dynamically modify the cluster configuration.
You can dynamically update the configuration of components (including TiDB, TiKV, and PD) using SQL statements, without restarting the cluster components. Currently, the method of changing TiDB instance configuration is different from that of changing configuration of other components (such as TiKV and PD).
Common Operations
This section describes the common operations of dynamically modifying configuration.
View instance configuration
To view the configuration of all instances in the cluster, use the show config statement. The result is as follows:
show config;
+------+-----------------+-----------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Type | Instance | Name | Value |
+------+-----------------+-----------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| tidb | 127.0.0.1:4001 | advertise-address | 127.0.0.1 |
| tidb | 127.0.0.1:4001 | binlog.binlog-socket | |
| tidb | 127.0.0.1:4001 | binlog.enable | false |
| tidb | 127.0.0.1:4001 | binlog.ignore-error | false |
| tidb | 127.0.0.1:4001 | binlog.strategy | range |
| tidb | 127.0.0.1:4001 | binlog.write-timeout | 15s |
| tidb | 127.0.0.1:4001 | check-mb4-value-in-utf8 | true |
...
You can filter the result by fields. For example:
show config where type='tidb'
show config where instance in (...)
show config where name like '%log%'
show config where type='tikv' and name='log.level'
Modify TiKV configuration dynamically
When using the set config statement, you can modify the configuration of a single instance or of all instances according to the instance address or the component type.
- Modify the configuration of all TiKV instances:
set config tikv `split.qps-threshold`=1000;
Modify the configuration of a single TiKV instance:
set config "127.0.0.1:20180" `split.qps-threshold`=1000;
If the modification is successful, Query OK is returned:
Query OK, 0 rows affected (0.01 sec)
If an error occurs during the batch modification, a warning is returned:
set config tikv `log-level`='warn';
Query OK, 0 rows affected, 1 warning (0.04 sec)
show warnings;
+---------+------+---------------------------------------------------------------------------------------------------------------+
| Level | Code | Message |
+---------+------+---------------------------------------------------------------------------------------------------------------+
| Warning | 1105 | bad request to http://127.0.0.1:20180/config: fail to update, error: "config log-level can not be changed" |
+---------+------+---------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
The batch modification does not guarantee atomicity. The modification might succeed on some instances, while failing on others. If you modify the configuration of the entire TiKV cluster using set tikv key=val, your modification might fail on some instances. You can use show warnings to check the result.
If some modifications fail, you need to re-execute the corresponding statement or modify each failed instance. If some TiKV instances cannot be accessed due to network issues or machine failure, modify these instances after they are recovered.
If a configuration item is successfully modified, the result is persisted in the configuration file, which will prevail in the subsequent operations. The names of some configuration items might conflict with TiDB reserved words, such as limit and key. For these configuration items, use backtick ` to enclose them. For example, `raftstore.raft-log-gc-size-limit`.
The following TiKV configuration items can be modified dynamically:
In the table above, parameters with the {db-name} or {db-name}.{cf-name} prefix are configurations related to RocksDB. The optional values of db-name are rocksdb and raftdb.
- When
db-nameisrocksdb, the optional values ofcf-namearedefaultcf,writecf,lockcf, andraftcf. - When
db-nameisraftdb, the value ofcf-namecan bedefaultcf.
For detailed parameter description, refer to TiKV Configuration File.
Modify PD configuration dynamically
Currently, PD does not support the separate configuration for each instance. All PD instances share the same configuration.
You can modify the PD configurations using the following statement:
set config pd `log.level`='info';
If the modification is successful, Query OK is returned:
Query OK, 0 rows affected (0.01 sec)
If a configuration item is successfully modified, the result is persisted in etcd instead of in the configuration file; the configuration in etcd will prevail in the subsequent operations. The names of some configuration items might conflict with TiDB reserved words. For these configuration items, use backtick ` to enclose them. For example, `schedule.leader-schedule-limit`.
The following PD configuration items can be modified dynamically:
For detailed parameter description, refer to PD Configuration File.
Modify TiDB configuration dynamically
Currently, the method of changing TiDB configuration is different from that of changing TiKV and PD configurations. You can modify TiDB configuration by using system variables.
The following example shows how to dynamically modify slow-threshold by using the tidb_slow_log_threshold variable.
The default value of slow-threshold is 300 ms. You can set it to 200 ms by using tidb_slow_log_threshold.
set tidb_slow_log_threshold = 200;
Query OK, 0 rows affected (0.00 sec)
select @@tidb_slow_log_threshold;
+---------------------------+
| @@tidb_slow_log_threshold |
+---------------------------+
| 200 |
+---------------------------+
1 row in set (0.00 sec)
The following TiDB configuration items can be modified dynamically:
Modify TiFlash configuration dynamically
Currently, you can modify the TiFlash configuration max_threads by using the system variable tidb_max_tiflash_threads, which specifies the maximum concurrency for TiFlash to execute a request.
The default value of tidb_max_tiflash_threads is -1, indicating that this system variable is invalid and depends on the setting of the TiFlash configuration file. You can set max_threads to 10 by using tidb_max_tiflash_threads:
set tidb_max_tiflash_threads = 10;
Query OK, 0 rows affected (0.00 sec)
select @@tidb_max_tiflash_threads;
+----------------------------+
| @@tidb_max_tiflash_threads |
+----------------------------+
| 10 |
+----------------------------+
1 row in set (0.00 sec)