Skip to content
pvmehta.com

pvmehta.com

  • Home
  • About Me
  • Toggle search form
  • Gathering statistics with DBMS_STATS Oracle
  • RAC 11g with vmware Oracle
  • findinfo.sql (SQL for getting CPU and Active session info) Oracle
  • How to know current SID Oracle
  • How does one overcome the Unix 2 Gig file limit? Linux/Unix
  • cur_sql.sql Oracle
  • setting prompt display with .profile Linux/Unix
  • Find Time Consuming SQL Statements in Oracle 10g Oracle
  • Jai Shree Ram PHP/MYSQL/Wordpress
  • Global Unique Identifier Generation in Oracle 9.2 SYS_GUID() Oracle
  • Kernel Parameters for Solaris Linux/Unix
  • catting.sh Linux/Unix
  • how to find VIP from ifconfig Linux/Unix
  • find_err.sql for finding errors from dba_errors. Oracle
  • DBMS_Shared_pool pinning triggers 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

  • Oracle 11g Environment Setup Oracle
  • logminer and my_lbu Oracle
  • Sample WW22 listener.ora Oracle
  • Rman Notes -1 Oracle
  • Btee and Bitmap Plans in Oracle 9i and higher Oracle
  • Very Good Oralce Internal Tuning Book 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 (393)
  • PHP/MYSQL/Wordpress (10)
  • POSTGRESQL (1)
  • 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

  • Complete Git Tutorial for Beginners25-Dec-2025
  • Postgres DB user and OS user.25-Dec-2025
  • 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

Archives

  • 2025
  • 2024
  • 2023
  • 2010
  • 2009
  • 2008
  • 2007
  • 2006
  • 2005
  • SQL Server: How to see historical transactions SQL Server
  • Jai Shree Ram Oracle
  • compile_inv.sql Oracle
  • default permission on ~/.ssh/authorized_keys2 or authorized_keys Linux/Unix
  • Temporary Tablespsace Temp tablespace behaviour Oracle
  • 276434.1 Modifying the VIP or VIP Hostname of a 10g or 11g Oracle Clusterware Node Oracle
  • alter database backup controlfile to trace Oracle
  • Rownum with Order by Oracle

Copyright © 2026 pvmehta.com.

Powered by PressBook News WordPress theme