Skip to content
pvmehta.com

pvmehta.com

  • Home
  • About Me
  • Toggle search form
  • USER_TABLES.Freelists Oracle
  • Python class import from different folders Python/PySpark
  • 272332.1 CRS 10g Diagnostic Collection Guide Oracle
  • DBMS_Shared_pool pinning triggers Oracle
  • True Session Wait Activity in Oracle 10g Verygood Oracle
  • My Test Case On 21-OCT-2005 Oracle
  • create a folder in multiple places Linux/Unix
  • find_longsql.sql Oracle
  • SYSOPER Mystery Oracle
  • DBMS_STATS Metalinks Notes Oracle
  • SQL Tracker by SID sqltrackerbysid.sql Oracle
  • find_err.sql for finding errors from dba_errors. Oracle
  • Follwoing korn shell is used to move files from source folder to destination folder and gzip it in destination folder. mv_iotto.ksh Linux/Unix
  • oracle fast start failover best practice Oracle
  • How to Decide upto what level you can decrement your datafile size. ( Shrink Datafile) 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

  • Ports used by Oracle Software Oracle
  • fkwoind.sql fkwoindex.sql Oracle
  • How to start CRS manually Oracle
  • How to find pinned objects from shared pool. (pinned via dbms_shared_pool.keep) Oracle
  • crtgr.sql /* For creating trigger from data dictionary */ Oracle
  • Optimizer SORT Operations Oracle

Leave a Reply Cancel reply

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

Categories

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

Recent Posts

  • Key Management in Oracle: The Core Issue: Missing Master Key12-May-2026
  • SAT Mathematics 10 questions and answer at the end.30-Apr-2026
  • top 10 AI news today30-Apr-2026
  • runon_allpdbs_show_conname.sh23-Apr-2026
  • runon_allcdbs_find_pdbs.sql23-Apr-2026
  • Running PDB on single node in RAC09-Apr-2026
  • find_arc.sql09-Apr-2026
  • pvm_pre_change.sql08-Apr-2026
  • find_encr_wallet.sql08-Apr-2026
  • find_pdbs.sql08-Apr-2026

Archives

  • 2026
  • 2025
  • 2024
  • 2023
  • 2010
  • 2009
  • 2008
  • 2007
  • 2006
  • 2005
  • Find long Running Transaction Linux/Unix
  • Looping for remote servers and find its database from oratab file. Linux/Unix
  • tab.sql Oracle
  • Find All internal Parameters Oracle
  • Creating never expiring DB user accounts in Oracle Oracle
  • replacing ^M character when passing files from Windows to Unix Linux/Unix
  • DETERMINING WHICH INSTANCE OWNS WHICH SHARED MEMORY & SEMAPHORE SEGMENTS Oracle
  • To see mem usage and CPU usage system wide. Linux/Unix

Copyright © 2026 pvmehta.com.

Powered by PressBook News WordPress theme