Atitit Lifting Database Deadlock processing summary

Source: Internet
Author: User

Atitit Lifting Database Deadlock processing summary

In normal terms, the lock is automatic. No official.
Normally, insert does not need to add rowlock, it is the default is Rowlock,


#-----The principle of automatic switching of locks. (Normal ignore it, except ALTER TABLE field)
When a transaction exceeds its upgrade threshold, the database may automatically escalate row and page locks to table locks.

For example, when a table transaction is executed on a row, the database automatically acquires locks on the affected rows, and the higher-level intent locks are placed on the pages and tables that contain the rows. All related index pages will also be locked at the same time. When the number of locks held by the firm exceeds its threshold, it attempts to change the intent lock on the table to a stronger lock. For example, an intent exclusive (IX) lock can be changed to an exclusive (X) lock. When a stronger lock is obtained, all page-level and row-level locks held by the transaction on the table are freed.

Author of Old Wow's Paw attilax Ayron, email:[email protected]
Reprint please indicate source: Http://blog.csdn.net/attilax

#-------Transactions and deadlocks

The transaction lengthens the processing process and increases the chance of deadlock.
It's not that you can't use transactions,,, you should use transactions or you should use transactions ... Use sync to resolve deadlocks at the same time.


#------Resolve Deadlocks

Default state ha, only when the same record is modified for the time, it may be deadlock ...

and file ya 10, add a sync sync inside the code go OK LAN

Non-important items, direct only update operation sync Walk OK ...


#------Resolution of Deadlocks (supplementary method)

Code leaks are unavoidable, and must be caught with both hands ...
Client, automatically closes the timeout conn, as if the timeout transaction does not take effect. Had to write their own GC outtime ...
Server, set conn timeout, and lock timeout ...
The watchdog must be. Query lock or long time sql, kill ....



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.