How to Handle Deadlocks in TiDB

Note:
This topic has been translated from a Chinese forum by GPT and might contain errors.

Original topic: tidb死锁了怎么处理

| username: TiDBer_Y2d2kiJh

[TiDB Usage Environment] Production Environment
[TiDB Version] v5.4.0
[Reproduction Path] A deadlock was found in the database, how should it be handled?
[Encountered Problem: Problem Phenomenon and Impact]
[Resource Configuration] Go to TiDB Dashboard - Cluster Info - Hosts and take a screenshot of this page
[Attachment: Screenshot/Log/Monitoring]

| username: 啦啦啦啦啦 | Original post link

Refer to this

| username: weixiaobing | Original post link

Deadlocks can be examined within the SQL business scenarios. They are generally caused by issues in the SQL logic of the business scenarios.

| username: TiDBer_Y2d2kiJh | Original post link

Could you please tell me how to solve this locking issue first?

| username: 啦啦啦啦啦 | Original post link

It has already appeared in the deadlocks dictionary table, which means it has ended. Is there still a need to resolve it… The rest can be optimized according to the link above.

| username: TiDBer_Y2d2kiJh | Original post link

Okay, thank you.

| username: 春风十里 | Original post link

Will deadlocks that occurred in the past be recorded in the log files?

| username: TiDBer_Y2d2kiJh | Original post link

Yes, this record appears: Deadlock found when trying to get lock; try restarting transaction.

| username: tony5413 | Original post link

Find the cause of the deadlock, throw it to the developers, and then give them a scolding.

| username: 春风十里 | Original post link

Where can I find TiDB logs? I want to check TiDB’s error logs, similar to MySQL’s error log. Additionally, I would like to understand the other file structures. I haven’t found any information on this topic yet.

| username: 摊煎饼果子的蒙其 | Original post link

Identify the cause of the deadlock, which is the SQL, and work with the developers to analyze and optimize it.

| username: 春风十里 | Original post link

I checked my test environment directory and found that there are also deadlock records in the tidb.log.


However, it seems that the log only contains one deadlock error record and not the other statement’s record. The information_schema.deadlock records are more detailed. The question is, will the information_schema.deadlock be deleted?

| username: TiDBer_Y2d2kiJh | Original post link

There is also a table that records deadlocks, and the number of records can be configured. select * from INFORMATION_SCHEMA.CLUSTER_DEADLOCKS;

| username: TiDBer_Y2d2kiJh | Original post link

Found it, it is indeed due to development reasons.

| username: system | Original post link

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.