sql server deadlock

On the morning to see the server memory sql server accounts for more than 90%, and thus has to manually restart the sql services, memory decline is accounted for, but the question is, this is just great, how to solve?

 

         First burst kill, delete a new process out of the process there?

         There are several online solutions. Tried one by one, I feel no effect, but fortunately, this temporary deadlock does not affect the operation of other services, but need to find a solution.

        First you need to understand how the deadlock is generated?

        Resources to compete in two or more tasks, each task if the task of trying to lock to lock the other resources at this time will cause permanent obstruction of these tasks, thereby deadlock. Analogy, there are two cooks in the kitchen, then only a kitchen knife, and once, A chef with a kitchen knife, chef also with B, then B, etc. A chef cooks can only run out, then use the knife.

        Deadlock is formed with a four requirements:

        Request to maintain conditions: access to resources processes can apply for a new resource at the same time;

        Non-deprivation: resources have been allocated can not be deprived from the process. (A chef chopping vegetables, then we would fry, outside guests reminders dish, so not deprivation.)

        Loop wait condition: a plurality of processes form a loop, and wherein each neighbor is waiting for a process;

        Mutually exclusive conditions: resources can only be used by a process.

Second, how to solve the deadlock problem?

1, Clear deadlock

2, the use of lock-free query

Read the next book, the book thrown a touch of the sentence: generally removed one of the most important matters, to release resources it holds, so that important matters first run, after reprocessing the transaction. Of course, in advance to avoid a deadlock occurs is the best way to solve the deadlock problem. (It did not say wrong, but the practical operation rather poor, only in theory.)

Wherein the processing steps are summarized as follows:

1, first find the corresponding information of this deadlock;

Here you can see blkby process that led to a deadlock, and then command the operation on behalf of the cause deadlock. How to view that this process is in particular operating statements that lead to it? Use dbcc inputbuffer (spid) to view. Here is where evnetinfo lead to action statement deadlock.

2, then you need to determine where the program which performed these statements, then check out whether there is sp_who2, causing a deadlock command, for example, command is delete, then look for related operations in the program. If the case does not affect the business, you can delete this part of the operation, or be replaced by other means? Or change the timing of tasks, optimization of this part of the operation and try again.

Like the figure, according to information tips, find the corresponding delete statement, then read this statement does not affect the main business, it is simply removed, and she resolved.

 

There are several questions:

1, the program is running deadlock is normal? If a small amount of deadlock, over a period of time, whether the deadlock will be automatically released? (Great God says will be automatically released)

2, restart the sql server service is to relieve the deadlock? Restart the server?

3, how to avoid such problems in program development? How to design sql statement to prevent this problem?

4, this program has been running 2--3 years, it has never been a deadlock, why will appear after the restart sql server service, but also a stubborn presence.

There I also use the profiler sql, you can see the correlation analysis of the deadlock, but the feeling did not grasp this tool.

 

Write a bit chaotic, finishing it step by step. If you experience similar problems, they can communicate with each other next.

 

Which refer to the study of the following links: https://www.cnblogs.com/yanggb/p/10944350.html 

Published 125 original articles · won praise 9 · views 30000 +

Guess you like

Origin blog.csdn.net/jiezhang656/article/details/103167394