Skip to content
pvmehta.com

pvmehta.com

  • Home
  • About Me
  • Toggle search form
  • tblwopk.sql /* Find Tables Without PK */ Oracle
  • 272332.1 CRS 10g Diagnostic Collection Guide Oracle
  • To check whether standby is recovering properly or not?? Oracle
  • All About Trace Fils Oracle
  • move_arch_files.ksh /* Good One */ Linux/Unix
  • plan10g.sql Oracle
  • Parallel DML Oracle
  • 751131.1 New Article Error 2819 While Requesting a Systemstate Dump Oracle
  • CPU Core related projections AWS
  • find checksum of a file. Linux/Unix
  • Disbaling DBA_SCHEDULER_JOBS Oracle
  • Wait Based Tuning Step by step with SQL statement Oracle
  • move_arch_files.ksh Linux/Unix
  • Index Range Scan Oracle
  • How to specify 2 arch location to avoid any kind of DB hanging. Oracle
pvmehta.com SQL scripts

Find which sessions is accessing object that prevent your session to have exclusive locks in Oracle

Posted on 11-Jun-202311-Jun-2023 By Admin No Comments on Find which sessions is accessing object that prevent your session to have exclusive locks in Oracle

If you want exclusive lock on any table, you need to make sure that no other session is  accessing it. This happens when you want to run DDL or any ALTER statements, that internally needs exclusive lock. Following script will to find the blocker session and provide killing statement for clearing locks. 

col owner format a20
set lines 120 pages 200

accept v_owner prompt "Enter owner:"
accept v_objnm prompt "Enter object_name:"

select a.inst_id, substr(d.sid,1,7) SID,substr(d.serial#,1,7) SERIAL,
substr(to_char(d.logon_time,'hh24:mi:ss'),1,8) time
,substr(b.object_name,1,23) OBJECT_NAME,
b.owner, d.machine, d.program, d.module,
'alter system kill session ''' || d.sid || ',' || d.serial# || ', @' || d.inst_id || ''';' || chr(10) || lpad('+', 80, '+')
from gv$lock a,dba_objects b,gv$session d
where (a.id1=b.object_id or a.id2 = b.object_id)
and a.inst_id = d.inst_id
/*and object_name = 'MAXVALUE'*/
and d.sid=a.sid
--and b.owner not in ('SYS')
and b.owner = upper('&v_owner')
and b.object_name = upper('&v_objnm')
order by d.username
/


select
'alter system kill session ''' || d.sid || ',' || d.serial# || ', @' || d.inst_id || ''';' || chr(10)
from gv$lock a,dba_objects b,gv$session d
where (a.id1=b.object_id or a.id2 = b.object_id)
and a.inst_id = d.inst_id
/*and object_name = 'MAXVALUE'*/
and d.sid=a.sid
--and b.owner not in ('SYS')
and b.owner = upper('&v_owner')
and b.object_name = upper('&v_objnm')
order by d.username
/
Oracle, SQL scripts

Post navigation

Previous Post: How to collect CPU usage on Linux using Shell script
Next Post: Oracle GoldenGate lag monitoring shell script

Related Posts

  • tblwopk.sql /* Find Tables Without PK */ Oracle
  • crtgr.sql /* For creating trigger from data dictionary */ Oracle
  • Goldengate Tutorial Oracle
  • Oracle Identifiers Oracle
  • Good link for LIO in Oracle ( Logical IOs) Oracle
  • CTAS with LONG Column for 9i and higher Oracle

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Categories

  • Ansible (0)
  • AWS (2)
  • Azure (1)
  • Linux/Unix (149)
  • MYSQL (5)
  • Oracle (392)
  • PHP/MYSQL/Wordpress (10)
  • POSTGRESQL (0)
  • Power-BI (0)
  • Python/PySpark (7)
  • RAC (17)
  • rman-dataguard (26)
  • shell (149)
  • SQL scripts (341)
  • SQL Server (6)
  • Uncategorized (0)
  • Videos (0)

Recent Posts

  • SQL Server Vs Oracle Architecture difference25-Jul-2025
  • SQL Server: How to see historical transactions25-Jul-2025
  • SQL Server: How to see current transactions or requests25-Jul-2025
  • T-SQL Vs PL/SQL Syntax25-Jul-2025
  • Check SQL Server edition25-Jul-2025
  • Checking SQL Server Version25-Jul-2025
  • Oracle vs MYSQL Architecture differences (For DBAs)24-Jul-2025
  • V$INSTANCE of Oracle in MYSQL24-Jul-2025
  • Day to day MYSQL DBA operations (Compared with Oracle DBA)24-Jul-2025
  • MYSQL and Oracle Comparison for Oracle DBA24-Jul-2025

Archives

  • 2025
  • 2024
  • 2023
  • 2010
  • 2009
  • 2008
  • 2007
  • 2006
  • 2005
  • pvm_metric.sql for gathering report from vmstat tables Oracle
  • create a folder in multiple places Linux/Unix
  • how to find VIP from ifconfig Linux/Unix
  • Explain Plan Output 2 Oracle
  • cold backup scripts to copy locally Linux/Unix
  • Looping for remote servers and find its database from oratab file. Linux/Unix
  • Zip and unzip with tar Linux/Unix
  • UNderstand and eliminate Latch contention. Oracle

Copyright © 2025 pvmehta.com.

Powered by PressBook News WordPress theme