Sunteți pe pagina 1din 3

Problem - find blocking sessions

Recipie #1 - find blocking sessions with v$session SELECT s.blocking_session, s.sid, s.serial#, s.seconds_in_wait FROM v$session s WHERE blocking_session IS NOT NULL Recipie #2 - find blocking sessions using v$lock SELECT l1.sid || ' is blocking ' || l2.sid blocking_sessions FROM v$lock l1, v$lock l2 WHERE l1.block = 1 AND l2.request > 0 AND l1.id1 = l2.id1 AND l1.id2 = l2.id2 Recipie #3 - blocking sessions with all available information SELECT s1.username || '@' || s1.machine || ' ( SID=' || s1.sid || ' ) is blocking ' || s2.username || '@' || s2.machine || ' ( SID=' || s2.sid || ' ) ' AS blocking_status FROM v$lock l1, v$session s1, v$lock l2, v$session s2 WHERE s1.sid=l1.sid AND s2.sid=l2.sid AND l1.BLOCK=1 AND l2.request > 0 AND l1.id1 = l2.id1 AND l2.id2 = l2.id2 ; Recipie #4 - identifying blocked objects The following queries shows you all the TM locks: SELECT sid, id1 FROM v$lock WHERE TYPE='TM'SID ID1 The ID you get from this query refers to the actual database object which can help you to identify the problem, look at the next query: SELECT object_name FROM dba_objects WHERE object_id=20127 There queries should help you to identify the cause of your blocking sessions! Problem - Finding Oracle Session ID (SID) The current Oracle session ID is often used when you want to analyze data from v$session and similar views. Recipie #1 - Finding the Oracle Session ID There are several ways to get the Oracle session ID, here's the probably most used version: SELECT SYS_CONTEXT('USERENV', 'SID') FROM DUAL; Recipie #2 - combining Session ID and v$session

Here's a simple example showing you how to use the current session ID in combination with v$session: SELECT osuser, program FROM v$session WHERE sid=SYS_CONTEXT('USERENV', 'SID'); Recipe #3 - alternative ways to get session ID just in case you wonder, there are more ways to get the current session ID: SELECT sid FROM v$mystat WHERE ROWNUM = 1; Problem - Finding locked database object SELECT DO.owner, DO.object_name, DO.object_type, lo.session_id, lo.oracle_username FROM dba_objects DO, v$locked_object lo WHERE DO.object_id = lo.object_id Show long running SQL Statements SELECT s.username, sl.sid, sq.executions, sl.last_update_time, sl.sql_id, sl.sql_hash_value, opname, target, elapsed_seconds, time_remaining, sq.sql_fulltext FROM v$session_longops sl INNER JOIN v$sql sq ON sq.sql_id = sl.sql_id INNER JOIN v$session s ON sl.SID = s.SID AND sl.serial# = s.serial# WHERE time_remaining > 0 Get details about long running operations SELECT osuser, sl.sql_id, sl.sql_hash_value, opname, target, elapsed_seconds, time_remaining FROM v$session_longops sl inner join v$session s ON sl.SID = s.SID AND sl.SERIAL# = s.SERIAL# WHERE time_remaining > 0

Determine Database Uptime Recipe #1 - Query v_$instance to get the uptime

SELECT host_name, instance_name, TO_CHAR(startup_time, 'DD-MM-YYYY HH24:MI:SS') startup_time, FLOOR(sysdate-startup_time) days FROM sys.v_$instance;This query will return some additional information like the host and database instance name as well as the number of days the database is running in the last column. Recipe #2 - Query v$session to get database uptime You'll often see articles telling you to query the session with SID 1, but this won't work everywhere. The following query seems to be more reliable, it checks the process with the name PMON, which is part of the database and reads its logon time: SELECT TO_CHAR(logon_time, 'DD-MM-YYYY HH24:MI:SS') FROM v$session WHERE program LIKE '%PMON%'

S-ar putea să vă placă și