Oracle deadlock query and Processing

Source: Internet
Author: User

 

I. Database deadlock
When the program is executed, click OK or save. The program does not respond or reports an error.
Ii. deadlock Principle
If you update or delete a column in a table in the database, this statement is not mentioned after the execution.
The statement that updates this column of data is in the waiting state during execution,
In this case, this statement has been executed, but it has not been successfully executed and no error has been 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. Users can
I don't 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;

The SID is replaced by the SID of the deadlock: Exit
PS-Ef | grep spid

Where spid is the process Number of the Process, kill the Oracle Process

From: http://southking.javaeye.com/blog/550832

 

 

Select a. SQL _text, B. username, C. object_id, C. session_id,
B. Serial #, C. oracle_username, C. OS _user_name, C. process,
''' | C. session_id | ',' | B. Serial # | ''''
From v $ SQL a, V $ session B, V $ locked_object C
Where a. hash_value = B. SQL _hash_value and
B. Sid = C. session_id

 

From: http://xinxiangsui2018.blog.163.com/blog/static/106097856201010304532280/

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.