Oracle deadlock and deadlock handling

Source: Internet
Author: User

Select SQL _text from v $ SQL where hash_value in (select SQL _hash_value from v $ session where sid in (select session_id from v $ locked_object ))

Check Methods for database deadlocks

I. Database deadlock

When the program is executed, click OK or save. The program does not respond or reports an error.

Ii. deadlock Principle

When you update or delete a column in a table in the database, the statement is not submitted after the execution is completed, another statement that updates this column of data is in the waiting state during execution. This statement is still being executed but has not been successfully executed, no error is reported.

Iii. deadlock locating

By checking the database table, you can check which statement is deadlocked and which machine is causing the deadlock.

1) Use the dba user to execute the following statements

Select username, lockwait, status, machine, program from v $ session where sid in (select session_id from v $ locked_object)

If there are output results, it indicates a deadlock exists and you can see which machine is deadlocked. Field description:

Username: the database user used by the deadlock statement;

Lockwait: the status of the deadlock. If there is content, it indicates the deadlock.

Status: Status. active indicates a deadlock.

Machine: The Machine where the deadlock statement is located.

Program: the application that generates the deadlock statement.

2) You can run the following statements with dba to view the statements that have been deadlocked.

Select SQL _text from v $ SQL where hash_value in

(Select SQL _hash_value from v $ session where sid in

(Select session_id from v $ locked_object ))

Iv. Solution to deadlock

Generally, you only need to submit statements that generate deadlocks, but in the actual execution process. The user may not know which statement is used to generate a deadlock. You can close the program and restart it.

This problem is often encountered during the use of Oracle, so a few solutions are also summarized.

  

1) Find the deadlock process:

Sqlplus "/as sysdba" (sys/change_on_install) SELECT s. username, l. OBJECT_ID, l. SESSION_ID, s. SERIAL #, l. ORACLE_USERNAME, l. OS _USER_NAME, l. process from v $ LOCKED_OBJECT l, V $ session s where l. SESSION_ID = S. SID;

2) kill the deadlock process:

Alter system kill session 'sid, serial # '; (sid = l. session_id)

3) if the problem persists:

Select pro. spid from v $ session ses, v $ process pro where ses. sid = XX and ses. paddr = pro. addr;

Replace the sid with the sid of the deadlock:

Exit

Ps-ef | grep spid

Spid is the process Number of the process and kill the Oracle process.

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.