Skip to content
pvmehta.com

pvmehta.com

  • Home
  • About Me
  • Toggle search form
  • Guide to Linux System Command Mastery Linux/Unix
  • plan10g.sql good Oracle
  • TNSNAMES entries details Oracle
  • replace alphabets using sed Linux/Unix
  • Jai Shree Ram Oracle
  • pvm_metric.sql for gathering report from vmstat tables Oracle
  • chk_space_SID.ksh Linux/Unix
  • Temporary Tablespsace Temp tablespace behaviour Oracle
  • reset Sequence Oracle
  • How to find pinned objects from shared pool. (pinned via dbms_shared_pool.keep) Oracle
  • Reclaim temp tablespace for oracle 8, 8i Oracle
  • cold backup scripts to copy locally Linux/Unix
  • Jai Shree Ram Oracle
  • Recovering lost SYS password Oracle
  • Oracle Identifiers Oracle

GSQ.sql

Posted on 19-May-202325-May-2023 By Admin No Comments on GSQ.sql

This SQL will be used to identify SQL details of given Session. You need to pass SID and INSTANCE_ID as INPUT. This query will provide session details, SQL_ID, SQL_EXEC_START time and other transaction level details.


set echo off feedback off verify off
col Transaction_id format a20
col username format a8
col days format 99.99
col hours1 format 999999
col TX_HRS format 999.9
col USER_HRS format 999.9
col LOCK format a2
column sql_address format a30
column sql_hash_value format 9999999999
column plan_hash_value format 9999999999999
accept v_instid prompt 'Enter Instance ID ->'
accept v_sid prompt 'Enter oracle sid ->'
set lines 168 pages 200
set long 3000
select a.inst_id || ':' || a.sid || ',' || a.serial# sid_info, a.service_name, a.sql_id xsql_id, a.sql_child_number xsql_child_number,
c.plan_hash_value, a.username, a.osuser, a.machine,
a.status sess_status, b.xidusn||'.'||b.xidslot||'.'||b.xidsqn Transaction_id, b.xid,
decode(UBAFIL,0, decode(UBABLK, 0, decode(UBASQN, 0, 'N', 'Y'), 'Y'), 'Y') "LOCK",
c.sql_profile, d.spid "os pid", a.program, a.module, c.sql_fulltext, a.event,
b.start_time "TX Start Time", round((sysdate - to_date(b.start_time, 'MM/DD/YY HH24:MI:SS')) * 24*60,1) "TX_MINS",
to_char(a.logon_time, 'DD-MON-RRRR:HH24:MI') "Logon Time", round((sysdate - a.logon_time) * 24*60,1) "LOGON_MINS",
a.blocking_session||'@'|| a.blocking_instance, a.sql_exec_start,
'alter system kill session ''' || a.sid || ',' || a.serial# || ', @' || a.inst_id || ''';' || chr(10) || lpad('+', 80, '+')
from gv$session a
left outer join gv$transaction b on (a.SADDR = b.SES_ADDR and a.inst_id = b.inst_id)
left outer join gv$sql c on (a.inst_id=c.inst_id and a.sql_id = c.sql_id and a.sql_child_number = c.child_number)
join gv$process d on (a.paddr = d.addr and a.inst_id=d.inst_id)
where a.sid='&v_sid'
and a.inst_id='&v_instid';

Oracle, SQL scripts Tags:data, databases, Get session information, Oracle expert, Oracle wait events, SQL, tuning expert

Post navigation

Previous Post: PHP code to add WordPress posts in bulk programmatically
Next Post: ENQ: KO – FAST OBJECT CHECKPOINT tips

Related Posts

  • Trace a SQL session from another session using ORADEBUG Oracle
  • V$ROLLSTAT status is Full Oracle
  • Very Good Oralce Internal Tuning Book Oracle
  • ORA-8031 issue and solution if it is occuring due to truncate. Oracle
  • Query to Generate aggregate on every 30 mins. Oracle
  • Good Oracle Architecture In Short and point to point 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 (393)
  • PHP/MYSQL/Wordpress (10)
  • POSTGRESQL (0)
  • Power-BI (0)
  • Python/PySpark (7)
  • RAC (17)
  • rman-dataguard (26)
  • shell (149)
  • SQL scripts (342)
  • SQL Server (6)
  • Uncategorized (0)
  • Videos (0)

Recent Posts

  • Trace a SQL session from another session using ORADEBUG30-Sep-2025
  • 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

Archives

  • 2025
  • 2024
  • 2023
  • 2010
  • 2009
  • 2008
  • 2007
  • 2006
  • 2005
  • T-SQL Vs PL/SQL Syntax SQL Server
  • Standby Database Behavior when a Datafile is Resized on the Primary Database Note:123883.1 Oracle
  • Search and replace editor command in vi Linux/Unix
  • SQL Server: How to see current transactions or requests SQL Server
  • block_ident.sql Oracle
  • Oracle Data Direct to TAPE Oracle
  • OEM-troubleshooting on 20-MAY-08 Oracle
  • USER_TABLES.Freelists Oracle

Copyright © 2025 pvmehta.com.

Powered by PressBook News WordPress theme