Skip to content
pvmehta.com

pvmehta.com

  • Home
  • About Me
  • Toggle search form
  • changing kernel parameter in Oracle Enterpise Linux Linux/Unix
  • Unix split command to split files Linux/Unix
  • crontab syntax Linux/Unix
  • Sort with ASCII order and Numeric Order Linux/Unix
  • online_bkup.sql Oracle
  • To seee semaphores and shared memory segments in Solaris Linux/Unix
  • proper cpu stats Linux/Unix
  • Oracle Metalink useful notes Oracle
  • pvm_metric.sql for gathering report from vmstat tables Oracle
  • Oracle Material from OTN Oracle
  • For Search and replace unix command. Linux/Unix
  • Rman Notes -1 Oracle
  • Library cahe Latches and internal explaination Oracle
  • Nice Article about semaphores and init.ora Processes parameter relations Linux/Unix
  • How to hide author name in WordPress BLOG PHP/MYSQL/Wordpress

Find long Running Transaction

Posted on 28-Jul-2008 By Admin No Comments on Find long Running Transaction

+++++++++++++longtx_12HR.sh

#!/bin/sh

. /opt/app/oracle/oracle_env

NOTIFY_LIST=dbaoracle@1800flowers.com

$ORACLE_HOME/bin/sqlplus -s “/ as sysdba” @/opt/app/oracle/scripts/longtx_12HR.sql

if [ `cat /opt/app/oracle/scripts/log/long_transaction_list.lst | grep -i “*****ATLAS NOTIFICATION REQUIRED*****” | wc -l` -n

e 0 ]; then

mailx -s “LONG RUNNING TRANSACTION ON ATLAS `hostname` on `date` ” $NOTIFY_LIST < /opt/app/oracle/scripts/log/long_transactio
n_list.lst

fi

+++++++++++++longtx_12HR.sql

set lines 120 pages 300

set serveroutput on

exec dbms_output.enable(NULL);

set echo off

spool /opt/app/oracle/scripts/log/long_transaction_list.lst

declare

cursor c1 is

select a.sid, a.serial#, substr(a.machine,1,22) machine, substr(a.osuser,1,15) osuser,

substr(a.username,1,22) username, a.sql_hash_value, a.sql_address, a.prev_hash_value,

a.prev_sql_addr, round((sysdate – to_date(b.start_time, ‘MM/DD/YY HH24:MI:SS’)) * 24, 2 ) hours1,

a.status sess_status, b.status tx_status

from v$session a , v$transaction b

where a.SADDR = b.SES_ADDR

and (sysdate – to_date(b.start_time, ‘MM/DD/YY HH24:MI:SS’)) * 24 > 12

order by (sysdate – to_date(b.start_time, ‘MM/DD/YY HH24:MI:SS’)) * 24;

last_sqltext varchar2(4000);

count1 number := 0;

begin

for cur in c1 loop

if (c1%rowcount = 1) then

dbms_output.put_line(‘=============================================================================’);

dbms_output.put_line(‘ LONG RUNNING TRANSACTION REPORT ‘);

dbms_output.put_line(‘ List of tranactions running for more than 12 Hours ‘);

dbms_output.put_line(‘ Script: longtx_12HR.sql ‘);

dbms_output.put_line(‘=============================================================================’);

end if;

count1 := count1 + 1;

dbms_output.put_line(‘Transactin# ‘ || count1 || ‘ Running for last ‘ || cur.hours1 || ‘ hours’);

dbms_output.put_line(‘SID=’||cur.sid ||’ ‘|| ‘SERIAL#=’ || cur.serial# || ‘ ‘ || ‘MACHINE=’ || cur.machine );

dbms_output.put_line(‘OSUSER=’|| cur.osuser || ‘ USERNAME=’ || cur.username || ‘ SESSION_STATUS=’||cur.sess_status || ‘ ‘ |

| ‘TX_STATUS=’ || cur.tx_status );

begin

select substr(sql_text, 1, 255) into last_sqltext

from v$sql

where hash_value = cur.sql_hash_value

and address = cur.sql_address

and rownum = 1;

exception

when no_data_found then

begin

select substr(sql_text,1,255) into last_sqltext

from v$sql

where hash_value = cur.prev_hash_value

and address = cur.prev_sql_addr

and rownum = 1;

exception

when no_data_found then last_sqltext := null;

end;

end;

dbms_output.put_line(last_sqltext);

dbms_output.put_line(‘——————————————————-‘);

end loop;

if count1 != 0 then

dbms_output.put_line(‘*****ATLAS NOTIFICATION REQUIRED*****’);

end if;

end;

/

spool off

exit

Linux/Unix, shell

Post navigation

Previous Post: Check_recovery.sh program to run sqlplus and return its values remotely.
Next Post: checking connectivity between two servers

Related Posts

  • remove archfiles only when it is applied to DR rm_archfiles.sh Linux/Unix
  • CPU speed on Linux Linux/Unix
  • To find all disk io ( EMC as well as local) Linux/Unix
  • Implementation of key based authentications Linux/Unix
  • Establishing trusted relationship between dbmonitor( central monitoring) and monitoring targets. Linux/Unix
  • Check_recovery.sh program to run sqlplus and return its values remotely. Linux/Unix

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
  • ORA-1841 Error Connecting to Upgraded Database After Set PASSWORD_LIFE_TIME Oracle
  • lck.sql Oracle
  • This is from Temi Oracle
  • CPU speed on solaris Linux/Unix
  • find_log_switch.sql Find log switches in graphical manner Oracle
  • ORA-00064: object is too large to allocate on this O/S during startup Oracle
  • Transfer SQL Profiles from One database to other database. Oracle
  • Passing from Unix to PLSQL using bind variables Linux/Unix

Copyright © 2025 pvmehta.com.

Powered by PressBook News WordPress theme