DisplayAdd1

TechnoTechDB is a platform, which will help to grow your carrier in Information sector. Having 15 years of Experience in Oracle/MongoDB/Postgres/Mysql databases, along with having good expertise level of knowledge in Scripting to automate database task. Our goal to start with zero to hero level expertise in Database. You can access/refer my some blogs on https://mrorcldba.blogspot.com link and post your comments and your suggestion to motive us.

Wednesday, 21 June 2023

Oracle Database Query Running more than 1 minutes and will kill automatically

Hello Friends, 

Below script help us to get SID and Serial details which is running more than 1 minutes and will kill automatically if you will keep below steps into a .sql file and run it from sql prompt. Please refer below screenshot. 

















SQL> select  round(last_call_et / 60,2) Time_in_mins, sid, serial# from gv$session where type<>'BACKGROUND' and username<>'SYS' and username <> 'DBSNMP' and last_call_et / 60 > 1;

no rows selected

SQL> select  round(last_call_et / 60,2) Time_in_mins, sid, serial# from gv$session where type<>'BACKGROUND' and username<>'SYS' and username <> 'DBSNMP' and last_call_et / 60 > 1;

TIME_IN_MINS        SID    SERIAL#

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

        12.6         15         21

        12.6        125         63

        12.6        138         55

SQL> set pagesize 0 linesize 1000 feedback off verify off trimspool on heading off echo off

SQL> SET SERVEROUTPUT ON

SQL> SET PAGESIZE 500

SQL> SET LINESIZE 300

SQL> spool /tmp/sid_kill.sql

SQL> select  'alter system kill session '''||sid||','||serial#||'''immediate ;' from gv$session where type<>'BACKGROUND' and username<>'SYS' and username <> 'DBSNMP' and last_call_et / 60 > 1;

alter system kill session '15,21'immediate ;

alter system kill session '125,63'immediate ;

alter system kill session '138,55'immediate ;

SQL> spool off;

SQL> set pagesize 0 linesize 1000 feedback on verify on trimspool on heading on echo on

SQL> @/tmp/sid_kill.sql

SQL> SQL> select  'alter system kill session '''||sid||','||serial#||'''immediate ;' from gv$session where type<>'BACKGROUND' and username<>'SYS' and username <> 'DBSNMP' and last_call_et / 60 > 1;

SQL> alter system kill session '15,21'immediate ;

System altered.

SQL> alter system kill session '125,63'immediate ;

System altered.

SQL> alter system kill session '138,55'immediate ;

System altered.

SQL> spool off;

SQL> exec dbms_lock.sleep(5);

PL/SQL procedure successfully completed.

SQL> select  sid, serial# from gv$session where type<>'BACKGROUND' and username<>'SYS' and username <> 'DBSNMP' and last_call_et / 60 > 1;

no rows selected

No comments:

Post a Comment

Steps to Rename Host in Oracle RESTART (ASM) in Linux

  oracle@localhost ] asmcmd ASMCMD> lsdg State    Type    Rebal  Sector  Logical_Sector  Block       AU  Total_MB  Free_MB  Req_mir_free_...