Investigating transactions and concurrency
In this recipe we will see more details on locking and, specifically, on deadlocks .
Getting ready
In this recipe we will use two SQL*Plus sessions, to simulate two users concurrently accessing the database.
How to do it...
This recipe deals wits transactions and concurrency. Follow these steps:
Connect
SESSION 1
to the database asSH
user:-- SESSION 1 CONNECT sh@TESTDB/sh
Update a row on the
CUSTOMERS
table inSESSION 1
:UPDATE CUSTOMERS SET CUST_FIRST_NAME = 'TEST1-1' WHERE CUST_ID = 26;
Connect
SESSION 2
to the database asSH
user:-- SESSION 2 CONNECT sh@TESTDB/sh
Update a row on the
CUSTOMERS
table inSESSION 2
, different from the one updated in step 2 bySESSION 1
:UPDATE CUSTOMERS SET CUST_FIRST_NAME = 'TEST2-1' WHERE CUST_ID = 30;
Try to update, in
SESSION 1
, the same row updated in step 4 bySESSION 2
:-- SESSION 1 UPDATE CUSTOMERS SET CUST_FIRST_NAME = 'TEST1-2' WHERE CUST_ID = 30;
Try to update, in
SESSION 2
, the same row updated...