Skip to content
pvmehta.com

pvmehta.com

  • Home
  • About Me
  • Toggle search form
  • Histogram Overview Oracle
  • New OFA for 11g Oracle
  • Rollback force for distributed transactions Oracle
  • Debugging Shell FIles Linux/Unix
  • move_arch_files.ksh Linux/Unix
  • To find explain plan for a statement that occurred in past. Oracle
  • Benefits and Usage of RMAN with Standby Databases Oracle
  • Good links for x$ tables in oracle. Oracle
  • How to analyze statspack or AWR report. Oracle
  • Restoring a user’s original password 1051962.101 Oracle
  • run this before doing any dbchange pvm_pre_change.sql Oracle
  • How to Make Trace Files Created by Oracle Readable by All Users ? Oracle
  • configUOCIOTTO.ora Oracle
  • Removing Blank lines from file using grep Linux/Unix
  • How to Use DBMS_STATS to Move Statistics to a Different Database Oracle

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

  • rm_backup_arch_file.ksh Linux/Unix
  • scp with ssh2 Linux/Unix
  • age_alert.ksh aging out alert.log Linux/Unix
  • Paste command syntax Linux/Unix
  • How to know Number of CPUs on Sun Box Linux/Unix
  • move_arch_files.ksh Linux/Unix

Leave a Reply Cancel reply

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

Categories

  • AWS (2)
  • Azure (1)
  • Linux/Unix (149)
  • Oracle (388)
  • PHP/MYSQL/Wordpress (10)
  • Power-BI (0)
  • Python/PySpark (7)
  • RAC (17)
  • rman-dataguard (26)
  • shell (149)
  • SQL scripts (337)
  • Uncategorized (0)
  • Videos (0)

Recent Posts

  • findinfo.sql (SQL for getting CPU and Active session info)27-May-2025
  • SQL Tracker by SID sqltrackerbysid.sql22-Apr-2025
  • How to connect to Oracle Database with Wallet with Python.21-Mar-2025
  • JSON/XML Types in Oracle18-Mar-2025
  • CPU Core related projections12-Mar-2025
  • Exadata Basics10-Dec-2024
  • Reading config file from other folder inside class24-Sep-2024
  • Python class import from different folders22-Sep-2024
  • Transfer SQL Profiles from One database to other database.05-Sep-2024
  • Load testing on Oracle 19C RAC with HammerDB18-Jan-2024

Archives

  • 2025
  • 2024
  • 2023
  • 2010
  • 2009
  • 2008
  • 2007
  • 2006
  • 2005
  • find_longsql.sql Oracle
  • rm_backup_arch_file.ksh Linux/Unix
  • Adding or Dropping Online Redo Log Files When Physical Standby in place Oracle
  • Oracle Recommended Patches — Oracle Database ID 756671.1 Oracle
  • How does one overcome the Unix 2 Gig file limit? Linux/Unix
  • OEM-troubleshooting on 20-MAY-08 Oracle
  • Running some SQL on multiple databases connecting using monitoring userid and password Linux/Unix
  • chk_space_SID.ksh Linux/Unix

Copyright © 2025 pvmehta.com.

Powered by PressBook News WordPress theme