在联机(共享)服务器模式下死锁的产生并解锁

由于UGA是专门用于存放与用户会话相关信息,如登录信息、会话状态等。

专用服务器模式下,进程和会话是一对一的关系,UGA被包含在PGA中,

在联机(共享)服务器模式下,进程和会话是一对多的关系,所以UGA就不再属于 PGA了,而会在大型池(Large Pool)中分配。但如果从大型池中分配失败,如大型池太小,或是根本没有设置大型池,则从共享池(Shared Pool)中分配。

官方:deadlocking,多个用户(进程)分别锁定了一个资源,并又试图请求锁定对方已经锁定的资源,就产生了一个锁定请求环,导致多个用户(进程)都处于等待对方释放其锁定资源的状态。

死锁:多个人修改同一条记录,且没有执行提交或回滚操作,由数据库自动解锁,找出是哪两个会话和哪两个sql语句返回给业务。

ps -ef | grep LOCAL=    #查询进程  YES本地连接,NO非本地连接

oracle    2917  2913  0 11:34 ?        00:00:00 oracleora (DESCRIPTION=(LOCAL=YES)(ADDRESS=(PROTOCOL=beq)))

oracle    3060  2629  0 12:14 ?        00:00:00 oracleora (DESCRIPTION=(LOCAL=YES)(ADDRESS=(PROTOCOL=beq)))

kill -9 进程号SID    #杀掉一个进程

select * from v$session where username='SCOTT';

select * from v$lock  #记录锁相关的视图

TX #type行级锁

6  #行锁

alter system kill session‘16,271’ #精准杀掉一个进程

#模拟一个死锁

session 1

SQL>  update emp

  2  set sal=8000

  3  where ename='SUNMENG';

1 row updated.

session2

SQL> update emp

  2  set sal=10000

  3  where ename='CATHERINE';

1 row updated.

session1

SQL> update SCOTT.EMP

  2  set sal=10000

  3  where ename='CATHERINE';

update SCOTT.EMP

session2

SQL> update emp

  2  set sal=9000

  3  where ename='SUNMENG';

update emp

session1

ERROR at line 1:

ORA-00060: deadlock detected while waiting for resource



SQL> set pages 200 lines 200;

SQL> col ADDR for a50;

SQL> select * from v$lock;  #查看有多少个锁,TM是同步访问对象用的,TX是和事务有关的.

ADDR                                               KADDR                   SID TY        ID1        ID2      LMODE    REQUEST      CTIME      BLOCK

-------------------------------------------------- ---------------- ---------- -- ---------- ---------- ---------- ---------- ---------- ----------

000000009118E708                                   000000009118E760          7 KD          0          0          6          0      12451          0

000000009118EB68                                   000000009118EBC0          7 KT      12876          0          4          0      12451          0

000000009118E628                                   000000009118E680         10 MR          3          0          4          0      12451          0

000000009118E9A8                                   000000009118EA00         10 MR          4          0          4          0      12451          0

000000009118E8C8                                   000000009118E920         10 MR          1          0          4          0      12451          0

000000009118E1C8                                   000000009118E220         10 MR          2          0          4          0      12451          0

000000009118EA88                                   000000009118EAE0         10 MR        201          0          4          0      12451          0

000000009118EF00                                   000000009118EF58         10 PW          1          0          3          0      12449          0

000000009118E2A8                                   000000009118E300         11 RT          1          0          6          0      12451          0

000000009118DF28                                   000000009118DF80         12 RD          1          0          1          0      12455          0

000000009118E388                                   000000009118E3E0         12 RS         25          1          2          0      12451          0

000000009118DE48                                   000000009118DEA0         12 XR          4          0          1          0      12455          0

000000009118E008                                   000000009118E060         12 CF          0          0          2          0      12455          0

000000009118E548                                   000000009118E5A0         13 TS          3          1          3          0      12451          0

000000009118E0E8                                   000000009118E140         15 AE        100          0          4          0      12450          0

000000009118F0C0                                   000000009118F118         26 AE        100          0          4          0       7124          0

000000008FA097B0                                   000000008FA09828         26 TX     262170       1008          6          0        471          0

000000009118ED40                                   000000009118ED98         26 TX     524298       1016          0          6        150          0

00007F1B5E11ADC8                                   00007F1B5E11AE28         26 TM      83202          0          3          0       1052          0

000000009118E7E8                                   000000009118E840         31 AE        100          0          4          0       4722          0

000000008FA54F48                                   000000008FA54FC0         31 TX     524298       1016          6          0        386          1

00007F1B5E11ADC8                                   00007F1B5E11AE28         31 TM      83202          0          3          0        386          0

22 rows selected.



SQL> select SID,SERIAL#,USERNAME,LOCKWAIT,TYPE,event from v$session; 

       SID    SERIAL# USERNAME                       LOCKWAIT         TYPE       EVENT

---------- ---------- ------------------------------ ---------------- ---------- ----------------------------------------------------------------

         1        109                                                 BACKGROUND Space Manager: slave idle wait

         2          1                                                 BACKGROUND pmon timer

         3          1                                                 BACKGROUND rdbms ipc message

         4          1                                                 BACKGROUND VKTM Logical Idle Wait

         5          1                                                 BACKGROUND rdbms ipc message

         6          1                                                 BACKGROUND DIAG idle wait

         7          1                                                 BACKGROUND rdbms ipc message

         8          1                                                 BACKGROUND DIAG idle wait

         9          1                                                 BACKGROUND rdbms ipc message

        10          1                                                 BACKGROUND rdbms ipc message

        11          1                                                 BACKGROUND rdbms ipc message

        12          1                                                 BACKGROUND rdbms ipc message

        13          1                                                 BACKGROUND smon timer

        14          1                                                 BACKGROUND rdbms ipc message

        15          1                                                 BACKGROUND rdbms ipc message

        16          1                                                 BACKGROUND rdbms ipc message

        20          3                                                 BACKGROUND Streams AQ: qmn coordinator idle wait

        25          7                                                 BACKGROUND Streams AQ: waiting for time management or cleanup tasks

        26         63 SCOTT                          000000009118ED98 USER       enq: TX - row lock contention

        27          1                                                 BACKGROUND rdbms ipc message

        28          9                                                 BACKGROUND Streams AQ: qmn slave idle wait

        29         29                                                 BACKGROUND rdbms ipc message

        31         23 SYS                                             USER       SQL*Net message to client

        32        169                                                 USER       jobq slave wait

        34        171                                                 USER       jobq slave wait

25 rows selected.

#精准杀掉被锁的进程。

SQL> alter system kill session '26,63';

System altered.


#再次执行上述操作,session2的事务已回滚并直接退出登录。
session2

update emp

       *

ERROR at line 1:

ORA-00028: your session has been killed

ORA-00028: your session has been killed

#由于解锁的过程以结束一个用户进程为代价,导致该用户session与instance取消连接,需要重新访问并建立专有连接。

session2

SQL> show parameter shared_pool;

ERROR:

ORA-03114: not connected to ORACLE

       综上所述,死锁在系统设计、进程调度方面都可以完美的避免,如何协调好操作系统的硬件资源,更好的为软件提供服务,需要确定资源的合理分配算法,避免进程永久占据系统资源,也要防止进程在处于等待状态的情况下占用资源,需要对资源的分配要有合理的规划。

你可能感兴趣的:(在联机(共享)服务器模式下死锁的产生并解锁)