Beruflich Dokumente
Kultur Dokumente
Gather statistics for your objects with the ANALYZE statement or the DBM
S_STATS package
You can add information to this view about application-specific long-running ope
rations by using the DBMS_APPLICATION_INFO.SET_SESSION_LONGOPS procedure.
ACTIVE SQL
set lines 200 pages 200
col SQL_TEXT for a77
select S.USERNAME, s.sid, s.osuser, sql_text
from v$sqltext_with_newlines t,V$SESSION s
where t.address =s.sql_address
and t.hash_value = s.sql_hash_value
and s.status = 'ACTIVE'
and s.username <> 'SYSTEM'
--AND USERNAME='&USERNAME'
order by s.sid,t.piece;
Find Long Operations (e.g. full table scans, RMAN, Insert, Import)
select substr(sql_text,instr(sql_text,'INTO "'),30) table_name,
rows_processed,
round((sysdate-to_date(first_load_time,'yyyy-mm-dd hh24:mi:ss'))*24*60,
1) Minutes,
trunc(rows_processed/((sysdate-to_date(first_load_time,'yyyy-mm-dd hh24
:mi:ss'))*24*60)) Rows_Per_Minute
from sys.v_$sqlarea
where sql_text like 'INSERT %INTO "%'
and command_type = 2
and open_versions > 0;
OR
set lines 200 pages 200
col username format a20
col message format a70
--col remaining format 9999
select
username||'-'||sid||','||SERIAL# username
,
to_char(start_time, 'hh24:mi:ss dd/mm/yy') started
,
time_remaining remaining_Sce
,
ELAPSED_SECONDS
,
round((sofar/totalwork)* 100,2) "COMPLETE%"
,
message
from
v$session_longops
where
time_remaining <> 0
--and TARGET like '%&USERNAME.%'
order by time_remaining desc;
Check Time Remaining Of Export/Import
SELECT table_name
,rows_processed
,Minutes,Rows_Per_Minute
,(1/Rows_Per_Minute)*(147515763-rows_processed) Time_Remaining_Min From
(select substr(sql_text,instr(sql_text,'INTO "'),30) table_name,
rows_processed,
round((sysdate-to_date(first_load_time,'yyyy-mm-dd hh24:mi:ss'))*24*60,1) M
inutes,
trunc(rows_processed/((sysdate-to_date(first_load_time,'yyyy-mm-dd hh24:mi:
ss'))*24*60)) Rows_Per_Minute
from
sys.v_$sqlarea
where
sql_text like 'INSERT %INTO "%'
and
command_type = 2
and
open_versions > 0);
Monitor Index Creation
col sid format 9999
col start_time format a5 heading "Start|time"
col elapsed format 9999 heading "Mins|past"
col min_remaining format 9999 heading "Mins|left"
col message format a81
select sid
, to_char(start_time,'hh24:mi') start_time
, elapsed_seconds/60 elapsed
, round(time_remaining/60,2) "min_remaining"
, message
from v$session_longops where time_remaining > 0
AND MESSAGE like '%&TABLE_NAME.%';
--AND MESSAGE like '%&USWENAME.TABLE_NAME.%';
Queries currently running for more than 60 seconds (For Procedure & Package)
select s.username,s.sid,s.serial#,s.last_call_et/60 mins_running,q.sql_text from
v$session s
join v$sqltext_with_newlines q
on s.sql_address = q.address
where status='ACTIVE'
and type <>'BACKGROUND'
and last_call_et> 60
order by sid,serial#,q.piece;
Oracle Locks
select
object_name,
object_type,
session_id,
type,
-- Type or system/user lock
lmode,
-- lock mode in which session holds lock
request,
block,
ctime
-- Time since current mode was granted
from
v$locked_object, all_objects, v$lock
where
v$locked_object.object_id = all_objects.object_id AND
v$lock.id1 = all_objects.object_id AND
v$lock.sid = v$locked_object.session_id
order by
session_id, ctime desc, object_name
/
OR
select OWNER,TABLE_NAME,ROW_SIZE_KB,BLOCK_SIZE_KB,(ROW_SIZE_KB*BLOCKS)/1024 Tot_
size_MB
from
(
select OWNER,TABLE_NAME, ROUND((AVG_ROW_LEN * NUM_ROWS / 1024), 2) ROW_SIZE_
KB, (BLOCKS * 8) BLOCK_SIZE_KB,BLOCKS
from DBA_TABLES
where OWNER not in ('SYS','SYSTEM','ORDSYS','DBSNMP','CTXSYS','XDB','OLAPSYS
','WMSYS','WKSYS','MDSYS','EXFSYS','SYSMAN')
)
Where ROW_SIZE_KB <> 0
and (ROW_SIZE_KB*BLOCKS)/1024 > 10
order by OWNER,TABLE_NAME;
BLOB column Size
select a.*,round(dbms_lob.getlength(a.bin)/1024,2) "Blob_Size_KB" from OWNER.BLO
B_TABLE_NAME a where rownum < 20;
select round(sum(dbms_lob.getlength(bin))/(1024*1024),2) "All_Blob_Size_MB" from
OWNER.BLOB_TABLE_NAME;
Query to get data file name of a given table (Output depends on Size of the Tabl
e)
column FILE_NAME for a60
select file_name, round( bytes/1024/1024 ) mbytes, round( ratio_to_report(bytes)
over () * 100, 2 ) pct
from (
select sum(a.bytes) bytes, b.file_name
from dba_extents a, dba_data_files b
where a.owner = 'RMAN'
and a.segment_name = 'DB'
and a.segment_type = 'TABLE'
and a.file_id = b.file_id
group by b.file_name
)
order by file_name;
Last DML Of the TABLE
select TABLE_OWNER,TABLE_NAME,INSERTS,UPDATES,DELETES,to_char(TIMESTAMP,'dd-Monyyyy hh24:mi:ss') TIMESTAMP,TRUNCATED,DROP_SEGMENTS
from DBA_TAB_MODIFICATIONS
where TABLE_OWNER in ('SCXDOWNLOAD')
and TABLE_NAME ='HISMES0';
Use below processes:STEP
STEP
STEP
STEP
STEP
1:2:3:4:5:-
select owner,segment_name,object_type,total_physical_reads
from ( select owner,object_name as segment_name,object_type,
value as total_physical_reads
from v$segment_statistics
where statistic_name in ('physical reads')
And OBJECT_TYPE = 'TABLE'
Table Access
-- And OBJECT_TYPE = 'INDEX'
Index Access
And OWNER in ('ERMOWNER','INSIGHT','SNAPMGR')
order by total_physical_reads desc)
where rownum <11;
-- Top 10
-- Top 10
LOGICAL_READS
Once a physical I/O has taken place and the block has been read into the memory,
the next request for the same data block won t require the block to be fetched fr
om the disk and hence avoiding a physical I/O. So now to return the results for
the select query requesting the same data block, the block will be fetched from
the memory and is called a Logical I/O.
Whenever the quantum of Logical I/O is calculated, two kinds of reads are consid
ered - Consistent reads and Current reads. Jointly, these 2 statistics are known
as Logical I/O performed by Oracle.
Let us look at these separately to better understand the concept of Logical I/O.
See More : http://www.dba-oracle.com/t_oracle_logical_io_physical_io.htm
col segment_name format a30
col owner format a30
select owner,segment_name,object_type,total_logical_reads
from ( select owner,object_name as segment_name,object_type,
value as total_logical_reads
from v$segment_statistics
where statistic_name in ('logical reads')
And OBJECT_TYPE = 'TABLE'
Table Access
-- And OBJECT_TYPE = 'INDEX'
Index Access
And OWNER in ('ERMOWNER','INSIGHT','SNAPMGR')
order by total_logical_reads desc)
where rownum <11;
-- Top 10
-- Top 10
--where TABLESPACE_NAME='VWSE_DATA'
--Where AUTOEXTENSIBLE ='YES' -- in ('DST_ADMIN_DATA','DST_ADMIN_INDEX')
Order by TABLESPACE_NAME,FILE_ID;
Identify Max/Min Size Of DataFile In Tablespace
col FILE_NAME for a50
col ID for 9999
col TABLESPACE_NAME for a20
select TO_CHAR(FILE_ID,99) ID
,FILE_NAME,TABLESPACE_NAME,Tot_Gb,AUTOEXTENSIBLE
,INCREMENT_BY,Max_Gb,Usr_Mb
,DECODE(Min_File_Size,1,'Min Size DataFile','Max Size DataFile') "File_Desc"
from (
select FILE_ID,FILE_NAME,TABLESPACE_NAME,BYTES/1073741824 Tot_Gb, AUTOEXTENSIBLE
,INCREMENT_BY,
MAXBYTES/1073741824 Max_Gb,USER_BYTES/1048576 Usr_Mb
,ROW_NUMBER () OVER(PARTITION BY TABLESPACE_NAME ORDER BY BYTES) Min_File_Size
,ROW_NUMBER () OVER(PARTITION BY TABLESPACE_NAME ORDER BY BYTES Desc) Max_File_S
ize
from dba_data_files
--WHERE TABLESPACE_NAME in ('DATA','INDEX','EX_DATA'))
WHERE Min_File_Size = 1
-- Enable To Sele
ct Minimun Size Of Datafile
--WHERE Max_File_Size=1
-- Enable To Select
Maximun Size Of Datafile
ORDER BY TABLESPACE_NAME;
Tablespace & Datafile Creation Time
SET LINE 150 pages 200
col FileNo for 99999
col "Tablespace Name" for a20
col "Datafile Name" for a50
col "DataFile Size" for a13
col "Size In MB" noprint
BREAK ON "Tablespace_Created"
TTITLE CENTER 'T A B L E S P A C E A N D D A T A F I L E C R E A T I O N T I
M E' SKIP 1 CENTER ============================================================
========= SKIP 1
SELECT FILE# FileNo,b.NAME "Tablespace Name"
,to_char(c.Tblsp_Creation_Time,'ddth-Mon-YY hh24:mi') "Tablespace_Created",
a.NAME "Datafile Name"
, TO_CHAR(CREATION_TIME,'ddth-Mon-YY hh24:mi') "Datafile_Created"
, BYTES/1024/1024 "Size In MB",
decode(sign(length(BYTES)-10),-1,lpad(BYTES/1024/1024,3)||' MB'
,lpad(BYTES/1024/1024/1024,3)||' GB') "DataFile Size",
STATUS,ENABLED
from v$datafile a, v$tablespace b,
(select b.NAME Tablespace
,min(CREATION_TIME) Tblsp_Creation_Time from v$datafile a
,v$tablespace b where a.TS#=b.TS# group by b.NAME) c
WHERE a.TS#=b.TS#
AND b.NAME=c.Tablespace
order by b.NAME,CREATION_TIME;
clear breaks;
Data File Status And Creation Time
of
of
of
of
rows_processed
executions
avg_cost
etime_per_exec
on report
on report
on report
on report
compute
compute
compute
compute
avg
avg
avg
avg
of
of
of
of
ctime_per_exec
gets_per_exec
reads_per_exec
row_per_exec
on report
on report
on report
on report
PROMPT
PROMPT Top 10 most expensive SQL (Elapsed Time (secs) )...
PROMPT
select rownum as rank, a.*
from (
select elapsed_Time/1000000 elapsed_time,
executions,
buffer_gets,
disk_reads,
cpu_time
hash_value,
sql_text
from v$sqlarea
where elapsed_time/1000000 > 5
order by elapsed_time desc) a
where rownum < 11
/
PROMPT
PROMPT Top 10 most expensive SQL (Elapsed Time (secs) Per Exec )...
PROMPT
select rownum as rank, a.*
from (
select elapsed_Time/1000000 elapsed_time,
executions,
elapsed_Time / (1000000 * decode(executions,0,1, executions) ) etime_per_exec,
buffer_gets,
disk_reads,
cpu_time
hash_value,
sql_text
from v$sqlarea
where elapsed_time/1000000 > 5
order by etime_per_exec desc) a
where rownum < 11
/
PROMPT
PROMPT Top 10 most expensive SQL (CPU Time (secs) )...
PROMPT
col SQL_TEXT for a99
select rownum as rank, a.*
from (
select cpu_time/1000000 cpu_time,
executions,
buffer_gets,
disk_reads,
cpu_time
hash_value,
sql_text
from v$sqlarea
where cpu_time/1000000 > 5
order by cpu_time desc) a
where rownum < 11
/
PROMPT
PROMPT Top 10 most expensive SQL (CPU Time (secs) per Exec)...
PROMPT
select rownum as rank, a.*
from (
select cpu_time/1000000 cpu_time,
executions,
cpu_time / (1000000 * decode(executions,0,1, executions)) ctime_per_exec,
buffer_gets,
disk_reads,
cpu_time
hash_value,
sql_text
from v$sqlarea
where cpu_time/1000000 > 5
order by ctime_per_exec desc) a
where rownum < 11
/
PROMPT
PROMPT Top 10 most expensive SQL (Buffer Gets)...
PROMPT
select rownum as rank, a.*
from (
select buffer_gets,
executions,
buffer_gets/ decode(executions,0,1, executions) gets_per_exec,
hash_value,
sql_text
from v$sqlarea
where buffer_gets > 50000
order by buffer_gets desc) a
where rownum < 11
/
PROMPT
PROMPT Top 10 most expensive SQL (Buffer Gets by Executions)...
PROMPT
select rownum as rank, a.*
from (
select buffer_gets,
executions,
buffer_gets/ decode(executions,0,1, executions) gets_per_exec,
hash_value,
sql_text
from v$sqlarea
where buffer_gets > 50000
order by gets_per_exec desc) a
where rownum < 11
/
PROMPT
PROMPT Top 10 most expensive SQL (Physical Reads)...
PROMPT
select rownum as rank, a.*
from (
select disk_reads,
executions,
rem
rem This May be a candidate application for using the init.ora parameter
rem CURSOR_SHARING = FORCE|SIMILAR
select rownum as rank, a.*
from (
select
upper(substr(sql_text, 1, 65)) sqltext, count(*)
from
v$sqlarea
group by upper(substr(sql_text, 1, 65))
having count(*) > 1
order by count(*) desc) a
where rownum < 11
/
prompt Output spooled to sqlarea.lst
spool off