вторник, 19 июля 2016 г.

My personal cycling results on veloviewer.com

Activities for Zukus

среда, 22 июня 2016 г.

TEMP tablespace usage history

V$TEMPSEG_USAGE

  1. SELECT username,
  2. session_addr,
  3. session_num,
  4. sqladdr,
  5. sqlhash,
  6. sql_id,
  7. contents,
  8. segtype,
  9. extents,
  10. blocks
  11. FROM v$tempseg_usage
  12. ORDER BY username;

Script to display the recent activity

  1. select distinct
  2. c.username "user",
  3. c.osuser ,
  4. c.sid,
  5. c.serial#,
  6. 'alter system kill session ''' || c.sid || ',' || c.serial# || ''' immediate;' kill_session_cmd,
  7. b.spid "unix_pid",
  8. c.machine,
  9. c.program "program",
  10. a.blocks * e.block_size/1024/1024 mb_temp_used ,
  11. a.tablespace,
  12. d.sql_text
  13. from
  14. v$tempseg_usage a, /* v$sort_usage */
  15. v$process b,
  16. v$session c,
  17. v$sqlarea d,
  18. dba_tablespaces e
  19. where c.saddr=a.session_addr
  20. and b.addr=c.paddr
  21. and a.sqladdr=d.address(+)
  22. and a.tablespace = e.tablespace_name
  23. order by mb_temp_used desc;

TEMP tablespace usage history

A views V$ACTIVE_SESSION_HISTORY and DBA_HIST_ACTIVE_SESS_HISTORY include temp_space_allocated field.
Script below showing last 7 days top 5 SQLs for each day of temp tablespace consumers:
  1. select t.sample_time, t.sql_id, t.temp_mb, t.temp_diff
  2. ,s.sql_text
  3. from (
  4. select --session_id,session_serial#,
  5. --'alter system kill session ''' || session_id || ',' || session_serial# || ''' immediate;' kill_session_cmd,
  6. trunc(sample_time) sample_time,sql_id, sum(temp_mb) temp_mb, sum(temp_diff) temp_diff
  7. , row_number() over (partition by trunc(sample_time) order by sum(temp_mb) desc nulls last) as rn
  8. from (
  9. select sample_time,session_id,session_serial#,sql_id,temp_space_allocated/1024/1024 temp_mb,
  10. temp_space_allocated/1024/1024-lag(temp_space_allocated/1024/1024,1,0) over (order by sample_time) as temp_diff
  11. --from dba_hist_active_sess_history
  12. from v$active_session_history
  13. where 1 = 1
  14. -- session_id=&1
  15. -- and session_serial#=&2
  16. )
  17. group by --session_id,session_serial#,
  18. trunc(sample_time),
  19. sql_id
  20. ) t
  21. left join v$sqlarea s
  22. on s.sql_id = t.sql_id
  23. where 1 = 1
  24. and rn <=5
  25. and sample_time >= trunc(sysdate) - 7
  26. order by sample_time desc, temp_mb desc
To release TEMP space usage before shrinking temporary tablespace use:
  1. select distinct
  2. session_id,session_serial#,
  3. 'alter system kill session ''' || session_id || ',' || session_serial# || ''' immediate;' kill_session_cmd
  4. from v$active_session_history
  5. where 1 = 1
  6. and sql_id='&3'

четверг, 25 февраля 2016 г.

Monitoring the recovery progress of Standard/Standby database using v$recovery_process


Here it is script to track recovery progress of your standard/standby database:
  1. set linesize 255
  2. set pagesize 60
  3. col type format a30
  4. col sofar_formatted format a20
  5. col total_formatted format a15
  6. col comments format a30
  7.  
  8. select to_char(start_time, 'dd-mon-rr hh24:mi:ss') start_time, type, item, units,
  9. sofar,
  10. case units
  11. when 'KB/sec' then round(sofar/1024,2) || ' MB/Sec'
  12. when 'Megabytes' then round(sofar/1024,2) || ' G'
  13. when 'Seconds' then to_char(cast(numtodsinterval(sofar, 'SECOND') as interval day(2) to second(2)), 'DD HH24:MI:SS')
  14. else to_char(sofar)
  15. end sofar_formatted,
  16. total,
  17. case units
  18. when 'KB/sec' then round(total/1024,2) || ' MB/Sec'
  19. when 'Megabytes' then round(total/1024,2) || ' G'
  20. when 'Seconds' then to_char(cast(numtodsinterval(total, 'SECOND') as interval day(2) to second(2)), 'DD HH24:MI:SS')
  21. else to_char(total)
  22. end total_formatted,
  23. comments
  24. from v$recovery_progress;

Output:

  1. set linesize 255
  2. START_TIME TYPE ITEM UNITS SOFAR SOFAR_FORMATTED TOTAL TOTAL_FORMATTED COMMENTS
  3. --------------------------- ------------------------------ -------------------------------- -------------------------------- ---------- -------------------- ---------- --------------- ------------------------------
  4. 11-feb-16 22:50:00 Media Recovery Log Files Files 8 8 8 8
  5. 11-feb-16 22:50:00 Media Recovery Active Apply Rate KB/sec 3316 3.24 MB/Sec 3316 3.24 MB/Sec
  6. 11-feb-16 22:50:00 Media Recovery Average Apply Rate KB/sec 762 .74 MB/Sec 762 .74 MB/Sec
  7. 11-feb-16 22:50:00 Media Recovery Maximum Apply Rate KB/sec 9617 9.39 MB/Sec 9617 9.39 MB/Sec
  8. 11-feb-16 22:50:00 Media Recovery Redo Applied Megabytes 1144 1.12 G 1144 1.12 G
  9. 11-feb-16 22:50:00 Media Recovery Last Applied Redo SCN+Time 0 0 0 0 SCN: 6296684740127
  10. 11-feb-16 22:50:00 Media Recovery Active Time Seconds 214 +00 00:03:34.00 214 +00 00:03:34.00
  11. 11-feb-16 22:50:00 Media Recovery Apply Time per Log Seconds 22 +00 00:00:22.00 22 +00 00:00:22.00
  12. 11-feb-16 22:50:00 Media Recovery Checkpoint Time per Log Seconds 5 +00 00:00:05.00 5 +00 00:00:05.00
  13. 11-feb-16 22:50:00 Media Recovery Elapsed Time Seconds 1537 +00 00:25:37.00 1537 +00 00:25:37.00

References

среда, 20 января 2016 г.

Index Rebuild vs. Coalesce vs. Shrink Space

Index Rebuild vs. Coalesce vs. Shrink Space (Pigs – 3 Different Ones) contains demo Differences between a Coalesce, Shrink Space and Rebuild
  1. ANALYZE INDEX bowie_stuff_i VALIDATE STRUCTURE;
  2.  
  3. SELECT height, blocks, lf_blks, br_blks, del_lf_rows, btree_space, pct_used FROM index_stats;
  4.  
  5. SELECT n.name, s.value FROM v$mystat s, v$statname n
  6. WHERE s.statistic# = n.statistic# AND n.name = 'redo size';
  7.  
  8. ALTER INDEX bowie_stuff_i COALESCE;
  9. -- or
  10. ALTER INDEX bowie_stuff_i SHRINK SPACE COMPACT;
  11. -- or
  12. ALTER INDEX bowie_stuff_i SHRINK SPACE;
  13. -- or
  14. ALTER INDEX bowie_stuff_i REBUILD;
  15. -- or
  16. ALTER INDEX bowie_stuff_i REBUILD ONLINE NOLOGGING;
  17.  
  18. SELECT n.name, s.value FROM v$mystat s, v$statname n
  19. WHERE s.statistic# = n.statistic# AND n.name = 'redo size';
  20.  
  21. ANALYZE INDEX bowie_stuff_i VALIDATE STRUCTURE;
  22.  
  23. SELECT height, blocks, lf_blks, br_blks, del_lf_rows, btree_space, pct_used FROM index_stats;