Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
oracle_locking_latches_mutexes [2020/02/27 15:52] – [Mutexes] andonovjoracle_locking_latches_mutexes [2021/01/07 18:48] (current) – [Enqueues] andonovj
Line 66: Line 66:
  
 It is worth mentioning that latches aren't used so much in newer Oracle version: >=11g. They were replaced by other structure called MUTEX, which is way more optimal and efficient :) It is worth mentioning that latches aren't used so much in newer Oracle version: >=11g. They were replaced by other structure called MUTEX, which is way more optimal and efficient :)
 +
 +Latch present a contrast with enqueues which always protect structures which has some disk based equivalent such as database objects, data blocks or table rows.
 +Another significant difference between latch and enqueue In latches there is no ordered queue of waiters like in enqueues. Latch waiters may either use timers to wake up and retry or spin (only in multiprocessors). Since all waiters are concurrently retrying (depending on the scheduler), anyone might get the latch and conceivably the first one to try might be the last one to get.
 +
 +
 +We can check all the latches as follows:
 +
 +<Code:none|All latches>
 +SQL> column name format A32 truncate heading "LATCH NAME"
 +SQL> column pid heading "HOLDER PID"
 +SQL> 
 +column name format A32 truncate heading "LATCH NAME"
 +column pid heading "HOLDER PID"
 +select c.name,a.addr,a.gets,a.misses,a.sleeps,
 +a.immediate_gets,a.immediate_misses,b.pid
 +from v$latch a, v$latchholder b, v$latchname c
 +where a.addr = b.laddr(+)
 +and a.latch# = c.latch#
 +order by a.latch#;
 +
 +LATCH NAME                       ADDR                   GETS     MISSES     SLEEPS IMMEDIATE_GETS IMMEDIATE_MISSES HOLDER PID
 +-------------------------------- ---------------- ---------- ---------- ---------- -------------- ---------------- ----------
 +PC and Classifier lists for WLM  0000000060001008          0          0          0              0                0
 +post/wait queue                  000000006000AA50    2928430      11793          6        3766322            66095
 +hot latch diags                  000000006000AAF0          0          0          0              0                0
 +event stats latch                000000006000AB90      22019          0          0              0                0
 +test excl. non-parent l0         000000006000AC30          0          0          0              0                0
 +test excl. parent l0             000000006000ACD0         16          0          0              0                0
 +test excl. parent2 l0            000000006000AD70         16          0          0              0                0
 +test shared non-parent l0        000000006000AE10          0          0          0              0                0
 +test excl. non-parent lmax       000000006000AEB0          0          0          0              0                0
 +test excl. parent2 lmid cln      000000006000AF50         16          0          0              0                0
 +-------------------------------------------------------------------------------------------------------------------------------
 +</Code>
 +
 +Let's further examine the most gets/misses/sleeps
 +
 +<Code:none|Most Gets/Misses/Sleeps>
 +SQL> SET LINESIZE 200
 +SET VERIFY OFF
 +
 +SELECT *
 +FROM   (SELECT name,
 +               addr,
 +               gets,
 +               misses,
 +               sleeps
 +        FROM   v$latch_children
 +        WHERE  name = 'cache buffers chains'
 +        AND    misses > 0
 +        ORDER BY gets DESC)
 +WHERE  rownum < 11;SQL> SQL> SQL>      3    4    5    6    7    8    9   10   11
 +
 +LATCH NAME                       ADDR                   GETS     MISSES     SLEEPS
 +-------------------------------- ---------------- ---------- ---------- ----------
 +cache buffers chains             00000015E20F7FD0   80117072      12433          1
 +cache buffers chains             00000015E28B5410   69023575      32689          1
 +cache buffers chains             00000015E2240B90   62530840       6372          0
 +cache buffers chains             00000015C2B81478   44844620       1942          0
 +cache buffers chains             00000015C267BBB8   39572452       3678          0
 +cache buffers chains             00000015C3128F78   38197451        307         28
 +cache buffers chains             00000016024085C0   34526929       5363          0
 +cache buffers chains             00000015E29B71D0   33984067       4204          0
 +cache buffers chains             00000015C2C1CFF8   26825192       2296          0
 +cache buffers chains             00000015C2E1CDF8   24599155      57614          0
 +</Code>
 +
 +From that we can see that latch child with addr: '00000015C2E1CDF8' has a lot of gets and some misses but 0 sleeps.
 +
 +<Code:none|Behind a child Latch>
 +ACCEPT address PROMPT "Enter ADDR: "
 +
 +COLUMN owner FORMAT A15
 +COLUMN object_name FORMAT A30
 +COLUMN subobject_name FORMAT A20
 +
 +SELECT *
 +FROM   (SELECT bh.hladdr,
 +        o.owner,
 +               o.object_name,
 +               o.subobject_name,
 +               o.object_type,
 +               bh.tch,
 +               bh.obj,
 +               bh.file#,
 +               bh.dbablk,
 +               DECODE(bh.class,1,'data block',
 +                               2,'sort block',
 +                               3,'save undo block',
 +                               4,'segment header',
 +                               5,'save undo header',
 +                               6,'free list',
 +                               7,'extent map',
 +                               8,'1st level bmb',
 +                               9,'2nd level bmb',
 +                               10,'3rd level bmb',
 +                               11,'bitmap block',
 +                               12,'bitmap index block',
 +                               13,'file header block',
 +                               14,'unused',
 +                               15,'system undo header',
 +                               16,'system undo block',
 +                               17,'undo header',
 +                               18,'undo block') AS class,
 +               DECODE(bh.state, 0,'free',
 +                                1,'xcur',
 +                                2,'scur',
 +                                3,'cr',
 +                                4,'read',
 +                                5,'mrec',
 +                                6,'irec',
 +                                7,'write',
 +                                8,'pi',
 +                                9,'memory',
 +                                10,'mwrite',
 +                                11,'donated') AS state
 +        FROM   x$bh bh,
 +               dba_objects o
 +        WHERE  o.data_object_id = bh.obj
 +        AND    hladdr IN (SELECT addr
 +                FROM   v$latch_children
 +                WHERE  name='cache buffers chains'
 + and addr='00000015C2E1CDF8')
 +        ORDER BY tch DESC);
 +
 +
 +HLADDR           OWNER           OBJECT_NAME                    SUBOBJECT_NAME       OBJECT_TYPE                    TCH        OBJ      FILE#     DBABLK CLASS              STATE
 +---------------- --------------- ------------------------------ -------------------- ----------------------- ---------- ---------- ---------- ---------- ------------------ -------
 +00000015C2E1CDF8 XCREW           ITEM_DAILY                                          TABLE                          173     172650         18    3209239 data block         xcur
 +00000015C2E1CDF8 XCREW           DUTY                                                TABLE                           43     173197         22     212524 data block         xcur
 +00000015C2E1CDF8 XCREW           CHAIN_ITEM_DAILY                                    TABLE                           41     173041         21    2864141 data block         xcur
 +00000015C2E1CDF8 XCREW           ROSTER_TAG                                          TABLE                           25     447074         22    3222873 data block         xcur
 +00000015C2E1CDF8 XCREW           DUTY                                                TABLE                           18     173197         21    2546330 data block         xcur
 +00000015C2E1CDF8 XCREW           ILLG_MSG                                            TABLE                            5     173010         20    2898245 data block         xcur
 +00000015C2E1CDF8 SCHEDOPS        ISEGMENT_INFO                                       INDEX                            4     132692         12     147397 data block         xcur
 +00000015C2E1CDF8 XCREW           DUTY                                                TABLE                            1     173197         20    2384016 data block         xcur
 +00000015C2E1CDF8 XCREW           AFS_LOG                                             TABLE                            1     173534         20    3216056 data block         xcur
 +00000015C2E1CDF8 XCREW           XPKDAILY_ACCOUNT                                    INDEX                            0     173877         24    1286504 data block         xcur
 +00000015C2E1CDF8 XCREW           DUTY                                                TABLE                            0     173197         18    2377199 data block         xcur
 +</Code>
 +
 +
 +We can also search for the most misses:
 +
 +<Code:none|Most misses>
 +SQL> SELECT
 +      addr,
 +      sleeps
 +FROM
 +      v$latch_children c,
 +      v$latchname n
 +WHERE
 +      n.name='cache buffers chains' and
 +      c.latch#=n.latch# and
 +      sleeps > 100
 +ORDER BY sleeps  2    3    4    5    6    7    8    9   10   11
 + 12  ;
 +
 +ADDR                 SLEEPS
 +---------------- ----------
 +00000015C31212F8        128
 +00000015C32020B8        177
 +00000015E27150D0        198
 +0000001602639EC0        225
 +00000016025F30C0        280
 +0000001602E696C0        294
 +0000001602291140        300
 +00000015E2B82650        548
 +00000015C2EA0138       1879
 +</Code>
 +
 +And of course we can see what is behind that latch: '00000015C2EA0138'
 +
 +<Code:none|Most sleepy latch>
 +
 +SQL> COLUMN owner FORMAT A15
 +COLUMN object_name FORMAT A30
 +COLUMN subobject_name FORMAT A20
 +
 +SELECT *
 +FROM   (SELECT bh.hladdr,
 +               o.owner,
 +               o.object_name,
 +               o.subobject_name,
 +               o.object_type,
 +               bh.tch,
 +               bh.obj,
 +               bh.file#,
 +               bh.dbablk,
 +               DECODE(bh.class,1,'data block',
 +                               2,'sort block',
 +                               3,'save undo block',
 +                               4,'segment header',
 +                               5,'save undo header',
 +                               6,'free list',
 +                               7,'extent map',
 +                               8,'1st level bmb',
 +                               9,'2nd level bmb',
 +                               10,'3rd level bmb',
 +                               11,'bitmap block',
 +                               12,'bitmap index block',
 +                               13,'file header block',
 +                               14,'unused',
 +                               15,'system undo header',
 +                               16,'system undo block',
 +                               17,'undo header',
 +                               18,'undo block') AS class,
 +               DECODE(bh.state, 0,'free',
 +                                1,'xcur',
 +                                2,'scur',
 +                                3,'cr',
 +                                4,'read',
 +                                5,'mrec',
 +                                6,'irec',
 +                                7,'write',
 +                                8,'pi',
 +                                9,'memory',
 +                                10,'mwrite',
 +                                11,'donated') AS state
 +        FROM   x$bh bh,
 +               dba_objects o
 +        WHERE  o.data_object_id = bh.obj
 +        AND    hladdr IN (SELECT addr
 +                        FROM   v$latch_children
 +                        WHERE  name='cache buffers chains'
 +                                        and addr='00000015C2EA0138')
 +        ORDER BY tch DESC);
 +                SQL> SQL> SQL> SQL>      3    4    5    6    7    8    9   10   11   12   13   14   15   16   17   18   19   20   21   22   23   24   25   26   27   28   29   30   31   32   33   34   35   36   37   38   39   40   41   42   43   44   45   46   47   48
 +
 +HLADDR           OWNER           OBJECT_NAME                    SUBOBJECT_NAME       OBJECT_TYPE                    TCH        OBJ      FILE#     DBABLK CLASS              STATE
 +---------------- --------------- ------------------------------ -------------------- ----------------------- ---------- ---------- ---------- ---------- ------------------ -------
 +00000015C2EA0138 XCREW           PERIODIC_ACCOUNT                                    TABLE                          254     172818         21      84048 data block         xcur
 +00000015C2EA0138 XCREW           XPKITEM_DAILY                                       INDEX                          237     174076         25    1361263 data block         xcur
 +00000015C2EA0138 SCHEDOPS        I_TXQ_STATE                                         INDEX                          204     132572         12     891882 data block         xcur
 +00000015C2EA0138 XCREW           ITEM_DAILY                                          TABLE                          154     172650         18    2803873 data block         xcur
 +00000015C2EA0138 IOCC            ACTIVEMQ_ACKS                                       TABLE                           83     132226         55      63100 data block         xcur
 +00000015C2EA0138 SCHEDOPS        LEG_REMARK                                          TABLE                           25     132191          9     805439 data block         xcur
 +00000015C2EA0138 XCREW           DAILY_ACCOUNT                                       TABLE                            8     173040         18    2607455 data block         xcur
 +00000015C2EA0138 XCREW           XPKEVENT_ACCOUNT                                    INDEX                            2     174386         27    1939174 data block         xcur
 +00000015C2EA0138 IOCC            ACTIVEMQ_ACKS                                       TABLE                            1     132226         55      63100 data block         cr
 +00000015C2EA0138 IOCC            ACTIVEMQ_ACKS                                       TABLE                            1     132226         55      63100 data block         cr
 +00000015C2EA0138 SCHEDOPS        PUBLISHED_VERSION                                   TABLE                            1     132325          9     487628 data block         xcur
 +00000015C2EA0138 IOCC            ACTIVEMQ_ACKS                                       TABLE                            1     132226         55      63100 data block         cr
 +00000015C2EA0138 IOCC            ACTIVEMQ_ACKS                                       TABLE                            1     132226         55      63100 data block         cr
 +00000015C2EA0138 IOCC            ACTIVEMQ_ACKS                                       TABLE                            1     132226         55      63100 data block         cr
 +00000015C2EA0138 IOCC            ACTIVEMQ_ACKS                                       TABLE                            1     132226         55      63100 data block         cr
 +00000015C2EA0138 SCHEDOPS        I_PUB_VERSION_FLT                                   INDEX                            0     132567         12      59842 data block         xcur
 +00000015C2EA0138 SCHEDOPS        SEGMENT_INFO                                        TABLE                            0     132252         10     135713 data block         xcur
 +</Code>
 +
  
 =====KGL Locks & Pins===== =====KGL Locks & Pins=====
Line 146: Line 396:
  
 =====Enqueues===== =====Enqueues=====
 +Enqueues are your standard locks and they come in several tyes:
 +
 +  * TX: Transaction lock: 
 +  *   * mode 6: data modification, 
 +  *   * mode 4: setting tablespace to read only, foreign key enforcement, unique index key enforcement, ITL space waits, and more.
 +  * TM: Table modification (or locking a referenced table when the foreign key is not indexed)
 +  * UL: Lock used by user applications, a lock is requested by DBMS_LOCK.REQUEST
 +  * CF: Control file: actions accessing the control file, like: log switch, redo archiving, and backup
 +  * ST: Space Transaction: dictionary-managed tablespaces within extent allocations and releases
 +  * TT: Temporary tablespace: parallel tablespace operations
 +  * CI: Cross-instance: data accessed from multiple instances (db link)
 +  * HV: Parallel direct-path insert
  • oracle_locking_latches_mutexes.1582818755.txt.gz
  • Last modified: 2020/02/27 23:52
  • (external edit)