title | summary | category | aliases | ||
---|---|---|---|---|---|
TiDB FAQ |
Learn about the most frequently asked questions (FAQs) relating to TiDB. |
faq |
|
This document lists the Most Frequently Asked Questions about TiDB.
TiDB is a distributed SQL database that features in horizontal scalability, high availability and consistent distributed transactions. It also enables you to use MySQL's SQL syntax and protocol to manage and retrieve data.
The TiDB cluster has three components: the TiDB server, the PD (Placement Driver) server, and the TiKV server. For more details, see TiDB architecture.
No. TiDB supports MySQL syntax and protocol, but it is a new open source database that is developed and maintained by PingCAP, Inc.
- TiDB works as the SQL computing layer, mainly responsible for parsing SQL, specifying query plan, and generating executor.
- TiKV works as a distributed Key-Value storage engine, used to store the real data. In short, TiKV is the storage engine of TiDB.
- PD works as the cluster manager of TiDB, which manages TiKV metadata, allocates timestamps, and makes decisions for data placement and load balancing.
Yes, it is. When all the required services are started, you can use TiDB as easily as a MySQL server. You can replace MySQL with TiDB to power your applications without changing a single line of code in most cases. You can also manage TiDB using the popular MySQL management tools.
Currently, TiDB supports the majority of MySQL 5.7 syntax, but does not support trigger, stored procedures, user-defined functions, and foreign keys. For more details, see Compatibility with MySQL.
TiDB is self-healing. All of the three components, TiDB, TiKV and PD, can tolerate failures of some of their instances. With its strong consistency guarantee, whether it’s data machine failures or even downtime of an entire data center, your data can be recovered automatically. For more information, see TiDB architecture.
TiDB implements Snapshot Isolation consistency, which it advertises as REPEATABLE-READ
for compatibility with MySQL. Data is redundantly copied between TiKV nodes using the Raft consensus algorithm to ensure recoverability should a node failure occur.
At the bottom layer, TiKV uses a model of replication log + State Machine to replicate data. For the write requests, the data is written to a Leader and the Leader then replicates the command to its Followers in the form of log. When the majority of nodes in the cluster receive this log, this log is committed and can be applied into the State Machine.
Yes. TiDB distributes transactions across your cluster, whether it is a few nodes in a single location or many nodes across multiple datacenters.
Inspired by Google's Percolator, the transaction model in TiDB is mainly a two-phase commit protocol with some practical optimizations. This model relies on a timestamp allocator to assign the monotone increasing timestamp for each transaction, so conflicts can be detected. PD works as the timestamp allocator in a TiDB cluster.
Any language supported by MySQL client or driver.
Yes. TiKV and TiDB support many popular standalone storage engines, such as GolevelDB and BoltDB. If the storage engine is a KV engine that supports transactions and it provides a client that meets the interface requirement of TiDB, then it can connect to TiDB.
The architecture of TiDB guarantees that it fully supports geo-distribution and multi-activeness. Your data and applications are always-on. All the outages are transparent to your applications and your data can recover automatically. The operation depends on the network latency and stability. It is recommended to keep the latency within 5ms. Currently, we already have similar use cases. For details, contact info@pingcap.com.
Currently, TiDB documentation is the most important and timely way to get knowledge of TiDB. In addition, we also have some technical communication groups. If you have any needs, contact info@pingcap.com.
See The System Variables.
Yes. But it differs from MySQL in syntax. As a distributed database, TiDB uses the optimistic lock. select for update
does not lock data when the transaction is started, but checks conflicts when the transaction is committed. If the check reveals conflicts, the committing transaction rolls back.
Can the codec of TiDB guarantee that the UTF-8 string is memcomparable? Is there any coding suggestion if our key needs to support UTF-8?
The character sets of TiDB use UTF-8 by default and currently only support UTF-8. The string of TiDB uses the memcomparable format.
32 characters at most.
5000 at most.
No. The JDBC driver of TiDB is MySQL JDBC (Connector/J). When using Atomikos, set the data source to type="com.mysql.jdbc.jdbc2.optional.MysqlXADataSource"
. TiDB does not support the connection with MySQL JDBC XADataSource. MySQL JDBC XADataSource only works for MySQL (for example, using DML to modify the redo
log).
After you configure the two data sources of Atomikos, set the JDBC drives to XA. When Atomikos operates TM and RM (DB), Atomikos sends the command including XA to the JDBC layer. Taking MySQL for an example, when XA is enabled in the JDBC layer, JDBC will send a series of XA logic operations to InnoDB, including using DML to change the redo
log. This is the operation of the two-phase commit. The current TiDB version does not support the upper application layer JTA/XA and does not parse XA operations sent by Atomikos.
As a standalone database, MySQL can only implement across-database transactions using XA; while TiDB supports distributed transactions using Google Percolator transaction model and its performance stability is higher than XA, so TiDB does not support XA and there is no need for TiDB to support XA.
The display content of TiDB show processlist
is almost the same as that of MySQL show processlist
. TiDB show processlist
does not display the system process ID. The ID that it displays is the current session ID. The differences between TiDB show processlist
and MySQL show processlist
are as follows:
- As TiDB is a distributed database, the
tidb-server
instance is a stateless engine for parsing and executing the SQL statements (for details, see TiDB architecture).show processlist
displays the session list executed in thetidb-server
instance that the user logs in to from the MySQL client, not the list of all the sessions running in the cluster. But MySQL is a standalone database and itsshow processlist
displays all the SQL statements executed in MySQL. - TiDB
show processlist
displays the estimated memory usage (unit: Byte) of the current session, which is not displayed in MySQLshow processlist
.
To modify the user password in TiDB, it is recommended to use set password for 'root'@'%' = '0101001';
or alter
, not update mysql.user
which might lead to the condition that the password in other nodes is not refreshed timely.
It is recommended to use the official standard statements when modifying the user password and privilege. For details, see TiDB user account management.
Why does the auto-increment ID of the later inserted data is smaller than that of the earlier inserted data in TiDB?
The auto-increment ID feature in TiDB is only guaranteed to be automatically incremental and unique but is not guaranteed to be allocated sequentially. Currently, TiDB is allocating IDs in batches. If data is inserted into multiple TiDB servers simultaneously, the allocated IDs are not sequential. When multiple threads concurrently insert data to multiple tidb-server
instances, the auto-increment ID of the later inserted data may be smaller. TiDB allows specifying AUTO_INCREMENT
for the integer field, but allows only one AUTO_INCREMENT
field in a single table. For details, see MySQL Compatibility.
The configuration method of TiDB sql_mode
is different from that of MySQL sql_mode
. TiDB does not support using the configuration file to configure sql\_mode
of the database; it only supports using the set
command to configure sql\_mode
of the database. You can use set @@global.sql_mode = 'STRICT_TRANS_TABLES';
to configure it.
-
Like MySQL, TiDB supports the SASL protocol for user login authentication and password processing.
-
When the client connects to TiDB, the challenge-response authentication mode starts. The process is as follows:
- The client connects to the server.
- The server sends a random string challenge to the client.
- The client sends the username and response to the server.
- The server verifies the response.
See TiDB Internal (I) - Data Storage.
See TiDB Internal (II) - Computing.
See TiDB Internal (III) - Scheduling.
Linux OS Platform | Version |
---|---|
Red Hat Enterprise Linux | 7.3 or later |
CentOS | 7.3 or later |
Oracle Enterprise Linux | 7.3 or later |
As an open source distributed NewSQL database with high performance, TiDB can be deployed in the Intel architecture server and major virtualization environments and runs well. TiDB supports most of the major hardware networks and Linux operating systems. For details, see Software and Hardware Requirements for deploying TiDB.
You can deploy and run TiDB on the 64-bit generic hardware server platform in the Intel x86-64 architecture. The requirements and recommendations about server hardware configuration for development, testing and production environments are as follows:
Component | CPU | Memory | Local Storage | Network | Instance Number (Minimum Requirement) |
---|---|---|---|---|---|
TiDB | 8 core+ | 16 GB+ | SAS, 200 GB+ | Gigabit network card | 1 (can be deployed on the same machine with PD) |
PD | 8 core+ | 16 GB+ | SAS, 200 GB+ | Gigabit network card | 1 (can be deployed on the same machine with TiDB) |
TiKV | 8 core+ | 32 GB+ | SAS, 200 GB+ | Gigabit network card | 3 |
Total Server Number | 4 |
Component | CPU | Memory | Hard Disk Type | Network | Instance Number (Minimum Requirement) |
---|---|---|---|---|---|
TiDB | 16 core+ | 48 GB+ | SAS | 10 Gigabit network card (2 preferred) | 2 |
PD | 8 core+ | 16 GB+ | SSD | 10 Gigabit network card (2 preferred) | 3 |
TiKV | 16 core+ | 48 GB+ | SSD | 10 Gigabit network card (2 preferred) | 3 |
Monitor | 8 core+ | 16 GB+ | SAS | Gigabit network card | 1 |
Total Server Number | 9 |
As a distributed cluster, TiDB has a high demand on time, especially for PD, because PD needs to distribute unique timestamps. If the time in the PD servers is not consistent, it takes longer waiting time when switching the PD server. The bond of two network cards guarantees the stability of data transmission, and 10 gigabit guarantees the transmission speed. Gigabit network cards are prone to meet bottlenecks, therefore it is strongly recommended to use 10 gigabit network cards.
If the resources are adequate, it is recommended to use RAID 10 for SSD. If the resources are inadequate, it is acceptable not to use RAID for SSD.
- TiDB has a high requirement on CPU and memory. If you need to open Binlog, the local disk space should be increased based on the service volume estimation and the time requirement for the GC operation. But the SSD disk is not a must.
- PD stores the cluster metadata and has frequent Read and Write requests. It demands a high I/O disk. A disk of low performance will affect the performance of the whole cluster. It is recommended to use SSD disks. In addition, a larger number of Regions has a higher requirement on CPU and memory.
- TiKV has a high requirement on CPU, memory and disk. It is required to use SSD.
For details, see Software and Hardware Recommendations.
See Ansible Deployment.
You need to set the --config
parameter in TiKV/PD to make the toml
configuration effective. TiKV/PD does not read the configuration by default. Currently, this issue only occurs when deploying using Binary. For TiKV, edit the configuration and restart the service. For PD, the configuration file is only read when PD is started for the first time, after which you can modify the configuration using pd-ctl. For details, see PD Control User Guide.
Should I deploy the TiDB monitoring framework (Prometheus + Grafana) on a standalone machine or on multiple machines? What is the recommended CPU and memory?
The monitoring machine is recommended to use standalone deployment. It is recommended to use an 8 core CPU with 16 GB+ memory and a 500 GB+ hard disk.
Check the time difference between the machine time of the monitor and the time within the cluster. If it is large, you can correct the time and the monitor will display all the metrics.
- supervise: the daemon process, to manage the processes
- svc: to start and stop the service
- svstat: to check the process status
Variable | Description |
---|---|
cluster_name | the name of a cluster, adjustable |
tidb_version | the version of TiDB, configured by default in TiDB-Ansible branches |
deployment_method | the method of deployment, binary by default, Docker optional |
process_supervision | the supervision way of processes, systemd by default, supervise optional |
timezone | the timezone of the managed node, adjustable, Asia/Shanghai by default, used with the set_timezone variable |
set_timezone | to edit the timezone of the managed node, True by default; False means closing |
enable_elk | currently not supported |
enable_firewalld | to enable the firewall, closed by default |
enable_ntpd | to monitor the NTP service of the managed node, True by default; do not close it |
machine_benchmark | to monitor the disk IOPS of the managed node, True by default; do not close it |
set_hostname | to edit the hostname of the managed node based on the IP, False by default |
enable_binlog | whether to deploy Pump and enable the binlog, False by default, dependent on the Kafka cluster; see the zookeeper_addrs variable |
zookeeper_addrs | the ZooKeeper address of the binlog Kafka cluster |
enable_slow_query_log | to record the slow query log of TiDB into a single file: ({{ deploy_dir }}/log/tidb_slow_query.log). False by default, to record it into the TiDB log |
deploy_without_tidb | the Key-Value mode, deploy only PD, TiKV and the monitoring service, not TiDB; set the IP of the tidb_servers host group to null in the inventory.ini file |
It is not recommended to deploy TiDB offline using Ansible. If the Control Machine has no access to external network, you can deploy TiDB offline using Ansible. For details, see Offline Deployment Using Ansible.
You can use Docker Compose to build a TiDB cluster locally, including the cluster monitoring components. You can also customize the version and number of instances for each component. The configuration file can also be customized. You can only use this deployment method for testing and development environment. For details, see Building the Cluster Using Docker Compose.
-
The slow query definition for TiDB is in the
conf/tidb.yml
configuration file oftidb-ansible
. Theslow-threshold: 300
parameter is used to configure the threshold value of the slow query (unit: millisecond).The slow query log is recorded in
tidb.log
by default. If you want to generate a slow query log file separately, setenable_slow_query_log
in theinventory.ini
configuration file toTrue
.Then run
ansible-playbook rolling_update.yml --tags=tidb
to perform a rolling update on thetidb-server
instance. After the update is finished, thetidb-server
instance will record the slow query log intidb_slow_query.log
. -
If a slow query occurs, you can locate the
tidb-server
instance where the slow query is and the slow query time point using Grafana and find the SQL statement information recorded in the log on the corresponding node. -
In addition to the log, you can also view the slow query using the
admin show slow
command. For details, seeadmin show slow
command.
How to add the label
configuration if label
of TiKV was not configured when I deployed the TiDB cluster for the first time?
The configuration of TiDB label
is related to the cluster deployment architecture. It is important and is the basis for PD to execute global management and scheduling. If you did not configure label
when deploying the cluster previously, you should adjust the deployment structure by manually adding the location-labels
information using the PD management tool pd-ctl
, for example, config set location-labels "zone, rack, host"
(you should configure it based on the practical label
level name).
For the usage of pd-ctl
, see PD Control Instruction.
The Direct mode wraps the Write request into the I/O command and sends this command to the disk to bypass the file system cache and directly test the real I/O Read/Write performance of the disk.
-
Random Read test:
./fio -ioengine=psync -bs=32k -fdatasync=1 -thread -rw=randread -size=10G -filename=fio_randread_test.txt -name='fio randread test' -iodepth=4 -runtime=60 -numjobs=4 -group_reporting --output-format=json --output=fio_randread_result.json
-
The mix test of sequential Write and random Read:
./fio -ioengine=psync -bs=32k -fdatasync=1 -thread -rw=randrw -percentage_random=100,0 -size=10G -filename=fio_randread_write_test.txt -name='fio mixed randread and sequential write test' -iodepth=4 -runtime=60 -numjobs=4 -group_reporting --output-format=json --output=fio_randread_write_test.json
Error UNREACHABLE! "msg": "Failed to connect to the host via ssh: "
when deploying TiDB using TiDB-Ansible
Two possible reasons and solutions:
- The SSH mutual trust is not configured as required. It’s recommended to follow the steps described in the official document and check whether it is successfully configured using
ansible -i inventory.ini all -m shell -a 'whoami' -b
. - If it involves the scenario where a single server is assigned multiple roles, for example, the mixed deployment of multiple components or multiple TiKV instances are deployed on a single server, this error might be caused by the SSH reuse mechanism. You can use the option of
ansible … -f 1
to avoid this error.
-
Apply rolling updates to the TiKV node (only update the TiKV service).
ansible-playbook rolling_update.yml --tags=tikv
-
Apply rolling updates to all services.
ansible-playbook rolling_update.yml
When you apply rolling updates to the TiDB services, the running application is not affected. You need to configure the minimum cluster topology (TiDB * 2, PD * 3, TiKV * 3). If the Pump/Drainer service is involved in the cluster, it is recommended to stop Drainer before rolling updates. When you update TiDB, Pump is also updated.
It is not recommended to deploy TiDB using Binary. The support for upgrading using Binary is not as friendly as using Ansible. It is recommended to deploy TiDB using Ansible.
Generally you should upgrade all components, because the whole version is tested together. Upgrade a single component only when an emergent issue occurs and you need to upgrade this component.
What causes "Timeout when waiting for search string 200 OK" when starting or upgrading a cluster? How to deal with it?
Possible reasons:
- The process did not start normally.
- The port is occupied.
- The process did not stop normally.
- You use
rolling_update.yml
to upgrade the cluster when the cluster is stopped (operation error).
Solution:
- Log into the node to check the status of the process or port.
- Correct the incorrect operation procedure.
Job | Playbook |
---|---|
Start the cluster | ansible-playbook start.yml |
Stop the cluster | ansible-playbook stop.yml |
Destroy the cluster | ansible-playbook unsafe_cleanup.yml (If the deployment directory is a mount point, an error will be reported, but implementation results will remain unaffected) |
Clean data (for test) | ansible-playbook unsafe_cleanup_data.yml |
Apply rolling updates | ansible-playbook rolling_update.yml |
Apply rolling updates to TiKV | ansible-playbook rolling_update.yml --tags=tikv |
Apply rolling updates to components except PD | ansible-playbook rolling_update.yml --skip-tags=pd |
Apply rolling updates to the monitoring components | ansible-playbook rolling_update_monitor.yml |
You can log into TiDB like logging into MySQL. For example:
mysql -h 127.0.0.1 -uroot -P4000
Similar to MySQL, TiDB includes static and solid parameters. You can directly modify static parameters using set global xxx = n
, but the new value of a parameter is only effective within the life cycle in this instance.
TiKV data is located in the --data-dir
, which include four directories of backup, db, raft, and snap, used to store backup, data, Raft data, and mirror data respectively.
Similar to MySQL, TiDB includes system tables as well, used to store the information required by the server when it runs.
By default, TiDB/PD/TiKV outputs standard error in the logs. If a log file is specified by --log-file
during the startup, the log is output to the specified file and executes rotation daily.
If the cluster is deployed using Ansible, you can use the ansible-playbook stop.yml
command to stop the TiDB cluster. If the cluster is not deployed using Ansible, kill
all the services directly. The components of TiDB will do graceful shutdown
.
- You can
kill
DML statements. First useshow processlist
to find the ID corresponding with the session, and then runkill tidb [session id]
. - You can
kill
DDL statements. First useadmin show ddl jobs
to find the ID of the DDL job you need to kill, and then runadmin cancel ddl jobs 'job_id' [, 'job_id'] ...
. For more details, see theADMIN
statement.
Currently, TiDB does not support session timeout in the database level. If you want to implement session timeout, use the session ID started by side records in the absence of LB (Load Balancing), and customize the session timeout on the application. After timeout, kill SQL using kill tidb [session id]
on the node that starts the query. It is currently recommended to implement session timeout using applications. When the timeout time is reached, the application layer reports an exception and continues to execute subsequent program segments.
What is the TiDB version management strategy for production environment? How to avoid frequent upgrade?
Currently, TiDB has a standard management of various versions. Each release contains a detailed change log and release notes. Whether it is necessary to upgrade in the production environment depends on the application system. It is recommended to learn the details about the functional differences between the previous and later versions before upgrading.
Take Release Version: v1.0.3-1-ga80e796
as an example of version number description:
v1.0.3
indicates the standard GA version.-1
indicates the current version has one commit.ga80e796
indicates the versiongit-hash
.
What's the difference between various TiDB master versions? How to avoid using the wrong TiDB-Ansible version?
The TiDB community is highly active. After the 1.0 GA release, the engineers have been keeping optimizing and fixing bugs. Therefore, the TiDB version is updated quite fast. If you want to keep informed of the latest version, see TiDB Weekly update.
It is recommended to deploy the TiDB cluster using the latest version of TiDB-Ansible, which will also be updated along with the TiDB version. TiDB has a unified management of the version number after the 1.0 GA release. You can view the version number using the following two methods:
select tidb_version()
tidb-server -V
Currently no.
As your business grows, your database might face the following three bottlenecks:
-
Lack of storage resources which means that the disk space is not enough.
-
Lack of computing resources such as high CPU occupancy.
-
Not enough write and read capacity.
You can scale TiDB as your business grows.
-
If the disk space is not enough, you can increase the capacity simply by adding more TiKV nodes. When the new node is started, PD will migrate the data from other nodes to the new node automatically.
-
If the computing resources are not enough, check the CPU consumption situation first before adding more TiDB nodes or TiKV nodes. When a TiDB node is added, you can configure it in the Load Balancer.
-
If the capacity is not enough, you can add both TiDB nodes and TiKV nodes.
Not really. We need some good features of gRPC, such as flow control, encryption and streaming.
The 92 indicates the escape character, which is ASCII 92 by default.
Why does the data length shown by information_schema.tables.data_length
differ from the store size on the TiKV monitoring panel?
Two reasons:
- The two results are calculated in different ways.
information_schema.tables.data_length
is an estimated value by calculating the averaged length of each row, while the store size on the TiKV monitoring panel sums up the length of the data files (the SST files of RocksDB) in a single TiKV instance. information_schema.tables.data_length
is a logical value, while the store size is a physical value. The redundant data generated by multiple versions of the transaction is not included in the logical value, while the redundant data is compressed by TiKV in the physical value.
Most of the APIs of PD are available only when the TiKV cluster is initialized. This message is displayed if PD is accessed when PD is started while TiKV is not started when a new cluster is deployed. If this message is displayed, start the TiKV cluster. When TiKV is initialized, PD is accessible.
This is because the --initial-cluster
in the PD startup parameter contains a member that doesn't belong to this cluster. To solve this problem, check the corresponding cluster of each member, remove the wrong member, and then restart PD.
PD can tolerate any synchronization error, but a larger error value means a larger gap between the timestamp allocated by the PD and the physical time, which will affect functions such as read of historical versions.
The client connection can only access the cluster through TiDB. TiDB connects PD and TiKV. PD and TiKV are transparent to the client. When TiDB connects to any PD, the PD tells TiDB who is the current leader. If this PD is not the leader, TiDB reconnects to the leader PD.
What is the difference between the leader-schedule-limit
and region-schedule-limit
scheduling parameters in PD?
- The
leader-schedule-limit
scheduling parameter is used to balance the Leader number of different TiKV servers, affecting the load of query processing. - The
region-schedule-limit
scheduling parameter is used to balance the replica number of different TiKV servers, affecting the data amount of different nodes.
Yes. Currently, you can only update the global number of replicas. When started for the first time, PD reads the configuration file (conf/pd.yml) and uses the max-replicas configuration in it. If you want to update the number later, use the pd-ctl configuration command config set max-replicas $num
and view the enabled configuration using config show all
. The updating does not affect the applications and is configured in the background.
Make sure that the total number of TiKV instances is always greater than or equal to the number of replicas you set. For example, 3 replicas need 3 TiKV instances at least. Additional storage requirements need to be estimated before increasing the number of replicas. For more information about pd-ctl, see PD Control User Guide.
How to check the health status of the whole cluster when lacking command line cluster management tools?
You can determine the general status of the cluster using the pd-ctl tool. For detailed cluster status, you need to use the monitor to determine.
The offline node usually indicates the TiKV node. You can determine whether the offline process is finished by the pd-ctl or the monitor. After the node is offline, perform the following steps:
- Manually stop the relevant services on the offline node.
- Delete the
node_exporter
data of the corresponding node from the Prometheus configuration file. - Delete the data of the corresponding node from Ansible
inventory.ini
.
If your TiDB cluster is deployed using TiDB-Ansible, the PD external service port is not bound to 127.0.0.1
, so PD Control does not recognize 127.0.0.1
and you can only connect to it using the local IP address.
The lease parameter (--lease=60
) is set from the command line when starting a TiDB server. The value of the lease parameter impacts the Database Schema Changes (DDL) speed of the current session. In the testing environments, you can set the value to 1s for to speed up the testing cycle. But in the production environments, it is recommended to set the value to minutes (for example, 60) to ensure the DDL safety.
The processing time is different for different scenarios. Generally, you can consider the following three scenarios:
- The
Add Index
operation with a relatively small number of rows in the corresponding data table: about 3s - The
Add Index
operation with a relatively large number of rows in the corresponding data table: the processing time depends on the specific number of rows and the QPS at that time (theAdd Index
operation has a lower priority than ordinary SQL operations) - Other DDL operations: about 1s
If the TiDB server instance that receives the DDL request is the same TiDB server instance that the DDL owner is in, the first and third scenarios above may cost only dozens to hundreds of milliseconds.
Possible reasons:
- If you run multiple DDL statements together, the last few DDL statements might run slowly. This is because the DDL statements are executed serially in the TiDB cluster.
- After you start the cluster successfully, the first DDL operation may take a longer time to run, usually around 30s. This is because the TiDB cluster is electing the leader that processes DDL statements.
- The processing time of DDL statements in the first ten minutes after starting TiDB would be much longer than the normal case if you meet the following conditions: 1) TiDB cannot communicate with PD as usual when you are stopping TiDB (including the case of power failure); 2) TiDB fails to clean up the registration data from PD in time because TiDB is stopped by the
kill -9
command. If you run DDL statements during this period, for the state change of each DDL, you need to wait for 2 * lease (lease = 45s). - If a communication issue occurs between a TiDB server and a PD server in the cluster, the TiDB server cannot get or update the version information from the PD server in time. In this case, you need to wait for 2 * lease for the state processing of each DDL.
No. Currently, TiDB only supports the distributed storage engine and the Goleveldb/RocksDB/BoltDB engine.
As part of MySQL compatibility, TiDB supports a number of INFORMATION_SCHEMA
tables. Many of these tables also have a corresponding SHOW command. For more information, see Information Schema.
In the communication process between the TiDB server and the TiKV server, the Server is busy
or backoff.maxsleep 20000ms
log message is displayed when processing a large volume of data. This is because the system is busy while the TiKV server processes data. At this time, usually you can view that the TiKV host resources usage rate is high. If this occurs, you can increase the server capacity according to the resources usage.
The current TiDB version has no limit for the maximum number of concurrent connections. If too large concurrency leads to an increase of response time, you can increase the capacity by adding TiDB nodes.
The create_time
of tables in the information_schema
is the creation time.
When TiDB is executing a SQL statement, the query will be EXPENSIVE_QUERY
if each operator is estimated to process over 10000 pieces of data. You can modify the tidb-server
configuration parameter to adjust the threshold and then restart the tidb-server
.
TiDB supports changing the priority on a per-session, global or individual statement basis. Priority has the following meaning:
-
HIGH_PRIORITY
: this statement has a high priority, that is, TiDB gives priority to this statement and executes it first. -
LOW_PRIORITY
: this statement has a low priority, that is, TiDB reduces the priority of this statement during the execution period.
You can combine the above two parameters with the DML of TiDB to use them. For example:
-
Adjust the priority by writing SQL statements in the database:
select HIGH_PRIORITY | LOW_PRIORITY count(*) from table_name; insert HIGH_PRIORITY | LOW_PRIORITY into table_name insert_values; delete HIGH_PRIORITY | LOW_PRIORITY from table_name; update HIGH_PRIORITY | LOW_PRIORITY table_reference set assignment_list where where_condition; replace HIGH_PRIORITY | LOW_PRIORITY into table_name;
-
The full table scan statement automatically adjusts itself to a low priority.
analyze
has a low priority by default.
Trigger strategy: auto analyze
is automatically triggered when the number of pieces of data in a new table reaches 1000 and this table has no write operation within one minute.
When the modified number or the current total row number is larger than tidb_auto_analyze_ratio
, the analyze
statement is automatically triggered. The default value of tidb_auto_analyze_ratio
is 0.5, indicating that this feature is enabled by default. To ensure safety, its minimum value is 0.3 when the feature is enabled, and it must be smaller than pseudo-estimate-ratio
whose default value is 0.8, otherwise pseudo statistics will be used for a period of time. It is recommended to set tidb_auto_analyze_ratio
to 0.5.
Its usage is similar to MySQL:
SELECT column_name FROM table_name USE INDEX(index_name)WHERE where_condition;
What is the recommended number of replicas in the TiKV cluster? Is it better to keep the minimum number for high availability?
Use 3 replicas for test. If you increase the number of replicas, the performance declines but it is more secure. Whether to configure more replicas depends on the specific business needs.
This is because the cluster ID stored in local TiKV is different from the cluster ID specified by PD. When a new PD cluster is deployed, PD generates random cluster IDs. TiKV gets the cluster ID from PD and stores the cluster ID locally when it is initialized. The next time when TiKV is started, it checks the local cluster ID with the cluster ID in PD. If the cluster IDs don't match, the cluster ID mismatch
message is displayed and TiKV exits.
If you previously deploy a PD cluster, but then you remove the PD data and deploy a new PD cluster, this error occurs because TiKV uses the old data to connect to the new PD cluster.
This is because the address in the startup parameter has been registered in the PD cluster by other TiKVs. This error occurs when there is no data folder under the directory that TiKV --store
specifies, but you use the previous parameter to restart the TiKV.
To solve this problem, use the store delete
function to delete the previous store and then restart TiKV.
Currently, some files of TiKV master have a higher compression rate, which depends on the underlying data distribution and RocksDB implementation. It is normal that the data size fluctuates occasionally. The underlying storage engine adjusts data as needed.
TiKV implements the Column Family (CF) feature of RocksDB. By default, the KV data is eventually stored in the 3 CFs (default, write and lock) within RocksDB.
- The default CF stores real data and the corresponding parameter is in
[rocksdb.defaultcf]
. The write CF stores the data version information (MVCC) and index-related data, and the corresponding parameter is in[rocksdb.writecf]
. The lock CF stores the lock information and the system uses the default parameter. - The Raft RocksDB instance stores Raft logs. The default CF mainly stores Raft logs and the corresponding parameter is in
[raftdb.defaultcf]
. - Each CF has an individual block-cache to cache data blocks and improve RocksDB read speed. The size of block-cache is controlled by the
block-cache-size
parameter. A larger value of the parameter means more hot data can be cached and is more favorable to read operation. At the same time, it consumes more system memory. - Each CF has an individual write-buffer and the size is controlled by the
write-buffer-size
parameter.
- The Raftstore thread is too slow or blocked by I/O. You can view the CPU usage status of Raftstore.
- TiKV is too busy (CPU, disk I/O, etc.) and cannot manage to handle it.
- Leaders can not reach out to followers. E.g., network problem or node failure.
- Leader balance from PD. E.g., PD wants to transfer leaders from a hotspot node to others.
TiDB uses Raft to replicate data among multiple replicas and guarantees the strong consistency of data. If one replica goes wrong, the other replicas can guarantee data security. The default number of replicas in each Region is 3. Based on the Raft protocol, a leader is elected in each Region, and if a single leader fails, a follower is soon elected as Region leader after a maximum of 2 * lease time (lease time is 10 seconds).
What are the TiKV scenarios that take up high I/O, memory, CPU, and exceed the parameter configuration?
Writing or reading a large volume of data in TiKV takes up high I/O, memory and CPU. Executing very complex queries costs a lot of memory and CPU resources, such as the scenario that generates large intermediate result sets.
No. For OLTP scenarios, TiDB requires high I/O disks for data access and operation. As a distributed database with strong consistency, TiDB has some write amplification such as replica replication and bottom layer storage compaction. Therefore, it is recommended to use NVMe SSD as the storage disks in TiDB best practices. Mixed deployment of TiKV and PD is not supported.
No. It differs from the table splitting rules of MySQL. In TiKV, the table Range is dynamically split based on the size of Region.
Region is not divided in advance, but it follows a Region split mechanism. When the Region size exceeds the value of the region_split_size
or region-split-keys
parameters, split is triggered. After the split, the information is reported to PD.
Does TiKV have the innodb_flush_log_trx_commit
parameter like MySQL, to guarantee the security of data?
Yes. Currently, the standalone storage engine uses two RocksDB instances. One instance is used to store the raft-log. When the sync-log
parameter in TiKV is set to true, each commit is mandatorily flushed to the raft-log. If a crash occurs, you can restore the KV data using the raft-log.
What is the recommended server configuration for WAL storage, such as SSD, RAID level, cache strategy of RAID card, NUMA configuration, file system, I/O scheduling strategy of the operating system?
WAL belongs to ordered writing, and currently, we do not apply a unique configuration to it. Recommended configuration is as follows:
- SSD
- RAID 10 preferred
- Cache strategy of RAID card and I/O scheduling strategy of the operating system: currently no specific best practices; you can use the default configuration in Linux 7 or later
- NUMA: no specific suggestion; for memory allocation strategy, you can use
interleave = all
- File system: ext4
Generally, enabling sync-log
reduces about 30% of the performance. For write performance when sync-log
is set to false
, see Performance test result for TiDB using Sysbench.
Can Raft + multiple replicas in the TiKV architecture achieve absolute data security? Is it necessary to apply the most strict mode (sync-log = true
) to a standalone storage?
Data is redundantly copied between TiKV nodes using the Raft consensus algorithm to ensure recoverability should a node failure occur. Only when the data has been written into more than 50% of the nodes, will the application return ACK (two out of three nodes). However, theoretically, two nodes might crash. Therefore, for scenarios with a strict requirement on data security, for example, the financial industry, you need to enable the sync-log
mode.
As an alternative to using sync-log
, you may also consider having five nodes instead of three in your Raft group. This would allow for the failure of two nodes, while still providing data safety.
Since TiKV uses the Raft protocol, multiple network roundtrips occur during data writing. What is the actual write delay?
Theoretically, TiDB has a write delay of 4 more network roundtrips than standalone databases.
Does TiDB have a InnoDB memcached plugin like MySQL which can directly use the KV interface and does not need the independent cache?
TiKV supports calling the interface separately. Theoretically, you can take an instance as the cache. Because TiDB is a distributed relational database, we do not support TiKV separately.
- Reduce the data transmission between TiDB and TiKV
- Make full use of the distributed computing resources of TiKV to execute computing pushdown
This is because the disk space is not enough. You need to add nodes or enlarge the disk space.
The memory usage of TiKV mainly comes from the block-cache of RocksDB, which is 40% of the system memory size by default. When the OOM error occurs frequently in TiKV, you should check whether the value of block-cache-size
is set too high. In addition, when multiple TiKV instances are deployed on a single machine, you need to explicitly configure the parameter to prevent multiple instances from using too much system memory that results in the OOM error.
At the beginning, many users tend to do a benchmark test or a comparison test between TiDB and MySQL. We have also done a similar official test and find the test result is consistent at large, although the test data has some bias. Because the architecture of TiDB differs greatly from MySQL, it is hard to find a benchmark point. The suggestions are as follows:
- Do not spend too much time on the benchmark test. Pay more attention to the difference of scenarios using TiDB.
- See the official test. For the Sysbench test and comparison test between TiDB and MySQL, see Performance test result for TiDB using Sysbench.
What's the relationship between the TiDB cluster capacity (QPS) and the number of nodes? How does TiDB compare to MySQL?
- Within 10 nodes, the relationship between TiDB write capacity (Insert TPS) and the number of nodes is roughly 40% linear increase. Because MySQL uses single-node write, its write capacity cannot be scaled.
- In MySQL, the read capacity can be increased by adding slave, but the write capacity cannot be increased except using sharding, which has many problems.
- In TiDB, both the read and write capacity can be easily increased by adding more nodes.
The performance test of MySQL and TiDB by our DBA shows that the performance of a standalone TiDB is not as good as MySQL.
TiDB is designed for scenarios where sharding is used because the capacity of a MySQL standalone is limited, and where strong consistency and complete distributed transactions are required. One of the advantages of TiDB is pushing down computing to the storage nodes to execute concurrent computing.
TiDB is not suitable for tables of small size (such as below ten million level), because its strength in concurrency cannot be shown with a small size of data and limited Regions. A typical example is the counter table, in which records of a few lines are updated high frequently. In TiDB, these lines become several Key-Value pairs in the storage engine, and then settle into a Region located on a single node. The overhead of background replication to guarantee strong consistency and operations from TiDB to TiKV leads to a poorer performance than a MySQL standalone.
Currently, the preferred method for backup is using the PingCAP fork of mydumper. Although the official MySQL tool mysqldump
is also supported in TiDB to back up and restore data, its performance is poorer than mydumper
/loader
and it needs much more time to back up and restore large volumes of data.
Keep the size of the data file exported from mydumper
as small as possible. It is recommended to keep the size within 64M. You can set value of the -F
parameter to 64.
You can edit the t
parameter of loader
based on the number of TiKV instances and load status. For example, in scenarios of three TiKV instances, you can set its value to 3 * (1 ~ n)
. When the TiKV load is very high and backoffer.maxSleep 15000ms is exceeded
displays a lot in loader
and TiDB logs, you can adjust the parameter to a smaller value. When the TiKV load is not very high, you can adjust the parameter to a larger value accordingly.
See Loader Instructions.
Because TiDB supports most MySQL syntax, generally you can migrate your applications to TiDB without changing a single line of code in most cases.
If I accidentally import the MySQL user table into TiDB, or forget the password and cannot log in, how to deal with it?
Restart the TiDB service, add the -skip-grant-table=true
parameter in the configuration file. Log into the cluster without password and recreate the user, or recreate the mysql.user
table using the following statement:
DROP TABLE IF EXIST mysql.user;
CREATE TABLE if not exists mysql.user (
Host CHAR(64),
User CHAR(16),
Password CHAR(41),
Select_priv ENUM('N','Y') NOT NULL DEFAULT 'N',
Insert_priv ENUM('N','Y') NOT NULL DEFAULT 'N',
Update_priv ENUM('N','Y') NOT NULL DEFAULT 'N',
Delete_priv ENUM('N','Y') NOT NULL DEFAULT 'N',
Create_priv ENUM('N','Y') NOT NULL DEFAULT 'N',
Drop_priv ENUM('N','Y') NOT NULL DEFAULT 'N',
Process_priv ENUM('N','Y') NOT NULL DEFAULT 'N',
Grant_priv ENUM('N','Y') NOT NULL DEFAULT 'N',
References_priv ENUM('N','Y') NOT NULL DEFAULT 'N',
Alter_priv ENUM('N','Y') NOT NULL DEFAULT 'N',
Show_db_priv ENUM('N','Y') NOT NULL DEFAULT 'N',
Super_priv ENUM('N','Y') NOT NULL DEFAULT 'N',
Create_tmp_table_priv ENUM('N','Y') NOT NULL DEFAULT 'N',
Lock_tables_priv ENUM('N','Y') NOT NULL DEFAULT 'N',
Execute_priv ENUM('N','Y') NOT NULL DEFAULT 'N',
Create_view_priv ENUM('N','Y') NOT NULL DEFAULT 'N',
Show_view_priv ENUM('N','Y') NOT NULL DEFAULT 'N',
Create_routine_priv ENUM('N','Y') NOT NULL DEFAULT 'N',
Alter_routine_priv ENUM('N','Y') NOT NULL DEFAULT 'N',
Index_priv ENUM('N','Y') NOT NULL DEFAULT 'N',
Create_user_priv ENUM('N','Y') NOT NULL DEFAULT 'N',
Event_priv ENUM('N','Y') NOT NULL DEFAULT 'N',
Trigger_priv ENUM('N','Y') NOT NULL DEFAULT 'N',
PRIMARY KEY (Host, User));
INSERT INTO mysql.user VALUES ("%", "root", "", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y");
TiDB can provide services while Loader is running because Loader inserts the data logically. But do not perform the related DDL operations.
Currently, TiDB does not support select into outfile
. You can use the following methods to export the data in TiDB:
- See MySQL uses mysqldump to export part of the table data in Chinese and export data using mysqldump and the WHERE condition.
- Use the MySQL client to export the results of
select
to a file.
To migrate all the data or migrate incrementally from DB2 or Oracle to TiDB, see the following solution:
- Use the official migration tool of Oracle, such as OGG, Gateway, CDC (Change Data Capture).
- Develop a program for importing and exporting data.
- Export Spool as text file, and import data using Load infile.
- Use a third-party data migration tool.
Currently, it is recommended to use OGG.
Error: java.sql.BatchUpdateExecption:statement count 5001 exceeds the transaction limitation
while using Sqoop to write data into TiDB in batches
In Sqoop, --batch
means committing 100 statement
s in each batch, but by default each statement
contains 100 SQL statements. So, 100 * 100 = 10000 SQL statements, which exceeds 5000, the maximum number of statements allowed in a single TiDB transaction.
Two solutions:
-
Add the
-Dsqoop.export.records.per.statement=10
option as follows:sqoop export \ -Dsqoop.export.records.per.statement=10 \ --connect jdbc:mysql://mysql.example.com/sqoop \ --username sqoop ${user} \ --password ${passwd} \ --table ${tab_name} \ --export-dir ${dir} \ --batch
-
You can also increase the limited number of statements in a single TiDB transaction, but this will consume more memory.
Yes, it does. And it supports DDL as well. For details, see how TiDB reads data from history versions.
See Syncer User Guide.
Download and import Syncer Json to Grafana. Edit the Prometheus configuration file and add the following content:
- job_name: 'syncer_ops' // task name
static_configs:
- targets: [’10.10.1.1:10096’] // Syncer monitoring address and port, informing Prometheus to pull the data of Syncer
Restart Prometheus.
Is there a current solution to replicating data from TiDB to other databases like HBase and Elasticsearch?
No. Currently, the data replication depends on the application itself.
Yes. For details, see Syncer User Guide
Frequent DDL operations may affect the replication speed. For Sycner, DDL operations are executed serially. When DDL operations are executed during data replication, data will be replicated serially and thus the replication speed will be slowed down.
If the machine that Syncer is in is broken and the directory of the syncer.meta
file is lost, what should I do?
When you replicate data using Syncer GTID, the syncer.meta
file is constantly updated during the replication process. The current version of Syncer does not contain the design for high availability. The syncer.meta
configuration file of Syncer is directly stored on the hard disks, which is similar to other tools in the MySQL ecosystem, such as mydumper.
Two solutions:
- Put the
syncer.meta
file in a relatively secure disk. For example, use disks with RAID 1. - Restore the location information of history replication according to the monitoring data that Syncer reports to Prometheus regularly. But the location information might be inaccurate due to the delay when a large amount of data is replicated.
If the downstream TiDB data is not consistent with the MySQL data during the replication process of Syncer, will DML operations cause exits?
- If the data exists in the upstream MySQL but does not exist in the downstream TiDB, when the upstream MySQL performs the
UPDATE
orDELETE
operation on this row of data, Syncer will not report an error and the replication process will not exit, and this row of data does not exist in the downstream. - If a conflict exists in the primary key indexes or the unique indexes in the downstream, preforming the
UPDATE
operation will cause an exit and performing theINSERT
operation will not cause an exit.
It is recommended to build a multi-source MySQL -> TiDB real-time replication environment using Syncer tool. You can migrate the read and write traffic in batches by editing the network configuration as needed. Deploy a stable network LB (HAproxy, LVS, F5, DNS, etc.) on the upper layer, in order to implement seamless migration by directly editing the network configuration.
The total read capacity has no limit. You can increase the read capacity by adding more TiDB servers. Generally the write capacity has no limit as well. You can increase the write capacity by adding more TiKV nodes.
As distributed transactions need to conduct two-phase commit and the bottom layer performs Raft replication, if a transaction is very large, the commit process would be quite slow and the following Raft replication flow is thus struck. To avoid this problem, we limit the transaction size:
- A transaction is limited to 5000 SQL statements (by default)
- Each Key-Value entry is no more than 6MB
- The total number of Key-Value entry is no more than 300,000 rows
- The total size of Key-Value entry is no more than 100MB
There are similar limits on Google Cloud Spanner.
-
When you import data, insert in batches and keep the number of rows within 10,000 for each batch.
-
As for
insert
andselect
, you can open the hidden parameterset @@session.tidb_batch_insert=1;
, andinsert
will execute large transactions in batches. In this way, you can avoid the timeout caused by large transactions, but this may lead to the loss of atomicity. Therefore, it is not recommended to use this parameter in the production environment. An error in the process of execution leads to partly inserted transaction. Therefore, use this parameter only when necessary, and use it in session to avoid affecting other statements. When the transaction is finished, useset @@session.tidb_batch_insert=0
to close it. -
As for
delete
andupdate
, you can uselimit
plus circulation to operate.
None of the DELETE
, TRUNCATE
and DROP
operations release data immediately. For the TRUNCATE
and DROP
operations, after the TiDB GC (Garbage Collection) time (10 minutes by default), the data is deleted and the space is released. For the DELETE
operation, the data is deleted but the space is not released according to TiDB GC. When subsequent data is written into RocksDB and executes COMPACT
, the space is reused.
No. None of the DDL operations can be executed on the target table when you load data, otherwise the data fails to be loaded.
Yes. But the load data
does not support the replace into
syntax.
Deleting a large amount of data leaves a lot of useless keys, affecting the query efficiency. Currently the Region Merge feature is in development, which is expected to solve this problem. For details, see the deleting data section in TiDB Best Practices.
When deleting a large amount of data, it is recommended to use Delete * from t where xx limit 5000;
. It deletes through the loop and uses Affected Rows == 0
as a condition to end the loop, so as not to exceed the limit of transaction size. With the prerequisite of meeting business filtering logic, it is recommended to add a strong filter index column or directly use the primary key to select the range, such as id >= 5000*n+m and id < 5000*(n+1)+m
.
If the amount of data that needs to be deleted at a time is very large, this loop method will get slower and slower because each deletion traverses backward. After deleting the previous data, lots of deleted flags remain for a short period (then all will be processed by Garbage Collection) and influence the following Delete statement. If possible, it is recommended to refine the Where condition. See details in TiDB Best Practices.
- The Lightning tool is developed for distributed data import. It should be noted that the data import process does not perform a complete transaction process for performance reasons. Therefore, the ACID constraint of the data being imported during the import process cannot be guaranteed. The ACID constraint of the imported data can only be guaranteed after the entire import process ends. Therefore, the applicable scenarios mainly include importing new data (such as a new table or a new index) or the full backup and restoring (truncate the original table and then import data).
- Data loading in TiDB is related to the status of disks and the whole cluster. When loading data, pay attention to metrics like the disk usage rate of the host, TiClient Error, Backoff, Thread CPU and so on. You can analyze the bottlenecks using these metrics.
You can configure concurrent GC to increase the speed of reclaiming storage space. The default concurrency is 1, and you can modify it to at most 50% of the number of TiKV instances using the following command:
update mysql.tidb set VARIABLE_VALUE="3" where VARIABLE_NAME="tikv_gc_concurrency";
See Understand the Query Execution Plan.
See Introduction to Statistics.
The count(1)
statement counts the total number of rows in a table. Improving the degree of concurrency can significantly improve the speed. To modify the concurrency, refer to the document. But it also depends on the CPU and I/O resources. TiDB accesses TiKV in every query. When the amount of data is small, all MySQL is in memory, and TiDB needs to conduct a network access.
Recommendations:
- Improve the hardware configuration. See Software and Hardware Requirements.
- Improve the concurrency. The default value is 10. You can improve it to 50 and have a try. But usually the improvement is 2-4 times of the default value.
- Test the
count
in the case of large amount of data. - Optimize the TiKV configuration. See Performance Tuning for TiKV.
You can use admin show ddl
to view the progress of the current DDL job. The operation is as follows:
tidb> admin show ddl\G;
*************************** 1. row ***************************
SCHEMA_VER: 140
OWNER: 1a1c4174-0fcd-4ba0-add9-12d08c4077dc
RUNNING_JOBS: ID:121, Type:add index, State:running, SchemaState:write reorganization, SchemaID:1, TableID:118, RowCount:77312, ArgLen:0, start time: 2018-12-05 16:26:10.652 +0800 CST, Err:<nil>, ErrCount:0, SnapshotVersion:404749908941733890
SELF_ID: 1a1c4174-0fcd-4ba0-add9-12d08c4077dc
From the above results, you can get that the add index
operation is being processed currently. You can also get from the RowCount
field of the RUNNING_JOBS
column that now the add index
operation has added 77312 rows of indexes.
admin show ddl
: to view the running DDL jobadmin show ddl jobs
: to view all the results in the current DDL job queue (including tasks that are running and waiting to run) and the last ten results in the completed DDL job queueadmin show ddl job queries 'job_id' [, 'job_id'] ...
: to view the original SQL statement of the DDL task corresponding to thejob_id
; thejob_id
only searches the running DDL job and the last ten results in the DDL history job queue
Yes. TiDB uses the cost-based optimizer. The cost model and statistics are constantly optimized. TiDB also supports correlation algorithms like hash join and soft merge.
View the Healthy
field using show stats_healthy
and generally you need to execute analyze
on a table when the field value is smaller than 60.
What is the ID rule when a query plan is presented as a tree? What is the execution order for this tree?
No rule exists for these IDs but the IDs are unique. When IDs are generated, a counter works and adds one when one plan is generated. The execution order has nothing to do with the ID. The whole query plan is a tree and the execution process starts from the root node and the data is returned to the upper level continuously. For details about the query plan, see Understanding the TiDB Query Execution Plan.
Currently the computing tasks of TiDB belong to two different types of tasks: cop task
and root task
.
cop task
is the computing task which is pushed down to the KV end for distributed execution; root task
is the computing task for single point execution on the TiDB end.
Generally the input data of root task
comes from cop task
; when root task
processes data, cop task
of TiKV can processes data at the same time and waits for the pull of root task
of TiDB. Therefore, cop
tasks can be considered as executed concurrently; but their data has an upstream and downstream relationship. During the execution process, they are executed concurrently during some time. For example, the first cop task
is processing the data in [100, 200] and the second cop task
is processing the data in [1, 100]. For details, see Understanding the TiDB Query Plan.
In TiDB, data is divided into Regions for management. Generally, the TiDB hotspot means the Read/Write hotspot in a Region. In TiDB, for the table whose primary key (PK) is not an integer or which has no PK, you can properly break Regions by configuring SHARD_ROW_ID_BITS
to scatter the Region hotspots. For details, see the introduction of SHARD_ROW_ID_BITS
in TiDB Specific System Variables and Syntax.
See Overview of the Monitoring Framework.
See Key Metrics.
The monitoring system of TiDB consists of Prometheus and Grafana. From the dashboard in Grafana, you can monitor various running metrics of TiDB which include the monitoring metrics of system resources, of client connection and SQL operation, of internal communication and Region scheduling. With these metrics, the database administrator can better understand the system running status, running bottlenecks and so on. In the practice of monitoring these metrics, we list the key metrics of each TiDB component. Generally you only need to pay attention to these common metrics. For details, see Key Metrics.
The Prometheus monitoring data is deleted every 15 days by default. Could I set it to two months or delete the monitoring data manually?
Yes. Find the startup script on the machine where Prometheus is started, edit the startup parameter and restart Prometheus.
--storage.tsdb.retention="60d"
In TiDB 2.0, Region health is monitored in the PD metric monitoring page, in which the Region Health
monitoring item shows the statistics of all the Region replica status. miss
means shortage of replicas and extra
means the extra replica exists. In addition, Region Health
also shows the isolation level by label
. level-1
means the Region replicas are isolated physically in the first label
level. All the Regions are in level-0
when location label
is not configured.
It means full table scan but the table might be a small system table.
The QPS
statistics is about all the SQL statements, including use database
, load data
, begin
, commit
, set
, show
, insert
and select
.
The Statement OPS
statistics is only about applications related SQL statements, including select
, update
and insert
, therefore the Statement OPS
statistics matches the applications better.
Check whether tidb_disable_txn_auto_retry
is set to on
. If so, set it to off
; if it is already off
, increase the value of tidb_retry_limit
until the error no longer occurs.
A PD request timeout. Check the status, monitoring data and log of the PD server, and the network between the TiDB server and the PD server.
A TiKV request timeout. Check the status, monitoring data and log of the TiKV server, and the network between the TiDB server and the TiKV server.
The TiKV server is busy. This usually occurs when the database load is very high. Check the status, monitoring data and log of the TiKV server.
A lock resolving timeout. This usually occurs when a large number of transaction conflicts exist. Check the application code to see whether lock contention exists in the database.
The accessed Region is not available. A Raft Group is not available, with possible reasons like an inadequate number of replicas. This usually occurs when the TiKV server is busy or the TiKV node is shut down. Check the status, monitoring data and log of the TiKV server.
The interval of GC Life Time
is too short. The data that should have been read by long transactions might be deleted. You can add GC Life Time
using the following command:
update mysql.tidb set variable_value='30m' where variable_name='tikv_gc_life_time';
Note:
"30m" means only cleaning up the data generated 30 minutes ago, which might consume some extra storage space.
Check whether tidb_disable_txn_auto_retry
is set to on
. If so, set it to off
; if it is already off
, increase the value of tidb_retry_limit
until the error no longer occurs.
- Check whether panic is in the log.
- Check whether OOM exists in dmesg using
dmesg -T | grep -i oom
. - A long time of no access might also lead to this error. It is usually caused by TCP timeout. If TCP is not used for a long time, the operating system kills it.
This error usually occurs when the version of TiDB does not match with the version of TiKV. To avoid version mismatch, upgrade all components when you upgrade the version.
When you execute the LOAD DATA LOCAL
statement but the MySQL client does not allow executing this statement (the value of the local_infile
option is 0), this error occurs.
The solution is to use the --local-infile=1
option when you start the MySQL client. For example, use command like mysql --local-infile=1 -u root -h 127.0.0.1 -P 4000
. The default value of local-infile
is different in different versions of MySQL client, therefore you need to configure it in some MySQL clients and do not need to configure it in some others.
This error occurs when TiDB fails to access PD. A worker in the TiDB background continuously queries the safepoint from PD and this error occurs if it fails to query within 100s. Generally, it is because the disk on PD is slow and busy or the network failed between TiDB and PD. For the details of common errors, see Error Number and Fault Diagnosis.
When the client or proxy disconnects from TiDB, TiDB does not immediately notice that the connection has been disconnected. Instead, TiDB can only notice the disconnection when it begins to return data to the connection. At this time, the log prints an EOF error.