Skip to main content

DB Locks

PT :  Identificar DB Locks
EN :  Identify DB Locks

Blocking sessions

select
s1.status,
s1.logon_time,
s1.last_call_et seconds_since_active,
s1.module,
s1.username || '@' || s1.machine || ' with ' || s1.PROGRAM || ' ( SID=' || s1.sid || ' )  is blocking '
|| s2.username || '@' || s2.machine || ' ( SID=' || s2.sid || ' ) ' || ' conn with ' || s2.PROGRAM AS blocking_status,
'alter system kill session ''' || s1.sid || ',' || s1.serial# || ',@' ||  S1.INST_ID || ''' immediate ;' as kill_sess,
'alter system disconnect session ''' || s1.sid || ',' || s1.serial# || ',@' ||  S1.INST_ID || ''' immediate ;' as disconnect_sess
from
    gv$lock l1,
    gv$session s1,
    gv$lock l2,
    gv$session s2
where
s1.type='USER'
and s1.status='INACTIVE'
--and S1.MODULE like 'HH%'
and s1.sid=l1.sid
and s2.sid=l2.sid
and l1.BLOCK=1 and l2.request > 0
and l1.id1 = l2.id1
and l2.id2 = l2.id2
order by 3 desc;


Blocked Objects

select
       b.session_id as sid,
       username,
       a.owner as object_owner,
       a.object_name,
       decode(b.locked_mode, 0, 'none',
                             1, 'Null (NULL)',
                             2, 'Row-S (SS)',
                             3, 'Row-X (SX)',
                             4, 'Share (S)',
                             5, 'S/Row-X (SSX)',
                             6, 'Exclusive (X)',
                             b.locked_mode) as locked_mode,
       b.os_user_name,
       s.username,
       s.program,
       s.module,
       'alter system kill session ''' || s.sid || ',' || s.serial# || ''' immediate ;' as kill_sess
FROM   dba_objects a,
       gv$locked_object b,
       gv$session s
WHERE
a.object_id = b.object_id and b.session_id=s.sid
and s.SID in (
select
 s1.sid
from
    gv$lock l1,
    gv$session s1,
    gv$lock l2,
    gv$session s2
where
s1.type='USER'
and s1.status='INACTIVE'
and S1.MODULE like 'HH%'
and s1.sid=l1.sid
and s2.sid=l2.sid
and l1.BLOCK=1 and l2.request > 0
and l1.id1 = l2.id1
and l2.id2 = l2.id2 )


Blocked objects by Session

select 'alter system kill session ''' || s.sid || ',' || s.serial# || ''' immediate ;' as kill_sess,
       b.session_id as sid,
       nvl(b.oracle_username, '(oracle)') as username,
       a.owner as object_owner,
       a.object_name,
       decode(b.locked_mode, 0, 'None',
                             1, 'Null (NULL)',
                             2, 'Row-S (SS)',
                             3, 'Row-X (SX)',
                             4, 'Share (S)',
                             5, 'S/Row-X (SSX)',
                             6, 'Exclusive (X)',
                             b.locked_mode) as locked_mode,
       b.os_user_name,
       s.username
from   dba_objects a,
       gv$locked_object b,
       gv$session s
where
a.object_id = b.object_id and b.session_id=s.sid
and s.sid=1234
order by 1, 2, 3, 4;


Comments

Popular posts from this blog

DB - How to monitor Oracle datapump jobs

These days there is lot of work around database migrations not only but mainly to cloud providers. One of the ways to migrate Oracle databases is using data pump (expdp/impdp). In general works fine, it allows an easy way to bring the database even different OS. It is always good to monitor the progress, to know where we are and estimate how long we are from the end. In this post, I am sharing some queries to help with database monitoring progress. The queries can be easily tailed to various scenarios. Starting with a simple one - the track the number of objects loaded during an import operation. When there is a massive amount of errors during the import. Drop and run the import again. The bellow query can be useful also to monitor the number of objects if we are dropping the users. Here, I’m making the assumption there were no other database activity in progress on the last 24 hours. select owner, count(0) from dba_objects where owner in ( select username from dba_users where created...

VM - Partilhar Pastas Windows - Linux

Neste post escrevo como partilhar pastas entre Windows (Host) e uma VM Guest, neste caso Linux. Ha algumas formas de fazer isto, esta parece me a mais facil. Seleccionar a Pasta Windows Na consola Virtual Box > Devices > Shared Folder Seleccionar a pasta windows para partilhar no Linux   O   Montar a pasta Windows na VM Ha duas opcoes : 1) Reiniciar a VM (Auto-mount) 2) Linha de comando [root@host ~]# mkdir -p /u01/stage/win_ebs_sw [root@host ~]# chmod 777 /u01/stage/win_ebs_sw [root@host ~]# mount -t vboxsf Oracle_EBS /u01/stage/win_ebs_sw/ [root@host ~]# ls /u01/stage/win_ebs_sw ebs_weblogic_webtier [root@host ~]# df -h /u01/stage/win_ebs_sw Filesystem Size Used Avail Use% Mounted on Oracle_EBS 895G 494G 401G 56% /u01/stage/win_ebs_sw Guardar a Configuracao no /etc/fstab para tornar as alteracoes permanentes. [root@host ~]# echo "Oracle_EBS /u01/stage/win_ebs_sw vboxsf defaults 0 0" >> /etc/fstab [root@host ~]# cat /etc/fstab # /etc/...

DB – How to monitor Oracle database long ops ?

As DBAs, some questions we are often asked and to be fair we ask ourselfs when we are doing massive operations, are : Is the database doing something? How long the database takes to complete the task? There a data dictionary view, GV$SESSION_LONGOPS whom is really usefull for monitoring and to provide estimated time to get the task done. Starting with a first example, a query for general propose . set lines 240 col message form a100 col opname form a50 select * from ( select round(l.sofar/l.totalwork*100,2) as complete, --l.* l.sid, --l.opname, l.message, l.start_time, l.time_remaining/60 "minuts remaining", l.elapsed_seconds from gv$session_longops l where totalwork !=0 ) where complete < 100; The view is also usefull on specific operations such as Oracle Recovery Manager (RMAN) jobs monitoring, this query returns information about backup,restore and recovery. select sid, serial#,opname, context, sofar, totalwork, round(sofar/totalwork*100,2) "%_complet...