Note:
This topic has been translated from a Chinese forum by GPT and might contain errors.
Original topic: 变量作用域问题疑问
[TiDB Usage Environment] Production Environment / Testing / PoC
[TiDB Version]
[Reproduction Path] What operations were performed when the issue occurred
[Encountered Issue: Issue Phenomenon and Impact] Variable scope issue query
[Resource Configuration] Go to TiDB Dashboard - Cluster Info - Hosts and take a screenshot of this page
[Attachment: Screenshot/Logs/Monitoring]
How do you set this instance level???
SET SESSION xxx= ‘xxx’;
This is at the instance level.
The cluster configuration under this link shows that they are also parameter variables. If you use set global
to set them, you will find that it only affects one instance. For example, the default tidb_slow_log_threshold
is 300. If you enter a TiDB server and set it to 1s, it will only take effect on this one TiDB server and will not synchronize to other TiDB servers.
Some parameters are global but can take effect on individual instances. Are you referring to this type of parameter?
You must have misread the documentation. These are configuration file parameters, not variables. Variables are stored in TiKV.
I believe there are no instance-level variables. Instance-level settings are configured in each TiDB configuration file, but those are not variable configurations.
Yes, it is this type of parameter. It is probably not set through TiDB, but rather through commands like edit-config.
Refer to the official documentation:
It contains the introduction of variables.
Persisted to the cluster: No, it only applies to the current TiDB instance connection.
—Setting the Scope of TiDB Variables
set session autocommit='off'; -- session level
set global autocommit='off'; -- global level
set config pd log.level='info'; -- cluster level configuration, can also be configured with edit-config
set config '192.168.2.22:2379' log.level='warning'; -- instance level configuration of cluster parameters, can also be configured with edit-config
global: Effective for new session connections, not effective for the current or already established sessions
session: Effective only in the current session
instance: Effective after the instance on the node restarts
It seems that this type of parameter is instance.tidb_slow_log_threshold
– For example
mysql -h192.168.2.22 -uroot -poracle -P4000
set global tidb_slow_log_threshold=1000;
mysql> show config where type='tidb' and name like '%tidb_slow_log_threshold%';
+------+-------------------+----------------------------------+-------+
| Type | Instance | Name | Value |
+------+-------------------+----------------------------------+-------+
| tidb | 192.168.2.21:4000 | instance.tidb_slow_log_threshold | 300 |
| tidb | 192.168.2.23:4000 | instance.tidb_slow_log_threshold | 300 |
| tidb | 192.168.2.22:4000 | instance.tidb_slow_log_threshold | 1000 |
+------+-------------------+----------------------------------+-------+
Note: 300 is the default value. 1000 is the modified value.
– Cluster restart
mysql> show config where type='tidb' and name like '%tidb_slow_log_threshold%';
+------+-------------------+----------------------------------+-------+
| Type | Instance | Name | Value |
+------+-------------------+----------------------------------+-------+
| tidb | 192.168.2.22:4000 | instance.tidb_slow_log_threshold | 300 |
| tidb | 192.168.2.23:4000 | instance.tidb_slow_log_threshold | 300 |
| tidb | 192.168.2.21:4000 | instance.tidb_slow_log_threshold | 300 |
+------+-------------------+----------------------------------+-------+
Note: After tiup cluster stop tpln_qa
, the value reverts to the default value.
You need to understand the basic concepts again. I also read it several times initially.
I have also gone through it several times. I have questions about the 303 video. The teacher hasn’t explained it yet!
My document clearly explains how to modify some parameters, such as changing the number of replicas.
This is indeed worth watching several times.
This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.