2026-05-01 07:25:46

This commit is contained in:
2026-05-01 09:25:48 +02:00
parent ea39d398ae
commit b2358a2f1b
60 changed files with 5675 additions and 4109 deletions
+130 -131
View File
@@ -1,131 +1,130 @@
set term off
/*
*
* Author : Vishal Gupta
* Purpose : Display hourly and daily redolog switches by size
* Parameters : None
*
* Revision History:
* ===================
* Date Author Description
* --------- ------------ -----------------------------------------
* 30-Dec-14 Vishal Gupta Added number of days as input parameter
* 18-Mar-14 Vishal Gupta Added separator columns for daily total
* 27-Feb-12 Vishal Gupta Formated the output and parameterized size granuality
* 05-Aug-04 Vishal Gupta First Draft
*
*/
set term on
/************************************
* INPUT PARAMETERS
************************************/
UNDEFINE days
DEFINE days="&&1"
set term off
COLUMN _DAYS NEW_VALUE DAYS NOPRINT
SELECT UPPER(DECODE('&&days','','15','&&days')) "_DAYS"
FROM DUAL;
set term on
/************************************
* CONFIGURATION PARAMETERS
************************************/
DEFINE size_label=GB
DEFINE size_divider="1024/1024/1024"
DEFINE round_precision=2
PROMPT
PROMPT ************************************************************************
PROMPT * A R C H I V E L O G S W I T C H S U M M A R Y (By Size)
PROMPT * (Hourly and Daily figures in &&size_label)
PROMPT *
PROMPT * Input Parameters
PROMPT * - Days = '&&days'
PROMPT ************************************************************************
PROMPT
PROMPT - <-------------------------------------------------------- hourly total ----------------------------------------------->
/*
Total h0 h1 h2 h3 h4 h5 h6 h7 h8 h9 h10 h11 h12 h13 h14 h15 h16 h17 h18 h19 h20 h21 h22 h23
Date Day (GB) (GB) (GB) (GB) (GB) (GB) (GB) (GB) (GB) (GB) (GB) (GB) (GB) (GB) (GB) (GB) (GB) (GB) (GB) (GB) (GB) (GB) (GB) (GB) (GB)
--------- --- ----- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
*/
SET head on FEED off ECHO OFF LINES 1000 TRIMSPOOL ON TRIM on PAGES 1000
COLUMN separator HEADING "!|!|!" FORMAT A1
COLUMN "Date" HEADING "Date" FORMAT A9
COLUMN "Total" HEADING "Day|Total|(&size_label)" FORMAT 99999
COLUMN "Day" HEADING "Day" FORMAT A3
COLUMN h0 HEADING "h0|(&size_label)" FORMAT 9999
COLUMN h1 HEADING "h1|(&size_label)" FORMAT 9999
COLUMN h2 HEADING "h2|(&size_label)" FORMAT 9999
COLUMN h3 HEADING "h3|(&size_label)" FORMAT 9999
COLUMN h4 HEADING "h4|(&size_label)" FORMAT 9999
COLUMN h5 HEADING "h5|(&size_label)" FORMAT 9999
COLUMN h6 HEADING "h6|(&size_label)" FORMAT 9999
COLUMN h7 HEADING "h7|(&size_label)" FORMAT 9999
COLUMN h8 HEADING "h8|(&size_label)" FORMAT 9999
COLUMN h9 HEADING "h9|(&size_label)" FORMAT 9999
COLUMN h10 HEADING "h10|(&size_label)" FORMAT 9999
COLUMN h11 HEADING "h11|(&size_label)" FORMAT 9999
COLUMN h12 HEADING "h12|(&size_label)" FORMAT 9999
COLUMN h13 HEADING "h13|(&size_label)" FORMAT 9999
COLUMN h14 HEADING "h14|(&size_label)" FORMAT 9999
COLUMN h15 HEADING "h15|(&size_label)" FORMAT 9999
COLUMN h16 HEADING "h16|(&size_label)" FORMAT 9999
COLUMN h17 HEADING "h17|(&size_label)" FORMAT 9999
COLUMN h18 HEADING "h18|(&size_label)" FORMAT 9999
COLUMN h19 HEADING "h19|(&size_label)" FORMAT 9999
COLUMN h20 HEADING "h20|(&size_label)" FORMAT 9999
COLUMN h21 HEADING "h21|(&size_label)" FORMAT 9999
COLUMN h22 HEADING "h22|(&size_label)" FORMAT 9999
COLUMN h23 HEADING "h23|(&size_label)" FORMAT 9999
SELECT to_char(trunc(COMPLETION_TIME),'DD-Mon-YY') "Date",
to_char(COMPLETION_TIME, 'Dy') "Day",
'|' separator,
ROUND(SUM(((BLOCKS * BLOCK_SIZE)/&size_divider))) "Total",
'|' separator,
ROUND(SUM(decode(to_char(COMPLETION_TIME, 'hh24'),'00',(BLOCKS * BLOCK_SIZE)/&size_divider,0))) "h0",
ROUND(SUM(decode(to_char(COMPLETION_TIME, 'hh24'),'01',(BLOCKS * BLOCK_SIZE)/&size_divider,0))) "h1",
ROUND(SUM(decode(to_char(COMPLETION_TIME, 'hh24'),'02',(BLOCKS * BLOCK_SIZE)/&size_divider,0))) "h2",
ROUND(SUM(decode(to_char(COMPLETION_TIME, 'hh24'),'03',(BLOCKS * BLOCK_SIZE)/&size_divider,0))) "h3",
ROUND(SUM(decode(to_char(COMPLETION_TIME, 'hh24'),'04',(BLOCKS * BLOCK_SIZE)/&size_divider,0))) "h4",
ROUND(SUM(decode(to_char(COMPLETION_TIME, 'hh24'),'05',(BLOCKS * BLOCK_SIZE)/&size_divider,0))) "h5",
ROUND(SUM(decode(to_char(COMPLETION_TIME, 'hh24'),'06',(BLOCKS * BLOCK_SIZE)/&size_divider,0))) "h6",
ROUND(SUM(decode(to_char(COMPLETION_TIME, 'hh24'),'07',(BLOCKS * BLOCK_SIZE)/&size_divider,0))) "h7",
ROUND(SUM(decode(to_char(COMPLETION_TIME, 'hh24'),'08',(BLOCKS * BLOCK_SIZE)/&size_divider,0))) "h8",
ROUND(SUM(decode(to_char(COMPLETION_TIME, 'hh24'),'09',(BLOCKS * BLOCK_SIZE)/&size_divider,0))) "h9",
ROUND(SUM(decode(to_char(COMPLETION_TIME, 'hh24'),'10',(BLOCKS * BLOCK_SIZE)/&size_divider,0))) "h10",
ROUND(SUM(decode(to_char(COMPLETION_TIME, 'hh24'),'11',(BLOCKS * BLOCK_SIZE)/&size_divider,0))) "h11",
ROUND(SUM(decode(to_char(COMPLETION_TIME, 'hh24'),'12',(BLOCKS * BLOCK_SIZE)/&size_divider,0))) "h12",
ROUND(SUM(decode(to_char(COMPLETION_TIME, 'hh24'),'13',(BLOCKS * BLOCK_SIZE)/&size_divider,0))) "h13",
ROUND(SUM(decode(to_char(COMPLETION_TIME, 'hh24'),'14',(BLOCKS * BLOCK_SIZE)/&size_divider,0))) "h14",
ROUND(SUM(decode(to_char(COMPLETION_TIME, 'hh24'),'15',(BLOCKS * BLOCK_SIZE)/&size_divider,0))) "h15",
ROUND(SUM(decode(to_char(COMPLETION_TIME, 'hh24'),'16',(BLOCKS * BLOCK_SIZE)/&size_divider,0))) "h16",
ROUND(SUM(decode(to_char(COMPLETION_TIME, 'hh24'),'17',(BLOCKS * BLOCK_SIZE)/&size_divider,0))) "h17",
ROUND(SUM(decode(to_char(COMPLETION_TIME, 'hh24'),'18',(BLOCKS * BLOCK_SIZE)/&size_divider,0))) "h18",
ROUND(SUM(decode(to_char(COMPLETION_TIME, 'hh24'),'19',(BLOCKS * BLOCK_SIZE)/&size_divider,0))) "h19",
ROUND(SUM(decode(to_char(COMPLETION_TIME, 'hh24'),'20',(BLOCKS * BLOCK_SIZE)/&size_divider,0))) "h20",
ROUND(SUM(decode(to_char(COMPLETION_TIME, 'hh24'),'21',(BLOCKS * BLOCK_SIZE)/&size_divider,0))) "h21",
ROUND(SUM(decode(to_char(COMPLETION_TIME, 'hh24'),'22',(BLOCKS * BLOCK_SIZE)/&size_divider,0))) "h22",
ROUND(SUM(decode(to_char(COMPLETION_TIME, 'hh24'),'23',(BLOCKS * BLOCK_SIZE)/&size_divider,0))) "h23"
from v$archived_log
where standby_dest = 'NO'
AND CREATOR IN ('ARCH' , 'FGRD','LGWR','RFS')
AND completion_time > sysdate - &days
group by trunc(COMPLETION_TIME), to_char(COMPLETION_TIME, 'Dy')
order by trunc(COMPLETION_TIME)
/
set term off
/*
*
* Author : Vishal Gupta
* Purpose : Display hourly and daily redolog switches by size
* Parameters : None
*
* Revision History:
* ===================
* Date Author Description
* --------- ------------ -----------------------------------------
* 30-Dec-14 Vishal Gupta Added number of days as input parameter
* 18-Mar-14 Vishal Gupta Added separator columns for daily total
* 27-Feb-12 Vishal Gupta Formated the output and parameterized size granuality
* 05-Aug-04 Vishal Gupta First Draft
*
*/
set term on
/************************************
* INPUT PARAMETERS
************************************/
UNDEFINE days
DEFINE days="&&1"
set term off
COLUMN _DAYS NEW_VALUE DAYS NOPRINT
SELECT UPPER(DECODE('&&days','','15','&&days')) "_DAYS"
FROM DUAL;
set term on
/************************************
* CONFIGURATION PARAMETERS
************************************/
DEFINE size_label=GB
DEFINE size_divider="1024/1024/1024"
DEFINE round_precision=2
PROMPT
PROMPT ************************************************************************
PROMPT * A R C H I V E L O G S W I T C H S U M M A R Y (By Size)
PROMPT * (Hourly and Daily figures in &&size_label)
PROMPT *
PROMPT * Input Parameters
PROMPT * - Days = '&&days'
PROMPT ************************************************************************
PROMPT
PROMPT - <-------------------------------------------------------- hourly total ----------------------------------------------->
/*
Total h0 h1 h2 h3 h4 h5 h6 h7 h8 h9 h10 h11 h12 h13 h14 h15 h16 h17 h18 h19 h20 h21 h22 h23
Date Day (GB) (GB) (GB) (GB) (GB) (GB) (GB) (GB) (GB) (GB) (GB) (GB) (GB) (GB) (GB) (GB) (GB) (GB) (GB) (GB) (GB) (GB) (GB) (GB) (GB)
--------- --- ----- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
*/
SET head on FEED off ECHO OFF LINES 1000 TRIMSPOOL ON TRIM on PAGES 1000
COLUMN separator HEADING "!|!|!" FORMAT A1
COLUMN "Date" HEADING "Date" FORMAT A9
COLUMN "Total" HEADING "Day|Total|(&size_label)" FORMAT 99999
COLUMN "Day" HEADING "Day" FORMAT A3
COLUMN h0 HEADING "h0|(&size_label)" FORMAT 9999
COLUMN h1 HEADING "h1|(&size_label)" FORMAT 9999
COLUMN h2 HEADING "h2|(&size_label)" FORMAT 9999
COLUMN h3 HEADING "h3|(&size_label)" FORMAT 9999
COLUMN h4 HEADING "h4|(&size_label)" FORMAT 9999
COLUMN h5 HEADING "h5|(&size_label)" FORMAT 9999
COLUMN h6 HEADING "h6|(&size_label)" FORMAT 9999
COLUMN h7 HEADING "h7|(&size_label)" FORMAT 9999
COLUMN h8 HEADING "h8|(&size_label)" FORMAT 9999
COLUMN h9 HEADING "h9|(&size_label)" FORMAT 9999
COLUMN h10 HEADING "h10|(&size_label)" FORMAT 9999
COLUMN h11 HEADING "h11|(&size_label)" FORMAT 9999
COLUMN h12 HEADING "h12|(&size_label)" FORMAT 9999
COLUMN h13 HEADING "h13|(&size_label)" FORMAT 9999
COLUMN h14 HEADING "h14|(&size_label)" FORMAT 9999
COLUMN h15 HEADING "h15|(&size_label)" FORMAT 9999
COLUMN h16 HEADING "h16|(&size_label)" FORMAT 9999
COLUMN h17 HEADING "h17|(&size_label)" FORMAT 9999
COLUMN h18 HEADING "h18|(&size_label)" FORMAT 9999
COLUMN h19 HEADING "h19|(&size_label)" FORMAT 9999
COLUMN h20 HEADING "h20|(&size_label)" FORMAT 9999
COLUMN h21 HEADING "h21|(&size_label)" FORMAT 9999
COLUMN h22 HEADING "h22|(&size_label)" FORMAT 9999
COLUMN h23 HEADING "h23|(&size_label)" FORMAT 9999
SELECT to_char(trunc(COMPLETION_TIME),'DD-Mon-YY') "Date",
to_char(COMPLETION_TIME, 'Dy') "Day",
'|' separator,
ROUND(SUM(((BLOCKS * BLOCK_SIZE)/&size_divider))) "Total",
'|' separator,
ROUND(SUM(decode(to_char(COMPLETION_TIME, 'hh24'),'00',(BLOCKS * BLOCK_SIZE)/&size_divider,0))) "h0",
ROUND(SUM(decode(to_char(COMPLETION_TIME, 'hh24'),'01',(BLOCKS * BLOCK_SIZE)/&size_divider,0))) "h1",
ROUND(SUM(decode(to_char(COMPLETION_TIME, 'hh24'),'02',(BLOCKS * BLOCK_SIZE)/&size_divider,0))) "h2",
ROUND(SUM(decode(to_char(COMPLETION_TIME, 'hh24'),'03',(BLOCKS * BLOCK_SIZE)/&size_divider,0))) "h3",
ROUND(SUM(decode(to_char(COMPLETION_TIME, 'hh24'),'04',(BLOCKS * BLOCK_SIZE)/&size_divider,0))) "h4",
ROUND(SUM(decode(to_char(COMPLETION_TIME, 'hh24'),'05',(BLOCKS * BLOCK_SIZE)/&size_divider,0))) "h5",
ROUND(SUM(decode(to_char(COMPLETION_TIME, 'hh24'),'06',(BLOCKS * BLOCK_SIZE)/&size_divider,0))) "h6",
ROUND(SUM(decode(to_char(COMPLETION_TIME, 'hh24'),'07',(BLOCKS * BLOCK_SIZE)/&size_divider,0))) "h7",
ROUND(SUM(decode(to_char(COMPLETION_TIME, 'hh24'),'08',(BLOCKS * BLOCK_SIZE)/&size_divider,0))) "h8",
ROUND(SUM(decode(to_char(COMPLETION_TIME, 'hh24'),'09',(BLOCKS * BLOCK_SIZE)/&size_divider,0))) "h9",
ROUND(SUM(decode(to_char(COMPLETION_TIME, 'hh24'),'10',(BLOCKS * BLOCK_SIZE)/&size_divider,0))) "h10",
ROUND(SUM(decode(to_char(COMPLETION_TIME, 'hh24'),'11',(BLOCKS * BLOCK_SIZE)/&size_divider,0))) "h11",
ROUND(SUM(decode(to_char(COMPLETION_TIME, 'hh24'),'12',(BLOCKS * BLOCK_SIZE)/&size_divider,0))) "h12",
ROUND(SUM(decode(to_char(COMPLETION_TIME, 'hh24'),'13',(BLOCKS * BLOCK_SIZE)/&size_divider,0))) "h13",
ROUND(SUM(decode(to_char(COMPLETION_TIME, 'hh24'),'14',(BLOCKS * BLOCK_SIZE)/&size_divider,0))) "h14",
ROUND(SUM(decode(to_char(COMPLETION_TIME, 'hh24'),'15',(BLOCKS * BLOCK_SIZE)/&size_divider,0))) "h15",
ROUND(SUM(decode(to_char(COMPLETION_TIME, 'hh24'),'16',(BLOCKS * BLOCK_SIZE)/&size_divider,0))) "h16",
ROUND(SUM(decode(to_char(COMPLETION_TIME, 'hh24'),'17',(BLOCKS * BLOCK_SIZE)/&size_divider,0))) "h17",
ROUND(SUM(decode(to_char(COMPLETION_TIME, 'hh24'),'18',(BLOCKS * BLOCK_SIZE)/&size_divider,0))) "h18",
ROUND(SUM(decode(to_char(COMPLETION_TIME, 'hh24'),'19',(BLOCKS * BLOCK_SIZE)/&size_divider,0))) "h19",
ROUND(SUM(decode(to_char(COMPLETION_TIME, 'hh24'),'20',(BLOCKS * BLOCK_SIZE)/&size_divider,0))) "h20",
ROUND(SUM(decode(to_char(COMPLETION_TIME, 'hh24'),'21',(BLOCKS * BLOCK_SIZE)/&size_divider,0))) "h21",
ROUND(SUM(decode(to_char(COMPLETION_TIME, 'hh24'),'22',(BLOCKS * BLOCK_SIZE)/&size_divider,0))) "h22",
ROUND(SUM(decode(to_char(COMPLETION_TIME, 'hh24'),'23',(BLOCKS * BLOCK_SIZE)/&size_divider,0))) "h23"
from v$archived_log
where standby_dest = 'NO'
AND CREATOR IN ('ARCH' , 'FGRD','LGWR','RFS')
AND completion_time > sysdate - &days
group by trunc(COMPLETION_TIME), to_char(COMPLETION_TIME, 'Dy')
order by trunc(COMPLETION_TIME)
/
+93 -92
View File
@@ -1,92 +1,93 @@
set term off
/*
*
* Author : Vishal Gupta
* Purpose : Display hourly and daily redolog switches by size
* Parameters : None
*
* Revision History:
* ===================
* Date Author Description
* --------- ------------ -----------------------------------------
* 30-Dec-14 Vishal Gupta Added number of days as input parameter
* 18-Mar-14 Vishal Gupta Added separator columns for daily total
* 27-Feb-12 Vishal Gupta Formated the output and parameterized size granuality
* 05-Aug-04 Vishal Gupta First Draft
*
*/
set term on
/************************************
* INPUT PARAMETERS
************************************/
UNDEFINE days
DEFINE days="&&1"
set term off
COLUMN _DAYS NEW_VALUE DAYS NOPRINT
SELECT UPPER(DECODE('&&days','','2','&&days')) "_DAYS"
FROM DUAL;
set term on
/************************************
* CONFIGURATION PARAMETERS
************************************/
DEFINE size_label=MB
DEFINE size_divider="1024/1024"
--DEFINE size_label=GB
--DEFINE size_divider="1024/1024/1024"
DEFINE round_precision=2
PROMPT
PROMPT ************************************************************************
PROMPT * A R C H I V E L O G S W I T C H S U M M A R Y (By Size)
PROMPT * (Hourly and Daily figures in &&size_label)
PROMPT *
PROMPT * Input Parameters
PROMPT * - Days = '&&days'
PROMPT ************************************************************************
PROMPT
SET head on FEED off ECHO OFF LINES 1000 TRIMSPOOL ON TRIM on PAGES 1000
COLUMN separator HEADING "!|!|!" FORMAT A1
COLUMN "Date" HEADING "Date" FORMAT A12
COLUMN "Day" HEADING "Day" FORMAT A3
COLUMN "Total" HEADING "Hourly|Total|(&size_label)" FORMAT 9,999,999
COLUMN "M00" HEADING "Minutes|01-10 |(&size_label) " FORMAT 999,999
COLUMN "M10" HEADING "Minutes|11-20 |(&size_label) " FORMAT 999,999
COLUMN "M20" HEADING "Minutes|21-30 |(&size_label) " FORMAT 999,999
COLUMN "M30" HEADING "Minutes|31-40 |(&size_label) " FORMAT 999,999
COLUMN "M40" HEADING "Minutes|41-50 |(&size_label) " FORMAT 999,999
COLUMN "M50" HEADING "Minutes|51-60 |(&size_label) " FORMAT 999,999
SELECT TO_CHAR(trunc(COMPLETION_TIME,'HH24'),'DD-MON-YY HH24') "Date",
to_char(COMPLETION_TIME, 'Dy') "Day",
'|' separator,
ROUND(SUM(((BLOCKS * BLOCK_SIZE)/&&size_divider))) "Total",
'|' separator,
ROUND(SUM(CASE WHEN TO_NUMBER(to_char(COMPLETION_TIME, 'MI')) BETWEEN 01 AND 10 THEN ROUND((BLOCKS * BLOCK_SIZE)/&&size_divider) ELSE 0 END)) "M00",
ROUND(SUM(CASE WHEN TO_NUMBER(to_char(COMPLETION_TIME, 'MI')) BETWEEN 11 AND 20 THEN ROUND((BLOCKS * BLOCK_SIZE)/&&size_divider) ELSE 0 END)) "M10",
ROUND(SUM(CASE WHEN TO_NUMBER(to_char(COMPLETION_TIME, 'MI')) BETWEEN 21 AND 30 THEN ROUND((BLOCKS * BLOCK_SIZE)/&&size_divider) ELSE 0 END)) "M20",
ROUND(SUM(CASE WHEN TO_NUMBER(to_char(COMPLETION_TIME, 'MI')) BETWEEN 31 AND 40 THEN ROUND((BLOCKS * BLOCK_SIZE)/&&size_divider) ELSE 0 END)) "M30",
ROUND(SUM(CASE WHEN TO_NUMBER(to_char(COMPLETION_TIME, 'MI')) BETWEEN 41 AND 50 THEN ROUND((BLOCKS * BLOCK_SIZE)/&&size_divider) ELSE 0 END)) "M40",
ROUND(SUM(CASE WHEN TO_NUMBER(to_char(COMPLETION_TIME, 'MI')) BETWEEN 51 AND 60 THEN ROUND((BLOCKS * BLOCK_SIZE)/&&size_divider) ELSE 0 END)) "M50",
'|' separator
from v$archived_log
where standby_dest = 'NO'
and CREATOR IN ('ARCH' , 'FGRD')
AND completion_time > sysdate - &days
group by trunc(COMPLETION_TIME,'HH24'), to_char(COMPLETION_TIME, 'Dy')
order by trunc(COMPLETION_TIME,'HH24')
;
set term off
/*
*
* Author : Vishal Gupta
* Purpose : Display hourly and daily redolog switches by size
* Parameters : None
*
* Revision History:
* ===================
* Date Author Description
* --------- ------------ -----------------------------------------
* 30-Dec-14 Vishal Gupta Added number of days as input parameter
* 18-Mar-14 Vishal Gupta Added separator columns for daily total
* 27-Feb-12 Vishal Gupta Formated the output and parameterized size granuality
* 05-Aug-04 Vishal Gupta First Draft
*
*/
set term on
/************************************
* INPUT PARAMETERS
************************************/
UNDEFINE days
DEFINE days="&&1"
set term off
COLUMN _DAYS NEW_VALUE DAYS NOPRINT
SELECT UPPER(DECODE('&&days','','2','&&days')) "_DAYS"
FROM DUAL;
set term on
/************************************
* CONFIGURATION PARAMETERS
************************************/
DEFINE size_label=MB
DEFINE size_divider="1024/1024"
--DEFINE size_label=GB
--DEFINE size_divider="1024/1024/1024"
DEFINE round_precision=2
PROMPT
PROMPT ************************************************************************
PROMPT * A R C H I V E L O G S W I T C H S U M M A R Y (By Size)
PROMPT * (Hourly and Daily figures in &&size_label)
PROMPT *
PROMPT * Input Parameters
PROMPT * - Days = '&&days'
PROMPT ************************************************************************
PROMPT
SET head on FEED off ECHO OFF LINES 1000 TRIMSPOOL ON TRIM on PAGES 1000
COLUMN separator HEADING "!|!|!" FORMAT A1
COLUMN "Date" HEADING "Date" FORMAT A12
COLUMN "Day" HEADING "Day" FORMAT A3
COLUMN "Total" HEADING "Hourly|Total|(&size_label)" FORMAT 9,999,999
COLUMN "M00" HEADING "Minutes|01-10 |(&size_label) " FORMAT 999,999
COLUMN "M10" HEADING "Minutes|11-20 |(&size_label) " FORMAT 999,999
COLUMN "M20" HEADING "Minutes|21-30 |(&size_label) " FORMAT 999,999
COLUMN "M30" HEADING "Minutes|31-40 |(&size_label) " FORMAT 999,999
COLUMN "M40" HEADING "Minutes|41-50 |(&size_label) " FORMAT 999,999
COLUMN "M50" HEADING "Minutes|51-60 |(&size_label) " FORMAT 999,999
SELECT TO_CHAR(trunc(COMPLETION_TIME,'HH24'),'DD-MON-YY HH24') "Date",
to_char(COMPLETION_TIME, 'Dy') "Day",
'|' separator,
ROUND(SUM(((BLOCKS * BLOCK_SIZE)/&&size_divider))) "Total",
'|' separator,
ROUND(SUM(CASE WHEN TO_NUMBER(to_char(COMPLETION_TIME, 'MI')) BETWEEN 01 AND 10 THEN ROUND((BLOCKS * BLOCK_SIZE)/&&size_divider) ELSE 0 END)) "M00",
ROUND(SUM(CASE WHEN TO_NUMBER(to_char(COMPLETION_TIME, 'MI')) BETWEEN 11 AND 20 THEN ROUND((BLOCKS * BLOCK_SIZE)/&&size_divider) ELSE 0 END)) "M10",
ROUND(SUM(CASE WHEN TO_NUMBER(to_char(COMPLETION_TIME, 'MI')) BETWEEN 21 AND 30 THEN ROUND((BLOCKS * BLOCK_SIZE)/&&size_divider) ELSE 0 END)) "M20",
ROUND(SUM(CASE WHEN TO_NUMBER(to_char(COMPLETION_TIME, 'MI')) BETWEEN 31 AND 40 THEN ROUND((BLOCKS * BLOCK_SIZE)/&&size_divider) ELSE 0 END)) "M30",
ROUND(SUM(CASE WHEN TO_NUMBER(to_char(COMPLETION_TIME, 'MI')) BETWEEN 41 AND 50 THEN ROUND((BLOCKS * BLOCK_SIZE)/&&size_divider) ELSE 0 END)) "M40",
ROUND(SUM(CASE WHEN TO_NUMBER(to_char(COMPLETION_TIME, 'MI')) BETWEEN 51 AND 60 THEN ROUND((BLOCKS * BLOCK_SIZE)/&&size_divider) ELSE 0 END)) "M50",
'|' separator
from v$archived_log
where standby_dest = 'NO'
and CREATOR IN ('ARCH' , 'FGRD')
AND completion_time > sysdate - &days
group by trunc(COMPLETION_TIME,'HH24'), to_char(COMPLETION_TIME, 'Dy')
order by trunc(COMPLETION_TIME,'HH24')
;
+34 -46
View File
@@ -6,22 +6,20 @@
-- | Copyright (c) 1998-2011 Jeffrey M. Hunter. All rights reserved. |
-- |----------------------------------------------------------------------------|
-- | DATABASE : Oracle |
-- | FILE : perf_log_switch_history_count_daily_7.sql |
-- | FILE : perf_log_switch_history_count_daily_all.sql |
-- | CLASS : Tuning |
-- | PURPOSE : Reports on how often log switches occur in your database on a |
-- | daily basis. This script is to be used with an Oracle 7 |
-- | database. |
-- | daily basis. It will query all records contained in |
-- | v$log_history. This script is to be used with an Oracle 8 |
-- | database or higher. |
-- | NOTE : As with any code, ensure to test this script in a development |
-- | environment before attempting to run it in production. |
-- +----------------------------------------------------------------------------+
-- SET LINESIZE 145
SET LINESIZE 145
SET PAGESIZE 9999
SET VERIFY off
ACCEPT startDate PROMPT 'Enter start date (DD-MON-YYYY): '
ACCEPT endDate PROMPT 'Enter end date (DD-MON-YYYY): '
COLUMN H00 FORMAT 999 HEADING '00'
COLUMN H01 FORMAT 999 HEADING '01'
COLUMN H02 FORMAT 999 HEADING '02'
@@ -50,44 +48,34 @@ COLUMN TOTAL FORMAT 999,999 HEADING 'Total'
SELECT
SUBSTR(time,1,5) DAY
, SUM(DECODE(SUBSTR(time,10,2),'00',1,0)) H00
, SUM(DECODE(SUBSTR(time,10,2),'01',1,0)) H01
, SUM(DECODE(SUBSTR(time,10,2),'02',1,0)) H02
, SUM(DECODE(SUBSTR(time,10,2),'03',1,0)) H03
, SUM(DECODE(SUBSTR(time,10,2),'04',1,0)) H04
, SUM(DECODE(SUBSTR(time,10,2),'05',1,0)) H05
, SUM(DECODE(SUBSTR(time,10,2),'06',1,0)) H06
, SUM(DECODE(SUBSTR(time,10,2),'07',1,0)) H07
, SUM(DECODE(SUBSTR(time,10,2),'08',1,0)) H08
, SUM(DECODE(SUBSTR(time,10,2),'09',1,0)) H09
, SUM(DECODE(SUBSTR(time,10,2),'10',1,0)) H10
, SUM(DECODE(SUBSTR(time,10,2),'11',1,0)) H11
, SUM(DECODE(SUBSTR(time,10,2),'12',1,0)) H12
, SUM(DECODE(SUBSTR(time,10,2),'13',1,0)) H13
, SUM(DECODE(SUBSTR(time,10,2),'14',1,0)) H14
, SUM(DECODE(SUBSTR(time,10,2),'15',1,0)) H15
, SUM(DECODE(SUBSTR(time,10,2),'16',1,0)) H16
, SUM(DECODE(SUBSTR(time,10,2),'17',1,0)) H17
, SUM(DECODE(SUBSTR(time,10,2),'18',1,0)) H18
, SUM(DECODE(SUBSTR(time,10,2),'19',1,0)) H19
, SUM(DECODE(SUBSTR(time,10,2),'20',1,0)) H20
, SUM(DECODE(SUBSTR(time,10,2),'21',1,0)) H21
, SUM(DECODE(SUBSTR(time,10,2),'22',1,0)) H22
, SUM(DECODE(SUBSTR(time,10,2),'23',1,0)) H23
, COUNT(*) TOTAL
SUBSTR(TO_CHAR(first_time, 'MM/DD/RR HH:MI:SS'),1,5) DAY
, SUM(DECODE(SUBSTR(TO_CHAR(first_time, 'MM/DD/RR HH24:MI:SS'),10,2),'00',1,0)) H00
, SUM(DECODE(SUBSTR(TO_CHAR(first_time, 'MM/DD/RR HH24:MI:SS'),10,2),'01',1,0)) H01
, SUM(DECODE(SUBSTR(TO_CHAR(first_time, 'MM/DD/RR HH24:MI:SS'),10,2),'02',1,0)) H02
, SUM(DECODE(SUBSTR(TO_CHAR(first_time, 'MM/DD/RR HH24:MI:SS'),10,2),'03',1,0)) H03
, SUM(DECODE(SUBSTR(TO_CHAR(first_time, 'MM/DD/RR HH24:MI:SS'),10,2),'04',1,0)) H04
, SUM(DECODE(SUBSTR(TO_CHAR(first_time, 'MM/DD/RR HH24:MI:SS'),10,2),'05',1,0)) H05
, SUM(DECODE(SUBSTR(TO_CHAR(first_time, 'MM/DD/RR HH24:MI:SS'),10,2),'06',1,0)) H06
, SUM(DECODE(SUBSTR(TO_CHAR(first_time, 'MM/DD/RR HH24:MI:SS'),10,2),'07',1,0)) H07
, SUM(DECODE(SUBSTR(TO_CHAR(first_time, 'MM/DD/RR HH24:MI:SS'),10,2),'08',1,0)) H08
, SUM(DECODE(SUBSTR(TO_CHAR(first_time, 'MM/DD/RR HH24:MI:SS'),10,2),'09',1,0)) H09
, SUM(DECODE(SUBSTR(TO_CHAR(first_time, 'MM/DD/RR HH24:MI:SS'),10,2),'10',1,0)) H10
, SUM(DECODE(SUBSTR(TO_CHAR(first_time, 'MM/DD/RR HH24:MI:SS'),10,2),'11',1,0)) H11
, SUM(DECODE(SUBSTR(TO_CHAR(first_time, 'MM/DD/RR HH24:MI:SS'),10,2),'12',1,0)) H12
, SUM(DECODE(SUBSTR(TO_CHAR(first_time, 'MM/DD/RR HH24:MI:SS'),10,2),'13',1,0)) H13
, SUM(DECODE(SUBSTR(TO_CHAR(first_time, 'MM/DD/RR HH24:MI:SS'),10,2),'14',1,0)) H14
, SUM(DECODE(SUBSTR(TO_CHAR(first_time, 'MM/DD/RR HH24:MI:SS'),10,2),'15',1,0)) H15
, SUM(DECODE(SUBSTR(TO_CHAR(first_time, 'MM/DD/RR HH24:MI:SS'),10,2),'16',1,0)) H16
, SUM(DECODE(SUBSTR(TO_CHAR(first_time, 'MM/DD/RR HH24:MI:SS'),10,2),'17',1,0)) H17
, SUM(DECODE(SUBSTR(TO_CHAR(first_time, 'MM/DD/RR HH24:MI:SS'),10,2),'18',1,0)) H18
, SUM(DECODE(SUBSTR(TO_CHAR(first_time, 'MM/DD/RR HH24:MI:SS'),10,2),'19',1,0)) H19
, SUM(DECODE(SUBSTR(TO_CHAR(first_time, 'MM/DD/RR HH24:MI:SS'),10,2),'20',1,0)) H20
, SUM(DECODE(SUBSTR(TO_CHAR(first_time, 'MM/DD/RR HH24:MI:SS'),10,2),'21',1,0)) H21
, SUM(DECODE(SUBSTR(TO_CHAR(first_time, 'MM/DD/RR HH24:MI:SS'),10,2),'22',1,0)) H22
, SUM(DECODE(SUBSTR(TO_CHAR(first_time, 'MM/DD/RR HH24:MI:SS'),10,2),'23',1,0)) H23
, COUNT(*) TOTAL
FROM
v$log_history a
WHERE
(TO_DATE(SUBSTR(time, 1,8), 'MM/DD/RR')
>=
TO_DATE('&startDate', 'DD-MON-YYYY')
)
AND
(TO_DATE(SUBSTR(time, 1,8), 'MM/DD/RR')
<=
TO_DATE('&endDate', 'DD-MON-YYYY')
)
GROUP BY SUBSTR(time,1,5)
v$log_history a
GROUP BY SUBSTR(TO_CHAR(first_time, 'MM/DD/RR HH:MI:SS'),1,5)
ORDER BY SUBSTR(TO_CHAR(first_time, 'MM/DD/RR HH:MI:SS'),1,5)
/
+1 -1
View File
@@ -1,2 +1,2 @@
-- Create AWR snapshot
EXEC DBMS_WORKLOAD_REPOSITORY.create_snapshot;
EXEC DBMS_WORKLOAD_REPOSITORY.create_snapshot;
+131 -129
View File
@@ -1,129 +1,131 @@
/*
*
* Author : Vishal Gupta
* Purpose : Display SQL Binds from AWR
* Version : 10.2 and above
* Parameters : 1 - SQL_ID
* 2 - Number of Days (Default 7 days)
* 2 - Whereclause
*
*
* Revision History:
* ===================
* Date Author Description
* --------- ------------ -----------------------------------------
* 27-Aug-15 Vishal Gupta Created
*
*
*/
/************************************
* INPUT PARAMETERS
************************************/
UNDEFINE sql_id
UNDEFINE days
UNDEFINE whereclause
UNDEFINE force_matching_signature
UNDEFINE use_force_matching_signature
DEFINE sql_id="&&1"
DEFINE days="&&2"
DEFINE whereclause="&&3"
DEFINE force_matching_signature=""
COLUMN _days NEW_VALUE days NOPRINT
COLUMN _force_matching_signature NEW_VALUE force_matching_signature NOPRINT
set term off
SELECT DECODE('&&days','','7','&&days') "_days"
, DECODE('&&sql_id','%','%','') "_force_matching_signature"
FROM DUAL
;
set term on
COLUMN _force_matching_signature NEW_VALUE force_matching_signature NOPRINT
set term off
select to_char(ss2.force_matching_signature) "_force_matching_signature"
from v$database d
, dba_hist_sqlstat ss2
where d.dbid = ss2.dbid
AND ss2.sql_id = '&&sql_id' and rownum = 1;
select CASE WHEN '&&force_matching_signature' IS NULL THEN '0'
WHEN '&&force_matching_signature' = '' THEN '0'
ELSE '&&force_matching_signature'
END "_force_matching_signature"
from dual
;
set term on
/************************************/
Prompt
Prompt **************************************************************
Prompt * AWR SQL Bind Values
Prompt * (Force Matching Signature = '&&force_matching_signature')
PROMPT *
PROMPT * Input Parameters
PROMPT * - SQL Id = '&&sql_id'
PROMPT * - Days = '&&days'
PROMPT * - WhereClause = '&&whereclause'
Prompt **************************************************************
COLUMN seperator HEADING "!|!|!|!" FORMAT a1
COLUMN end_interval_time HEADING "Snap Time" FORMAT a15
COLUMN instance_number HEADING "I#" FORMAT 99
COLUMN SQL_ID HEADING "SQLId" FORMAT a13
COLUMN plan_hash_value HEADING "Plan|Hash|Value" FORMAT 999999999999
COLUMN bind_values HEADING "Bind Values" FORMAT a100
COLUMN bind_datatype HEADING "Bind DataType" FORMAT a80
SELECT TO_CHAR(s.end_interval_time,'DD-MON-YY HH24:MI') end_interval_time
, ss.instance_number
, ss.sql_id
, ss.plan_hash_value
, (select listagg(NVL(name,':B' || position)
||'['
|| datatype_string || NVL2(scale
,'(' || scale || NVL2(precision,','|| precision,'') || ')'
,''
)
|| ']'
||'='
|| CASE
WHEN datatype_string <> 'TIMESTAMP' THEN NVL(value_string,'NULL')
ELSE TO_CHAR(ANYDATA.ACCESStimestamp(VALUE_ANYDATA))
END
,','
) WITHIN GROUP (order by position)
from table(dbms_sqltune.extract_binds(ss.BIND_DATA))
) bind_values
/*
, (select listagg(NVL(name,':B' || position) || '='
|| datatype_string || NVL2(scale,'(' || scale || NVL2(precision,','|| precision, '') || ')' ,'' )
,','
) WITHIN GROUP (order by position)
from table(dbms_sqltune.extract_binds(ss.BIND_DATA))
) bind_datatype
*/
from v$database d
JOIN dba_hist_snapshot s ON s.dbid = d.dbid
JOIN dba_hist_sqlstat ss ON ss.dbid = s.dbid AND ss.instance_number = s.instance_number AND ss.snap_id = s.snap_id
AND ss.executions_delta > 0
where s.end_interval_time > SYSDATE - &&days
AND ss.sql_id LIKE CASE ss.force_matching_signature
WHEN 0 THEN '&&sql_id'
ELSE '%'
END
AND ss.force_matching_signature = '&&force_matching_signature'
&&whereclause
ORDER BY s.end_interval_time
, ss.instance_number
;
/*
*
* Author : Vishal Gupta
* Purpose : Display SQL Binds from AWR
* Version : 10.2 and above
* Parameters : 1 - SQL_ID
* 2 - Number of Days (Default 7 days)
* 2 - Whereclause
*
*
* Revision History:
* ===================
* Date Author Description
* --------- ------------ -----------------------------------------
* 27-Aug-15 Vishal Gupta Created
*
*
*/
/************************************
* INPUT PARAMETERS
************************************/
UNDEFINE sql_id
UNDEFINE days
UNDEFINE whereclause
UNDEFINE force_matching_signature
UNDEFINE use_force_matching_signature
DEFINE sql_id="&&1"
DEFINE days="&&2"
DEFINE whereclause="&&3"
DEFINE force_matching_signature=""
COLUMN _days NEW_VALUE days NOPRINT
COLUMN _force_matching_signature NEW_VALUE force_matching_signature NOPRINT
set term off
SELECT DECODE('&&days','','7','&&days') "_days"
, DECODE('&&sql_id','%','%','') "_force_matching_signature"
FROM DUAL
;
set term on
COLUMN _force_matching_signature NEW_VALUE force_matching_signature NOPRINT
set term off
select to_char(ss2.force_matching_signature) "_force_matching_signature"
from v$database d
, dba_hist_sqlstat ss2
where d.dbid = ss2.dbid
AND ss2.sql_id = '&&sql_id' and rownum = 1;
select CASE WHEN '&&force_matching_signature' IS NULL THEN '0'
WHEN '&&force_matching_signature' = '' THEN '0'
ELSE '&&force_matching_signature'
END "_force_matching_signature"
from dual
;
set term on
/************************************/
Prompt
Prompt **************************************************************
Prompt * AWR SQL Bind Values
Prompt * (Force Matching Signature = '&&force_matching_signature')
PROMPT *
PROMPT * Input Parameters
PROMPT * - SQL Id = '&&sql_id'
PROMPT * - Days = '&&days'
PROMPT * - WhereClause = '&&whereclause'
Prompt **************************************************************
COLUMN seperator HEADING "!|!|!|!" FORMAT a1
COLUMN end_interval_time HEADING "Snap Time" FORMAT a15
COLUMN instance_number HEADING "I#" FORMAT 99
COLUMN SQL_ID HEADING "SQLId" FORMAT a13
COLUMN plan_hash_value HEADING "Plan|Hash|Value" FORMAT 999999999999
COLUMN bind_values HEADING "Bind Values" FORMAT a100
COLUMN bind_datatype HEADING "Bind DataType" FORMAT a80
SELECT TO_CHAR(s.end_interval_time,'DD-MON-YY HH24:MI') end_interval_time
, ss.instance_number
, ss.sql_id
, ss.plan_hash_value
, (select listagg(NVL(name,':B' || position)
||'['
|| datatype_string || NVL2(scale
,'(' || scale || NVL2(precision,','|| precision,'') || ')'
,''
)
|| ']'
||'='
|| CASE
WHEN datatype_string <> 'TIMESTAMP' THEN NVL(value_string,'NULL')
ELSE TO_CHAR(ANYDATA.ACCESStimestamp(VALUE_ANYDATA))
END
,','
) WITHIN GROUP (order by position)
from table(dbms_sqltune.extract_binds(ss.BIND_DATA))
) bind_values
/*
, (select listagg(NVL(name,':B' || position) || '='
|| datatype_string || NVL2(scale,'(' || scale || NVL2(precision,','|| precision, '') || ')' ,'' )
,','
) WITHIN GROUP (order by position)
from table(dbms_sqltune.extract_binds(ss.BIND_DATA))
) bind_datatype
*/
from v$database d
JOIN dba_hist_snapshot s ON s.dbid = d.dbid
JOIN dba_hist_sqlstat ss ON ss.dbid = s.dbid AND ss.instance_number = s.instance_number AND ss.snap_id = s.snap_id
AND ss.executions_delta > 0
where s.end_interval_time > SYSDATE - &&days
AND ss.sql_id LIKE CASE ss.force_matching_signature
WHEN 0 THEN '&&sql_id'
ELSE '%'
END
AND ss.force_matching_signature = '&&force_matching_signature'
&&whereclause
ORDER BY s.end_interval_time
, ss.instance_number
;
+7 -5
View File
@@ -42,12 +42,14 @@ from
dba_hist_sqlstat sqlstat
join dba_hist_snapshot snap using (snap_id,instance_number)
join gv$instance i using (instance_number)
where
snap.begin_interval_time>=&&2
and snap.end_interval_time<=&&3
and force_matching_signature='&&1'
and executions_delta>0
where
snap.begin_interval_time>=&&2
and snap.end_interval_time<=&&3
and force_matching_signature='&&1'
and executions_delta>0
order by
snap_id asc
/
+7 -5
View File
@@ -40,12 +40,14 @@ from
dba_hist_sqlstat sqlstat
join dba_hist_snapshot snap using (snap_id,instance_number)
join gv$instance i using (instance_number)
where
snap.begin_interval_time>=&&2
and snap.end_interval_time<=&&3
and sql_id='&&1'
and executions_delta>0
where
snap.begin_interval_time>=&&2
and snap.end_interval_time<=&&3
and sql_id='&&1'
and executions_delta>0
order by
snap_id asc
/
+48
View File
@@ -0,0 +1,48 @@
-- https://blogs.oracle.com/optimizer/post/check-sql-stale-statistics
set pagesize 100
set linesize 150
set trims off
set tab off
set verify off
column table_name format a50
column index_name format a50
column object_type format a40
column owner format a40
with plan_tables as (
select distinct object_name,object_owner, object_type
from dba_hist_sql_plan
where object_type like 'TABLE%'
and sql_id = '&1')
select t.object_owner owner,
t.object_name table_name,
t.object_type object_type,
decode(stale_stats,'NO','OK',NULL, 'NO STATS!', 'STALE!') staleness
from dba_tab_statistics s,
plan_tables t
where s.table_name = t.object_name
and s.owner = t.object_owner
and s.partition_name is null
and s.subpartition_name is null
order by t.object_owner, t.object_name;
PROMPT ==========
PROMPT Indexes
PROMPT ==========
with plan_indexes as (
select distinct object_name,object_owner, object_type
from dba_hist_sql_plan
where object_type like 'INDEX%'
and sql_id = '&1')
select i.object_owner owner,
i.object_name index_name,
i.object_type object_type,
decode(stale_stats,'NO','OK',NULL, 'NO STATS!', 'STALE!') staleness
from dba_ind_statistics s,
plan_indexes i
where s.index_name = i.object_name
and s.owner = i.object_owner
and s.partition_name is null
and s.subpartition_name is null
order by i.object_owner, i.object_name;
+65
View File
@@ -0,0 +1,65 @@
/*
Syntax: @blockers <where clause> <w.COL1,COL2,...,b.COL1,b.COL2,...,f.COL1,f.COL2...>
w.COLx for waiter cols
b.COLx for blocker cols
f.COLx for final blocker cols
vplesnila 2025-08-29 - creation
*/
col event for a25 trunc
col username for a20
col machine for a30
col osuser for a20
col action for a30
col module for a30
col program2 for a15 trunc heading "Program2"
col program for a25 trunc heading "Program"
col inst_id for 9 head "I#"
col blocking_instance for 9 head "B|I#"
col blocking_session for 9999999 head "B|SID"
col blocking_session_status for a10 head "Blocking|status"
col final_blocking_instance for 9 head "FB|I#"
col final_blocking_session for 9999999 head "FB|SID"
col final_blocking_session_status for a10 head "Final|Blocking|status"
col blocking_serial head "B|serial#"
col final_blocking_serial head "FB|serial#"
col blocked_sess_str for a15 heading "Blocked" justify left
col blocking_sess_str for a15 heading "Blocking" justify left
col final_blocking_sess_str for a15 heading "Final|Blocking" justify left
select
&&2
,w.sid||','||w.serial#||'@'||w.inst_id blocked_sess_str
,w.blocking_session||','||w.blocking_serial||'@'||w.blocking_instance blocking_sess_str
,case
when w.blocking_session=w.final_blocking_session and w.blocking_instance=w.final_blocking_instance then null
else w.final_blocking_session||','||w.final_blocking_serial||'@'||w.final_blocking_instance
end final_blocking_sess_str
from (
select
s1.*
,s2.serial# blocking_serial
,s3.serial# final_blocking_serial
,CASE WHEN s1.type = 'BACKGROUND' OR REGEXP_LIKE(s1.program, '.*\([PJ]\d+\)') THEN
REGEXP_REPLACE(SUBSTR(s1.program,INSTR(s1.program,'(')), '\d', 'n')
ELSE
'('||REGEXP_REPLACE(REGEXP_REPLACE(s1.program, '(.*)@(.*)(\(.*\))', '\1'), '\d', 'n')||')'
END || ' ' program2
from
gv$session s1
inner join gv$session s2 on s1.blocking_session=s2.sid and s1.blocking_instance=s2.inst_id
inner join gv$session s3 on s1.final_blocking_session=s3.sid and s1.final_blocking_instance=s3.inst_id
where
s1.blocking_session is not null
) w
inner join gv$session b on b.sid=w.blocking_session and b.inst_id=w.inst_id
inner join gv$session f on f.sid=w.final_blocking_session and f.inst_id=w.inst_id
where
&&1
order by
final_blocking_sess_str desc,
blocking_sess_str desc
/
+27 -12
View File
@@ -1,13 +1,12 @@
-- Transfer (copy) a SQL Profile from PDBx on CDBa into PDBy on CDBb
SPO coe_xfr_sql_profile.log;
SET DEF ON TERM OFF ECHO ON FEED OFF VER OFF HEA ON LIN 2000 PAGES 100 LONG 8000000 LONGC 800000 TRIMS ON TI OFF TIMI OFF SERVEROUT ON SIZE 1000000 NUMF "" SQLP SQL>;
SET SERVEROUT ON SIZE UNL;
REM
REM $Header: 215187.1 coe_xfr_sql_profile.sql 11.4.5.5 2013/03/01 carlos.sierra $
REM
REM Copyright (c) 2000-2013, Oracle Corporation. All rights reserved.
REM $Header: coe_xfr_sql_profile.sql 2020/03/10 carlos.sierra $
REM
REM AUTHOR
REM carlos.sierra@oracle.com
REM Carlos Sierra
REM
REM SCRIPT
REM coe_xfr_sql_profile.sql
@@ -51,13 +50,17 @@ REM sqlt/utl/sqltprofile.sql
REM 3. Be aware that using DBMS_SQLTUNE requires a license for
REM Oracle Tuning Pack.
REM 4. Use a DBA user but not SYS.
REM 5. If you get "ORA-06532: Subscript outside of limit, ORA-06512: at line 1"
REM Then you may consider this change (only in a test and disposable system):
REM create or replace TYPE sys.sqlprof_attr AS VARRAY(5000) of VARCHAR2(500);
REM
SET TERM ON ECHO OFF;
PRO
PRO Parameter 1:
PRO SQL_ID (required)
PRO
DEF sql_id = '&1';
DEF sql_id = '&1.';
UNDEF 1;
PRO
WITH
p AS (
@@ -69,10 +72,12 @@ SELECT plan_hash_value
SELECT plan_hash_value
FROM dba_hist_sql_plan
WHERE sql_id = TRIM('&&sql_id.')
AND dbid = (SELECT dbid FROM v$database)
AND other_xml IS NOT NULL ),
m AS (
SELECT plan_hash_value,
SUM(elapsed_time)/SUM(executions) avg_et_secs
SUM(elapsed_time)/SUM(executions) avg_et_secs,
SUM(executions) executions
FROM gv$sql
WHERE sql_id = TRIM('&&sql_id.')
AND executions > 0
@@ -80,27 +85,33 @@ SELECT plan_hash_value,
plan_hash_value ),
a AS (
SELECT plan_hash_value,
SUM(elapsed_time_total)/SUM(executions_total) avg_et_secs
SUM(elapsed_time_delta)/SUM(executions_delta) avg_et_secs,
SUM(executions_delta) executions
FROM dba_hist_sqlstat
WHERE sql_id = TRIM('&&sql_id.')
AND executions_total > 0
AND executions_delta > 0
GROUP BY
plan_hash_value )
SELECT p.plan_hash_value,
ROUND(NVL(m.avg_et_secs, a.avg_et_secs)/1e6, 3) avg_et_secs
SELECT
TO_CHAR(ROUND(m.avg_et_secs/1e6, 6), '999,990.000000') avg_et_secs_mem,
TO_CHAR(ROUND(a.avg_et_secs/1e6, 6), '999,990.000000') avg_et_secs_awr,
p.plan_hash_value,
m.executions executions_mem,
a.executions executions_awr
--TO_CHAR(ROUND(NVL(m.avg_et_secs, a.avg_et_secs)/1e6, 6), '999,990.000000') avg_et_secs
FROM p, m, a
WHERE p.plan_hash_value = m.plan_hash_value(+)
AND p.plan_hash_value = a.plan_hash_value(+)
ORDER BY
avg_et_secs NULLS LAST;
NVL(m.avg_et_secs, a.avg_et_secs) NULLS LAST, a.avg_et_secs;
PRO
PRO Parameter 2:
PRO PLAN_HASH_VALUE (required)
PRO
DEF plan_hash_value = '&2';
UNDEF 2;
PRO
PRO Values passed to coe_xfr_sql_profile:
PRO ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
PRO SQL_ID : "&&sql_id."
PRO PLAN_HASH_VALUE: "&&plan_hash_value."
PRO
@@ -230,6 +241,7 @@ BEGIN
FROM dba_hist_sql_plan
WHERE sql_id = TRIM('&&sql_id.')
AND plan_hash_value = TO_NUMBER(TRIM('&&plan_hash_value.'))
AND dbid = (SELECT dbid FROM v$database)
AND other_xml IS NOT NULL
ORDER BY
id)
@@ -251,6 +263,7 @@ BEGIN
FOR i IN (SELECT other_xml
FROM gv$sql_plan
WHERE plan_hash_value = TO_NUMBER(TRIM('&&plan_hash_value.'))
--WHERE full_plan_hash_value = TO_NUMBER(TRIM('&&plan_hash_value.'))
AND other_xml IS NOT NULL
ORDER BY
child_number, id)
@@ -272,6 +285,8 @@ BEGIN
FOR i IN (SELECT other_xml
FROM dba_hist_sql_plan
WHERE plan_hash_value = TO_NUMBER(TRIM('&&plan_hash_value.'))
--WHERE full_plan_hash_value = TO_NUMBER(TRIM('&&plan_hash_value.'))
AND dbid = (SELECT dbid FROM v$database)
AND other_xml IS NOT NULL
ORDER BY
id)
-1
View File
@@ -4,4 +4,3 @@ prompt To ADD colored <sql_id>: execute DBMS_WORKLOAD_REPOSITORY.ADD_COLORED_
prompt To REMOVE colored <sql_id>: execute DBMS_WORKLOAD_REPOSITORY.REMOVE_COLORED_SQL(sql_id=>'<sql_id>')
prompt
+110 -108
View File
@@ -1,108 +1,110 @@
-- Create SQL Plan Baselin from AWR Plan
SET PAGES 200 LONG 80000;
ACC sql_id PROMPT 'Enter SQL_ID: ';
WITH
p AS (
SELECT plan_hash_value
FROM dba_hist_sql_plan
WHERE sql_id = TRIM('&&sql_id.')
AND dbid = (SELECT dbid FROM v$database)
AND other_xml IS NOT NULL ),
a AS (
SELECT plan_hash_value,
SUM(elapsed_time_total)/SUM(executions_total) avg_et_secs,
MAX(executions_total) executions_total
FROM dba_hist_sqlstat
WHERE sql_id = TRIM('&&sql_id.')
AND executions_total > 0
GROUP BY
plan_hash_value )
SELECT p.plan_hash_value,
ROUND(a.avg_et_secs/1e6, 6) avg_et_secs,
a.executions_total
FROM p, a
WHERE p.plan_hash_value = a.plan_hash_value(+)
ORDER BY
avg_et_secs NULLS LAST;
ACC plan_hash_value PROMPT 'Enter Plan Hash Value: ';
COL dbid NEW_V dbid NOPRI;
SELECT dbid FROM v$database;
COL begin_snap_id NEW_V begin_snap_id NOPRI;
COL end_snap_id NEW_V end_snap_id NOPRI;
SELECT MIN(p.snap_id) begin_snap_id, MAX(p.snap_id) end_snap_id
FROM dba_hist_sqlstat p,
dba_hist_snapshot s
WHERE p.dbid = &&dbid
AND p.sql_id = '&&sql_id.'
AND p.plan_hash_value = TO_NUMBER('&&plan_hash_value.')
AND s.snap_id = p.snap_id
AND s.dbid = p.dbid
AND s.instance_number = p.instance_number;
VAR sqlset_name VARCHAR2(30);
EXEC :sqlset_name := REPLACE('s_&&sql_id._&&plan_hash_value._awr', ' ');
PRINT sqlset_name;
SET SERVEROUT ON;
VAR plans NUMBER;
DECLARE
l_sqlset_name VARCHAR2(30);
l_description VARCHAR2(256);
sts_cur SYS.DBMS_SQLTUNE.SQLSET_CURSOR;
BEGIN
l_sqlset_name := :sqlset_name;
l_description := 'SQL_ID:&&sql_id., PHV:&&plan_hash_value., BEGIN:&&begin_snap_id., END:&&end_snap_id.';
l_description := REPLACE(REPLACE(l_description, ' '), ',', ', ');
BEGIN
DBMS_OUTPUT.put_line('dropping sqlset: '||l_sqlset_name);
SYS.DBMS_SQLTUNE.drop_sqlset (
sqlset_name => l_sqlset_name,
sqlset_owner => USER );
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.put_line(SQLERRM||' while trying to drop STS: '||l_sqlset_name||' (safe to ignore)');
END;
l_sqlset_name :=
SYS.DBMS_SQLTUNE.create_sqlset (
sqlset_name => l_sqlset_name,
description => l_description,
sqlset_owner => USER );
DBMS_OUTPUT.put_line('created sqlset: '||l_sqlset_name);
OPEN sts_cur FOR
SELECT VALUE(p)
FROM TABLE(DBMS_SQLTUNE.select_workload_repository (&&begin_snap_id., &&end_snap_id.,
'sql_id = ''&&sql_id.'' AND plan_hash_value = TO_NUMBER(''&&plan_hash_value.'') AND loaded_versions > 0',
NULL, NULL, NULL, NULL, 1, NULL, 'ALL')) p;
SYS.DBMS_SQLTUNE.load_sqlset (
sqlset_name => l_sqlset_name,
populate_cursor => sts_cur );
DBMS_OUTPUT.put_line('loaded sqlset: '||l_sqlset_name);
CLOSE sts_cur;
:plans := DBMS_SPM.load_plans_from_sqlset (
sqlset_name => l_sqlset_name,
sqlset_owner => USER );
END;
/
PRINT plans;
SET PAGES 14 LONG 80 ECHO OFF SERVEROUT OFF;
UNDEF sql_id plan_hash_value
CL COL
-- Create SQL Plan Baselin from AWR Plan
SET PAGES 200 LONG 80000;
ACC sql_id PROMPT 'Enter SQL_ID: ';
WITH
p AS (
SELECT plan_hash_value
FROM dba_hist_sql_plan
WHERE sql_id = TRIM('&&sql_id.')
AND dbid = (SELECT dbid FROM v$database)
AND other_xml IS NOT NULL ),
a AS (
SELECT plan_hash_value,
SUM(elapsed_time_total)/SUM(executions_total) avg_et_secs,
MAX(executions_total) executions_total
FROM dba_hist_sqlstat
WHERE sql_id = TRIM('&&sql_id.')
AND executions_total > 0
GROUP BY
plan_hash_value )
SELECT p.plan_hash_value,
ROUND(a.avg_et_secs/1e6, 6) avg_et_secs,
a.executions_total
FROM p, a
WHERE p.plan_hash_value = a.plan_hash_value(+)
ORDER BY
avg_et_secs NULLS LAST;
ACC plan_hash_value PROMPT 'Enter Plan Hash Value: ';
COL dbid NEW_V dbid NOPRI;
SELECT dbid FROM v$database;
COL begin_snap_id NEW_V begin_snap_id NOPRI;
COL end_snap_id NEW_V end_snap_id NOPRI;
SELECT MIN(p.snap_id) begin_snap_id, MAX(p.snap_id) end_snap_id
FROM dba_hist_sqlstat p,
dba_hist_snapshot s
WHERE p.dbid = &&dbid
AND p.sql_id = '&&sql_id.'
AND p.plan_hash_value = TO_NUMBER('&&plan_hash_value.')
AND s.snap_id = p.snap_id
AND s.dbid = p.dbid
AND s.instance_number = p.instance_number;
PROMPT &&begin_snap_id &&end_snap_id
VAR sqlset_name VARCHAR2(30);
EXEC :sqlset_name := REPLACE('s_&&sql_id._&&plan_hash_value._awr', ' ');
PRINT sqlset_name;
SET SERVEROUT ON;
VAR plans NUMBER;
DECLARE
l_sqlset_name VARCHAR2(30);
l_description VARCHAR2(256);
sts_cur SYS.DBMS_SQLTUNE.SQLSET_CURSOR;
BEGIN
l_sqlset_name := :sqlset_name;
l_description := 'SQL_ID:&&sql_id., PHV:&&plan_hash_value., BEGIN:&&begin_snap_id., END:&&end_snap_id.';
l_description := REPLACE(REPLACE(l_description, ' '), ',', ', ');
BEGIN
DBMS_OUTPUT.put_line('dropping sqlset: '||l_sqlset_name);
SYS.DBMS_SQLTUNE.drop_sqlset (
sqlset_name => l_sqlset_name,
sqlset_owner => USER );
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.put_line(SQLERRM||' while trying to drop STS: '||l_sqlset_name||' (safe to ignore)');
END;
l_sqlset_name :=
SYS.DBMS_SQLTUNE.create_sqlset (
sqlset_name => l_sqlset_name,
description => l_description,
sqlset_owner => USER );
DBMS_OUTPUT.put_line('created sqlset: '||l_sqlset_name);
OPEN sts_cur FOR
SELECT VALUE(p)
FROM TABLE(DBMS_SQLTUNE.select_workload_repository (&&begin_snap_id., &&end_snap_id.,
'sql_id = ''&&sql_id.'' AND plan_hash_value = TO_NUMBER(''&&plan_hash_value.'') AND loaded_versions > 0',
NULL, NULL, NULL, NULL, 1, NULL, 'ALL')) p;
SYS.DBMS_SQLTUNE.load_sqlset (
sqlset_name => l_sqlset_name,
populate_cursor => sts_cur );
DBMS_OUTPUT.put_line('loaded sqlset: '||l_sqlset_name);
CLOSE sts_cur;
:plans := DBMS_SPM.load_plans_from_sqlset (
sqlset_name => l_sqlset_name,
sqlset_owner => USER );
END;
/
PRINT plans;
SET PAGES 14 LONG 80 ECHO OFF SERVEROUT OFF;
UNDEF sql_id plan_hash_value
CL COL
+25 -35
View File
@@ -1,35 +1,25 @@
REM $Header: 215187.1 create_spb_from_cur.sql 12.1.02 2013/09/09 carlos.sierra $
-- Create SQL Plan Baseline from SQL Cursor
ACC sql_text_piece PROMPT 'Enter SQL Text piece: '
SET PAGES 200 LONG 80000 ECHO ON;
COL sql_text PRI;
SELECT sql_id, sql_text /* exclude_me */
FROM v$sqlarea
WHERE sql_text LIKE '%&&sql_text_piece.%'
AND sql_text NOT LIKE '%/* exclude_me */%';
ACC sql_id PROMPT 'Enter SQL_ID: ';
SELECT plan_hash_value, SUM(executions) executions, SUM(elapsed_time) elapsed_time, /* exclude_me */
CASE WHEN SUM(executions) > 0 THEN ROUND(SUM(elapsed_time)/SUM(executions)/1e6, 3) END avg_secs_per_exec
FROM v$sql
WHERE sql_id = '&&sql_id.'
GROUP BY
plan_hash_value
ORDER BY
4 DESC NULLS FIRST;
ACC plan_hash_value PROMPT 'Enter Plan Hash Value: ';
VAR plans NUMBER;
EXEC :plans := DBMS_SPM.load_plans_from_cursor_cache('&&sql_id.', TO_NUMBER('&&plan_hash_value.'));
PRINT plans;
SET PAGES 14 LONG 80 ECHO OFF;
UNDEF sql_text_piece sql_id plan_hash_value
PROMPT In RAC environement, be sure to be connected to the instance where the SQL_ID is in library cache
undefine sql_id
define sql_id=&&1
SELECT plan_hash_value, SUM(executions) executions, SUM(elapsed_time) elapsed_time, /* exclude_me */
CASE WHEN SUM(executions) > 0 THEN ROUND(SUM(elapsed_time)/SUM(executions)/1e6, 3) END avg_secs_per_exec
FROM v$sql
WHERE sql_id = '&&sql_id.'
GROUP BY
plan_hash_value
ORDER BY
4 DESC NULLS FIRST;
ACC plan_hash_value PROMPT 'Enter Plan Hash Value: ';
VAR plans NUMBER;
EXEC :plans := DBMS_SPM.load_plans_from_cursor_cache('&&sql_id.', TO_NUMBER('&&plan_hash_value.'));
PRINT plans;
SET PAGES 14 LONG 80 ECHO OFF;
UNDEF sql_text_piece sql_id plan_hash_value
+11
View File
@@ -0,0 +1,11 @@
-- Copyright 2018 Tanel Poder. All rights reserved. More info at http://tanelpoder.com
-- Licensed under the Apache License, Version 2.0. See LICENSE.txt for terms & conditions.
select
TO_CHAR(sysdate, 'yyyy-mm-dd hh24:mi:ss') as "SYSDATE",
(to_date(sysdate) - to_date('01011970','ddmmyyyy')) * 24*60*60 SECONDS_EPOCH,
to_char((to_date(sysdate) - to_date('01011970','ddmmyyyy')) * 24*60*60, 'XXXXXXXX') SEC_HEX,
q'[TIMESTAMP']'||TO_CHAR(sysdate, 'yyyy-mm-dd hh24:mi:ss')||'''' as "SYSDATE_ANSI_TIMESTAMP_SYNTAX"
from
dual
/
+7 -7
View File
@@ -39,18 +39,18 @@ CLEAR COLUMNS
CLEAR BREAKS
CLEAR COMPUTES
COLUMN comp_id FORMAT a9 HEADING 'Component|ID'
COLUMN comp_name FORMAT a35 HEADING 'Component|Name'
COLUMN version FORMAT a13 HEADING 'Version'
COLUMN status FORMAT a11 HEADING 'Status'
COLUMN comp_id FORMAT a9 HEADING 'Component|ID'
COLUMN comp_name FORMAT a35 HEADING 'Component|Name'
COLUMN version_full FORMAT a13 HEADING 'Version'
COLUMN status FORMAT a11 HEADING 'Status'
COLUMN modified HEADING 'Modified'
COLUMN Schema FORMAT a15 HEADING 'Schema'
COLUMN procedure FORMAT a45 HEADING 'Procedure'
COLUMN Schema FORMAT a15 HEADING 'Schema'
COLUMN procedure FORMAT a45 HEADING 'Procedure'
SELECT
comp_id
, comp_name
, version
, version_full
, status
, modified
, schema
+16
View File
@@ -0,0 +1,16 @@
-- Copyright 2018 Tanel Poder. All rights reserved. More info at http://tanelpoder.com
-- Licensed under the Apache License, Version 2.0. See LICENSE.txt for terms & conditions.
col dblinks_owner head OWNER for a20
col dblinks_db_link head DB_LINK for a40
col dblinks_username head USERNAME for a20
col dblinks_host head HOST for a40
select
owner dblinks_owner,
db_link dblinks_db_link,
username dblinks_username,
host dblinks_host,
created
from
dba_db_links;
+82
View File
@@ -0,0 +1,82 @@
/*
*
* Author : Vishal Gupta
* Purpose : Display DataGuard Statistics
* Parameters : NONE
*
* Revision History:
* ===================
* Date Author Description
* --------- ------------ -----------------------------------------
* 30-Jul-12 Vishal Gupta Created
*
*/
PROMPT *****************************************************************
PROMPT * DataGuard Stats
PROMPT *****************************************************************
COLUMN name HEADING "Name" FORMAT a23
COLUMN value HEADING "Value" FORMAT a20
COLUMN unit HEADING "Unit" FORMAT a30
COLUMN time_computed HEADING "TimeComputed" FORMAT a20
COLUMN datum_time HEADING "datum_time" FORMAT a20
SELECT ds.name
, ds.value
, ds.unit
, ds.time_computed
, ds.datum_time
FROM v$dataguard_stats ds
;
PROMPT
PROMPT
PROMPT *********************************************
PROMPT * R E C O V E R Y P R O G R E S S *
PROMPT *********************************************
COLUMN inst_id HEADING "I#" FORMAT 99
COLUMN start_time HEADING "Start Time" FORMAT a18
COLUMN type HEADING "Type" FORMAT a20
COLUMN item HEADING "Item" FORMAT a25
COLUMN units HEADING "Units" FORMAT a10
COLUMN sofar HEADING "SoFar" FORMAT a45
COLUMN total HEADING "Total" FORMAT 999,999,999,999
COLUMN timestamp HEADING "Start Time" FORMAT a18
COLUMN comments HEADING "Comments" FORMAT a18
SELECT r.inst_id
--, TO_CHAR(r.start_time,'DD-MON-YY HH24:MI:SS') start_time
--, r.type
, r.item
, CASE r.item
WHEN 'Last Applied Redo' THEN TO_CHAR(r.timestamp,'DD-MON-YY HH24:MI:SS') || ' , ' || r.comments
|| chr(10) || 'ApplyLag - ' || REPLACE(REPLACE(TO_CHAR( CAST(sysdate as TIMESTAMP) - CAST( r.timestamp as TIMESTAMP))
,'+0000000','+')
,'.000000','')
WHEN 'Active Time' THEN FLOOR(r.sofar/3600) || 'h ' || FLOOR(MOD(r.sofar,3600)/60) || 'm ' || MOD(r.sofar,60) || 's'
WHEN 'Elapsed Time' THEN FLOOR(r.sofar/3600) || 'h ' || FLOOR(MOD(r.sofar,3600)/60) || 'm ' || MOD(r.sofar,60) || 's'
|| chr(10) || 'StartTime: ' || TO_CHAR(r.start_time,'DD-MON-YY HH24:MI:SS')
ELSE TRIM(TO_CHAR(r.sofar,'999,999,999,999')) || ' ' || r.units
END SoFar
--, r.total
FROM gv$recovery_progress r
WHERE r.start_time = (SELECT MAX(start_time) from gv$recovery_progress)
ORDER BY DECODE(r.item
,'Last Applied Redo',1
,'Standby Apply Lag',2
,'Active Apply Rate',3
,'Average Apply Rate',4
,'Maximum Apply Rate',5
,'Redo Applied',6
,'Log Files',7
,'Apply Time per Log',8
,'Checkpoint Time per Log',9
,'Active Time',21
,'Elapsed Time',22
,999
)
;
+44
View File
@@ -0,0 +1,44 @@
-- Copyright 2018 Tanel Poder. All rights reserved. More info at http://tanelpoder.com
-- Licensed under the Apache License, Version 2.0. See LICENSE.txt for terms & conditions.
SET LiNeSiZe 10000 PageSize 5000
SET TrimOut ON Head Off
-- /**/
-- SELECT
-- LISTAGG
-- (SUBSTR(s,
-- MOD(r2-1,115)+1,1)) WITHIN GROUP(ORDER BY r)
-- FROM(SELECT rownum r,RPAD(RPAD(RPAD(RPAD(LPAD(LPAD
-- ('(',x,'('),20,' '),x+20,')'),40,' '),40+y,' '),50,'W')s FROM(
-- SELECT CEIL(ABS(SIN(rownum/30)*13))x,CEIL(ABS(COS(rownum/9)*5))y
-- FROM dual CONNECT BY LEVEL<=115)), (SELECT rownum r2 FROM (dual)
-- CONNECT BY LEVEL <= 50) GROUP BY MOD(r2-1, 115) +1;
SELECT
CHR(POWER(3,3))
||'[38;5;0m'||LISTAGG(SUBSTR(
REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(s ,')',
CHR(POWER(3,3))||'[48;5;'||TRIM(TO_CHAR((POWER(2,4)+CEIL((SIN(r2/5) +
SIN(ROWNUM/150)+1)*3-1)+CEIL((-SIN(ROWNUM/150)+1)*3-1)*6+CEIL((COS(ROWNUM/150)+1)*3-1) *6*6),
'099'))||'m)'),'(',CHR(POWER(3,3))||'[48;5;'||TRIM(TO_CHAR((POWER(2,4)+CEIL((SIN(r2/5)+SIN(ROWNUM/150) +1)*3-1)+
CEIL((-SIN(ROWNUM /150)+1)*3-1)*6+CEIL((COS(ROWNUM/150)+1)*3-1)*6*6),'099'))||'m('),' ',CHR(POWER(3,3))||'[48;5;'||TRIM (TO_CHAR(
(POWER(2,4)+CEIL(4)+CEIL(4)*6+CEIL(5-(r2/8))*6*6),'099'))||'m '),'.',CHR(POWER(3,3))||'[48;5;'||TRIM(TO_CHAR((POWER(2,4)+CEIL(5)+CEIL(4)*6+CEIL
(3)*6*6),'099'))||'m~'),'W',CHR(POWER(3,3))||'[48;5;'||TRIM(TO_CHAR((POWER(2,4)+CEIL(4+ABS(SIN(r/25)))+CEIL(2-ABS(SIN (r/5))*2)
*6+CEIL(2-ABS(SIN(r/5))*2)*6*6),'099'))||'m '),(MOD(r2-1,115)+1)*12+1,12))WITHIN GROUP(ORDER BY r)||CHR(POWER (3,3))
||'[0m' v FROM(SELECT ROWNUM r, RPAD(RPAD(RPAD(RPAD(LPAD(LPAD('(',x,'('),20,' '), x+20,')'),40,' '), 40+y,
'.'),50,'W')s FROM (SELECT CEIL(ABS(SIN(ROWNUM/30)*13))x,CEIL(ABS(COS(ROWNUM *
1/DBMS_RANDOM.VALUE(7,7.5))*7))y FROM dual CONNECT BY LEVEL<=115)),
(SELECT ROWNUM r2 FROM dual CONNECT BY LEVEL<=50)
GROUP BY MOD(r2-1,115)+1;
+87 -66
View File
@@ -1,3 +1,5 @@
DEFINE search_string=&1
COLUMN name FORMAT A28 TRUNC
@@ -10,126 +12,144 @@ COLUMN tag FORMAT A20 WORD_WRAP
WITH q AS (
SELECT *
FROM (
SELECT 'otherxml.sql' AS name, 'Display outline hints from library cache' AS description, '@otherxml <sql_id> <child#>
' AS Usage, '@otherxml 1fbwxvngasv1f 1' AS Example, 'outline hint' AS tag FROM dual UNION ALL
SELECT 'sql_profile_hints.sql' AS name, 'Display SQL profile hints' AS description, '@sql_profile_hints.sql <sql_profile>
' AS Usage, '@sql_profile_hints.sql sqlprof_2v4h21kf9bz0h' AS Example, 'sqlprof hint' AS tag FROM dual UNION ALL
' AS Usage, '@sql_profile_hints.sql sqlprof_2v4h21kf9bz0h' AS Example, 'sqlprof hint' AS tag FROM dual UNION ALL
SELECT 'awr_sqlid.sql' AS name, 'Display SQL text from AWR' AS description, '@awr_sqlid <sql_id>
' AS Usage, '@awr_sqlid 7q729nhdgtsqq' AS Example, 'awr sqltext' AS tag FROM dual UNION ALL
' AS Usage, '@awr_sqlid 7q729nhdgtsqq' AS Example, 'awr sqltext' AS tag FROM dual UNION ALL
SELECT 'sqlbinds.sql' AS name, 'Show captured binds from GV$SQL_BIND_CAPTURE' AS description, '@sqlbinds <sql_id> <child_number> <bindvar_name>
' AS Usage, '@sqlbinds 0qyu7wm1b2g1r % %' AS Example, 'bind' AS tag FROM dual UNION ALL
' AS Usage, '@sqlbinds 0qyu7wm1b2g1r % %' AS Example, 'bind' AS tag FROM dual UNION ALL
SELECT 'awr_sql_binds.sql' AS name, 'Display SQL Binds from AWR' AS description, '@awr_sql_binds.sql <sql_id> <num_days> <where>
' AS Usage, '@awr_sql_binds.sql 0qyu7wm1b2g1r 7 "and 1=1"'||chr(10)||'@awr_sql_binds.sql 6qqf9bakz7j3n 7 "and plan_hash_value=2088506832"' AS Example, 'bind' AS tag FROM dual UNION ALL
' AS Usage, '@awr_sql_binds.sql 0qyu7wm1b2g1r 7 "and 1=1"'||chr(10)||'@awr_sql_binds.sql 6qqf9bakz7j3n 7 "and plan_hash_value=2088506832"' AS Example, 'bind' AS tag FROM dual UNION ALL
SELECT 'xlast.sql' AS name, 'Explain plan last SQL_ID' AS description, 'xlast.sql
' AS Usage, '' AS Example, 'explain' AS tag FROM dual UNION ALL
' AS Usage, '' AS Example, 'explain' AS tag FROM dual UNION ALL
SELECT 'colored_sql_id.sql' AS name, 'Show colored SQL_ID' AS description, 'colored_sql_id.sql
' AS Usage, '' AS Example, 'color' AS tag FROM dual UNION ALL
' AS Usage, '' AS Example, 'color' AS tag FROM dual UNION ALL
SELECT 'xplan.sql' AS name, 'Explain plan from Library Cache' AS description, '@xplan <sql_id> <child_num>
' AS Usage, '@xplan.sql gy2zd0jzw3w6y 0' AS Example, 'explain' AS tag FROM dual UNION ALL
SELECT 'sqlidtabstat.sql' AS name, 'Staleness for tables/indexes in execution plan' AS description, '@sqlidtabstat.sql <sql_id>
' AS Usage, '@sqlidtabstat.sql 2bu78cxnrm4s7' AS Example, 'stale' AS tag FROM dual UNION ALL
' AS Usage, '@xplan.sql gy2zd0jzw3w6y 0' AS Example, 'explain' AS tag FROM dual UNION ALL
SELECT 'sqlidtabstat.sql' AS name, 'Staleness tables/indexes in execution plan from Library Cache' AS description, '@sqlidtabstat.sql <sql_id>
' AS Usage, '@sqlidtabstat.sql 2bu78cxnrm4s7' AS Example, 'stale library cache' AS tag FROM dual UNION ALL
SELECT 'awrsqlidtabstat.sql' AS name, 'Staleness tables/indexes in execution plan from AWR' AS description, '@awrsqlidtabstat.sql <sql_id>
' AS Usage, '@awrsqlidtabstat.sql 2bu78cxnrm4s7' AS Example, 'stale awr' AS tag FROM dual UNION ALL
SELECT 'stale.sql' AS name, 'List DB stale tables' AS description, '@stale.sql
' AS Usage, '' AS Example, 'stale' AS tag FROM dual UNION ALL
' AS Usage, '' AS Example, 'stale' AS tag FROM dual UNION ALL
SELECT 'tab_details.sql' AS name, 'Table details' AS description, '@tab_details.sql <owner> <table_name>
' AS Usage, '@tab_details.sql SCOTT EMP' AS Example, 'table detail' AS tag FROM dual UNION ALL
' AS Usage, '@tab_details.sql SCOTT EMP' AS Example, 'table detail' AS tag FROM dual UNION ALL
SELECT 'tabstat.sql' AS name, 'Stats details for non PARTITIONED table' AS description, '@tabstat.sql <OWNER> <TABLE>
' AS Usage, '@tabstat.sql SCOTT DEPT' AS Example, 'table stat' AS tag FROM dual UNION ALL
' AS Usage, '@tabstat.sql SCOTT DEPT' AS Example, 'table stat' AS tag FROM dual UNION ALL
SELECT 'tspstat.sql' AS name, 'Stats details for SUB-PARTITIONED table' AS description, '@tspstat.sql <owner> <table_name> <partition_name> <subpartition_name>
' AS Usage, '@tspstat.sql SCOTT EMP EMP1998 EMP EMP1998_ITALY'||chr(10)||'@tspstat.sql SCOTT EMP EMP1998 EMP %' AS Example, 'subpart stat' AS tag FROM dual UNION ALL
' AS Usage, '@tspstat.sql SCOTT EMP EMP1998 EMP EMP1998_ITALY'||chr(10)||'@tspstat.sql SCOTT EMP EMP1998 EMP %' AS Example, 'subpart stat' AS tag FROM dual UNION ALL
SELECT 'tpstat.sql' AS name, 'Stats details for PARTITIONED table' AS description, '@tpstat.sql <OWNER> <TABLE> <PARTITION>
' AS Usage, '@tpstat.sql SCOTT EMP EMP1998' AS Example, 'part stat' AS tag FROM dual UNION ALL
' AS Usage, '@tpstat.sql SCOTT EMP EMP1998' AS Example, 'part stat' AS tag FROM dual UNION ALL
SELECT 'stats_history.sql' AS name, 'Display table statistics history' AS description, '@stats_history.sql <OWNER> <OBJ_NAME> <PART_NAME> <OBJ_TYPE>
' AS Usage, '@stats_history.sql XPS LOAD % %' AS Example, 'history stat' AS tag FROM dual UNION ALL
' AS Usage, '@stats_history.sql XPS LOAD % %' AS Example, 'history stat' AS tag FROM dual UNION ALL
SELECT 'stats_getpref_table.sql' AS name, 'Get table statistics prefs' AS description, '@stats_getpref_table.sql <owner> <table_name>
' AS Usage, '@stats_getpref_table.sql REPORT REP112' AS Example, 'pref stat' AS tag FROM dual UNION ALL
SELECT 'stats_getpref_global.sql' AS name, 'Get GLOBAL statistics prefs' AS description, '@stats_getpref_global.sql
' AS Usage, '' AS Example, 'pref stat' AS tag FROM dual UNION ALL
' AS Usage, '@stats_getpref_table.sql REPORT REP112' AS Example, 'pref stat' AS tag FROM dual UNION ALL
SELECT 'stats_getpref_global.sql' AS name, 'Get GLOBAL statistics prefs' AS description, '@stats_getpref_global.sql
' AS Usage, '' AS Example, 'pref stat' AS tag FROM dual UNION ALL
SELECT 'sqltt_sqlid.sql' AS name, 'Create SQL Tuning Task for SQL_ID' AS description, '@sqltt_sqlid.sql <sql_id> <max_minutes>
' AS Usage, '@sqltt_sqlid.sql 70mfpusqy9jvj 5' AS Example, 'tuning task' AS tag FROM dual UNION ALL
' AS Usage, '@sqltt_sqlid.sql 70mfpusqy9jvj 5' AS Example, 'tuning task' AS tag FROM dual UNION ALL
SELECT 'awr_snapshot.sql' AS name, 'Create AWR snapshot' AS description, '@awr_snapshot.sql
' AS Usage, '' AS Example, 'awr snapshot' AS tag FROM dual UNION ALL
' AS Usage, '' AS Example, 'awr snapshot' AS tag FROM dual UNION ALL
SELECT 'sql_profile.sql' AS name, 'Display all SQL Profiles' AS description, '@sql_profile.sql
' AS Usage, '' AS Example, 'sqlprofile' AS tag FROM dual UNION ALL
' AS Usage, '' AS Example, 'sqlprofile' AS tag FROM dual UNION ALL
SELECT 'sql_profile_detail.sql' AS name, 'Display SQL Profile detail' AS description, '@sql_profile_detail.sql <sql_profile>
' AS Usage, '@sql_profile_detail.sql sqlprof_2v4h21kf9bz0h' AS Example, 'sqlprofile' AS tag FROM dual UNION ALL
' AS Usage, '@sql_profile_detail.sql sqlprof_2v4h21kf9bz0h' AS Example, 'sqlprofile' AS tag FROM dual UNION ALL
SELECT 'create_spb_from_cur.sql' AS name, 'Create SQL Plan Baseline from Library Cache' AS description, '@create_spb_from_cur.sql <sql_id>
' AS Usage, '@create_spb_from_cur.sql g3sm89z3xb4zs' AS Example, 'baseline spb' AS tag FROM dual UNION ALL
' AS Usage, '@create_spb_from_cur.sql g3sm89z3xb4zs' AS Example, 'baseline spb' AS tag FROM dual UNION ALL
SELECT 'create_spb_from_awr.sql' AS name, 'Create SQL Plan Baseline from AWR' AS description, '@create_spb_from_awr.sql <sql_id>
' AS Usage, '@create_spb_from_awr.sql g3sm89z3xb4zs' AS Example, 'baseline spb awr' AS tag FROM dual UNION ALL
SELECT 'sql_plan_baselines.sql' AS name, 'List SQL Plan Baselines' AS description, '@sql_plan_baselines.sql
' AS Usage, '' AS Example, 'baseline spb' AS tag FROM dual UNION ALL
' AS Usage, '@create_spb_from_awr.sql g3sm89z3xb4zs' AS Example, 'baseline spb awr' AS tag FROM dual UNION ALL
SELECT 'sql_plan_baselines.sql' AS name, 'List SQL Plan Baselines' AS description, '@sql_plan_baselines.sql <where_clause>
' AS Usage, '@sql_plan_baselines.sql "1=1"'||chr(10)||'@sql_plan_baselines.sql "accepted=''YES'' and Last_Modified >(sysdate-1)"'||chr(10)||'@sql_plan_baselines.sql "plan_hash_value=237994299"'||chr(10)||'@sql_plan_baselines.sql "sql_id=''g3gwhhx6r00qc''"' AS Example, 'baseline spb' AS tag FROM dual UNION ALL
SELECT 'sqlid_sign.sql' AS name, 'Display force matching signature of SQL_ID' AS description, '@sqlid_sign.sql <sql_id>
' AS Usage, '' AS Example, 'signature' AS tag FROM dual UNION ALL
' AS Usage, '' AS Example, 'signature' AS tag FROM dual UNION ALL
SELECT 'awrsign.sql' AS name, 'AWR history for this force matching signature' AS description, '@awrsign.sql <force_matching_signature> <from_date> <to_date>
' AS Usage, '' AS Example, 'signature' AS tag FROM dual UNION ALL
' AS Usage, '' AS Example, 'signature' AS tag FROM dual UNION ALL
SELECT 'awrsqlid.sql' AS name, 'AWR history of SQL_ID' AS description, '@awrsqlid.sql <force_matching_signature> <from_date> <to_date>
' AS Usage, '' AS Example, 'awr' AS tag FROM dual UNION ALL
' AS Usage, '' AS Example, 'awr' AS tag FROM dual UNION ALL
SELECT 'ashtop.sql' AS name, 'ASH time from GV$ACTIVE_SESSION_HISTORY grouped by dimensions' AS description, '@ashtop.sql <grouping_cols> <filters> <fromtime> <totime>
' AS Usage, '@ashtop.sql username,sql_id session_type=''FOREGROUND'' sysdate-1/24 sysdate' AS Example, 'ash' AS tag FROM dual UNION ALL
' AS Usage, '@ashtop.sql username,sql_id session_type=''FOREGROUND'' sysdate-1/24 sysdate' AS Example, 'ash' AS tag FROM dual UNION ALL
SELECT 'dashtop.sql' AS name, 'ASH time from DBA_HIST_ACTIVE_SESS_HISTORY grouped by dimensions' AS description, '@dashtop.sql <grouping_cols> <filters> <fromtime> <totime>
' AS Usage, '@dashtop.sql sql_id 1=1 "TIMESTAMP''2024-02-06 09:10:35''" "TIMESTAMP''2024-02-06 12:20:50''"' AS Example, 'ash' AS tag FROM dual UNION ALL
' AS Usage, '@dashtop.sql sql_id 1=1 "TIMESTAMP''2024-02-06 09:10:35''" "TIMESTAMP''2024-02-06 12:20:50''"' AS Example, 'ash' AS tag FROM dual UNION ALL
SELECT 'ash_wait_chains.sql' AS name, 'ASH wait chains GV$ACTIVE_SESSION_HISTORY' AS description, '@ash_wait_chains.sql <grouping_cols> <filters> <fromtime> <totime>
' AS Usage, '@ash_wait_chains.sql username||'':''||program2||event2 session_type=''FOREGROUND'' sysdate-1/24 sysdate' AS Example, 'ash wait chain' AS tag FROM dual UNION ALL
' AS Usage, '@ash_wait_chains.sql username||'':''||program2||event2 session_type=''FOREGROUND'' sysdate-1/24 sysdate' AS Example, 'ash wait chain' AS tag FROM dual UNION ALL
SELECT 'dash_wait_chains.sql' AS name, 'ASH wait chains DBA_HIST_ACTIVE_SESS_HISTORY' AS description, '@dash_wait_chains.sql <grouping_cols> <filters> <fromtime> <totime>
' AS Usage, '@dash_wait_chains.sql username||'':''||program2||event2 session_type=''FOREGROUND'' "TIMESTAMP''2024-02-06 09:10:35''" "TIMESTAMP''2024-02-06 12:20:50''"' AS Example, 'ash wait chain' AS tag FROM dual UNION ALL
' AS Usage, '@dash_wait_chains.sql username||'':''||program2||event2 session_type=''FOREGROUND'' "TIMESTAMP''2024-02-06 09:10:35''" "TIMESTAMP''2024-02-06 12:20:50''"' AS Example, 'ash wait chain' AS tag FROM dual UNION ALL
SELECT 'asqlmon.sql' AS name, 'Report SQL-monitoring-style from ASH (GV$ACTIVE_SESSION_HISTORY)' AS description, '@asqlmon.sql <sqlid> <child#> <from_time> <to_time>
' AS Usage, '' AS Example, 'ash sqlmon' AS tag FROM dual UNION ALL
' AS Usage, '' AS Example, 'ash sqlmon' AS tag FROM dual UNION ALL
SELECT 'dasqlmon.sql' AS name, 'Report SQL-monitoring-style from ASH (DBA_HIST_ACTIVE_SESS_HISTORY)' AS description, '@dasqlmon.sql <sqlid> <child#> <from_time> <to_time>
' AS Usage, '' AS Example, 'ash sqlmon' AS tag FROM dual UNION ALL
' AS Usage, '' AS Example, 'ash sqlmon' AS tag FROM dual UNION ALL
SELECT 'transaction_long_running.sql' AS name, 'Long running transactions' AS description, '@transaction_long_running.sql <complement_where_clause>
' AS Usage, '@transaction_long_running.sql "and 1=1"'||chr(10)||'@transaction_long_running.sql "and sid=3198"' AS Example, 'trans' AS tag FROM dual UNION ALL
' AS Usage, '@transaction_long_running.sql "and 1=1"'||chr(10)||'@transaction_long_running.sql "and sid=3198"' AS Example, 'trans' AS tag FROM dual UNION ALL
SELECT 'pardef.sql' AS name, 'Table (and index) partitions definition' AS description, '@pardef.sql <owner> <table_name> <part_name>
' AS Usage, '@pardef.sql POC DEMO1 %' AS Example, 'part' AS tag FROM dual UNION ALL
' AS Usage, '@pardef.sql POC DEMO1 %' AS Example, 'part' AS tag FROM dual UNION ALL
SELECT 'planx.sql' AS name, 'Carlos Sierra Explain Plan from LC/AWR' AS description, '@planx.sql <diag_pack_licence> <sql_id>
' AS Usage, '@planx.sql Y gy2zd0jzw3w6y' AS Example, 'explain cache library awr' AS tag FROM dual UNION ALL
' AS Usage, '@planx.sql Y gy2zd0jzw3w6y' AS Example, 'explain cache library awr' AS tag FROM dual UNION ALL
SELECT 's.sql' AS name, 'Display current Session Wait and SQL_ID' AS description, '@s.sql <list of sid>
' AS Usage, '@s.sql 52,110,225'||chr(10)||'@s.sql "select sid from v$session where username = ''XYZ''"'||chr(10)||'@s/sql &mysid' AS Example, 'session wait sql_id' AS tag FROM dual UNION ALL
' AS Usage, '@s.sql 52,110,225'||chr(10)||'@s.sql "select sid from v$session where username = ''XYZ''"'||chr(10)||'@s/sql &mysid' AS Example, 'session wait sql_id' AS tag FROM dual UNION ALL
SELECT 'usess.sql' AS name, 'User session ldetails (SQL_ID, event, module etc.)' AS description, '@usess.sql <where_clause>
' AS Usage, '@usess.sql "1=1"'||chr(10)||'@usess.sql s.status=''ACTIVE'''||chr(10)||'@usess.sql "s.status=''ACTIVE'' and s.username=''STREAM_USER'' and s.module like ''%REPLI%''"' AS Example, 'session wait' AS tag FROM dual UNION ALL
' AS Usage, '@usess.sql "1=1"'||chr(10)||'@usess.sql s.status=''ACTIVE'''||chr(10)||'@usess.sql "s.status=''ACTIVE'' and s.username=''STREAM_USER'' and s.module like ''%REPLI%''"' AS Example, 'session wait' AS tag FROM dual UNION ALL
SELECT 'sess.sql' AS name, 'User session (idevelopment.info)' AS description, '@sess.sql
' AS Usage, '' AS Example, 'session' AS tag FROM dual UNION ALL
' AS Usage, '' AS Example, 'session' AS tag FROM dual UNION ALL
SELECT 'sessa.sql' AS name, 'User active session (idevelopment.info)' AS description, '@sessa.sql
' AS Usage, '' AS Example, 'session active' AS tag FROM dual UNION ALL
' AS Usage, '' AS Example, 'session active' AS tag FROM dual UNION ALL
SELECT 'locked_objects.sql' AS name, 'Locked objects' AS description, '@locked_objects.sql <owner> <object_name> <object_type> <where_clause>
' AS Usage, '@locked_objects.sql % % % "and 1=1"'||chr(10)||'@locked_objects.sql SCOTT EMP % "and 1=1"'||chr(10)||'@locked_objects.sql % % % "and osuser!=''oracle'' and owner!=''SYS''"' AS Example, 'lock' AS tag FROM dual UNION ALL
' AS Usage, '@locked_objects.sql % % % "and 1=1"'||chr(10)||'@locked_objects.sql SCOTT EMP % "and 1=1"'||chr(10)||'@locked_objects.sql % % % "and osuser!=''oracle'' and owner!=''SYS''"' AS Example, 'lock' AS tag FROM dual UNION ALL
SELECT 'locks.sql' AS name, 'Displays currently locked objects in database' AS description, '@locks.sql
' AS Usage, '' AS Example, 'lock' AS tag FROM dual UNION ALL
' AS Usage, '' AS Example, 'lock' AS tag FROM dual UNION ALL
SELECT 'locks_blocking.sql' AS name, 'Displays blocking locks in database' AS description, '@locks_blocking.sql
' AS Usage, '' AS Example, 'lock block' AS tag FROM dual UNION ALL
' AS Usage, '' AS Example, 'lock block' AS tag FROM dual UNION ALL
SELECT 'sid_details.sql' AS name, 'Display Session Details' AS description, '@sid_details.sql <sid> <indt_id>
' AS Usage, '@sid_details.sql 7531 3' AS Example, 'session' AS tag FROM dual UNION ALL
' AS Usage, '@sid_details.sql 7531 3' AS Example, 'session' AS tag FROM dual UNION ALL
SELECT 'nonshared.sql' AS name, 'Print reasons for non-shared child cursors from V$SQL_SHARED_CURSOR' AS description, '@nonshared.sql <sql_id>
' AS Usage, '@nonshared.sql 7gf6xg9xfv3vb' AS Example, 'shared cursor' AS tag FROM dual UNION ALL
' AS Usage, '@nonshared.sql 7gf6xg9xfv3vb' AS Example, 'shared cursor' AS tag FROM dual UNION ALL
SELECT 'o.sql' AS name, 'Display object' AS description, '@o.sql <owner>.<object_name>
' AS Usage, '@o.sql SCOTT.EMP'||chr(10)||'@o.sql %.EMP%' AS Example, 'object' AS tag FROM dual UNION ALL
' AS Usage, '@o.sql SCOTT.EMP'||chr(10)||'@o.sql %.EMP%' AS Example, 'object' AS tag FROM dual UNION ALL
SELECT 'xawr.sql' AS name, 'Execution plan from AWR' AS description, '@xawr.sql <sql_id> <phv>
' AS Usage, '@xawr.sql 6qqf9bakz7j3n 1522095726' AS Example, 'awr sql_id' AS tag FROM dual UNION ALL
' AS Usage, '@xawr.sql 6qqf9bakz7j3n 1522095726' AS Example, 'awr sql_id' AS tag FROM dual UNION ALL
SELECT 'wrka.sql' AS name, 'PGA and TEMP usage' AS description, '@wrka.sql <where_clause>
' AS Usage, '@wrka.sql 1=1 '||chr(10)||'@wrka.sql sid=123'||chr(10)||'@wrka.sql username=''APPUSER'' '||chr(10)||'@wrka.sql @wrka "program LIKE ''%BatchRunner.exe%'' AND machine=''host123''"' AS Example, 'temp pga' AS tag FROM dual UNION ALL
' AS Usage, '@wrka.sql 1=1 '||chr(10)||'@wrka.sql sid=123'||chr(10)||'@wrka.sql username=''APPUSER'' '||chr(10)||'@wrka.sql @wrka "program LIKE ''%BatchRunner.exe%'' AND machine=''host123''"' AS Example, 'temp pga' AS tag FROM dual UNION ALL
SELECT 'wrkasum.sql' AS name, 'Summary of PGA and TEMP' AS description, '@wrkasum.sql <where_clause>
' AS Usage, '@wrkasum.sql sql_id=''7q729nhdgtsqq''' AS Example, 'temp pga' AS tag FROM dual UNION ALL
' AS Usage, '@wrkasum.sql sql_id=''7q729nhdgtsqq''' AS Example, 'temp pga' AS tag FROM dual UNION ALL
SELECT 'arch_size_hourly.sql' AS name, 'Archivelog size history by DAY' AS description, '@arch_size_hourly.sql <number_of_days>
' AS Usage, '@arch_size_hourly.sql 7' AS Example, 'arch' AS tag FROM dual UNION ALL
' AS Usage, '@arch_size_hourly.sql 7' AS Example, 'arch' AS tag FROM dual UNION ALL
SELECT 'arch_size_hourly_detail.sql' AS name, 'Archivelog size history by HOUR' AS description, '@arch_size_hourly_detail.sql <number_of_days>
' AS Usage, '@arch_size_hourly_detail.sql 2' AS Example, 'arch' AS tag FROM dual UNION ALL
SELECT 'arch_switch_hist.sql' AS name, 'Archivelog switch history by DAY+HOUR' AS description, '@arch_switch_hist.sql
' AS Usage, '@arch_switch_hist.sql' AS Example, 'arch switch' AS tag FROM dual UNION ALL
SELECT 'recovery_area_usage.sql' AS name, 'Display Recovery Area Usage' AS description, '@recovery_area_usage.sql
' AS Usage, '@recovery_area_usage.sql' AS Example, 'recovery area recovery area fra' AS tag FROM dual UNION ALL
' AS Usage, '@arch_size_hourly_detail.sql 2' AS Example, 'arch' AS tag FROM dual UNION ALL
SELECT 'arch_switch_hist.sql' AS name, 'Archivelog switch history by DAY+HOUR' AS description, '@arch_switch_hist.sql
' AS Usage, '@arch_switch_hist.sql' AS Example, 'arch switch' AS tag FROM dual UNION ALL
SELECT 'recovery_area_usage.sql' AS name, 'Display Recovery Area Usage' AS description, '@recovery_area_usage.sql
' AS Usage, '@recovery_area_usage.sql' AS Example, 'recovery area recovery area fra' AS tag FROM dual UNION ALL
SELECT 'log.sql' AS name, 'Show redo log layout' AS description, '@log.sql
' AS Usage, '@log.sql' AS Example, 'log redo standby' AS tag FROM dual UNION ALL
' AS Usage, '@log.sql' AS Example, 'log redo standby' AS tag FROM dual UNION ALL
SELECT 'tbs.sql' AS name, 'Tablespace usage' AS description, '@tbs.sql <tablespace_name>
' AS Usage, '@tbs.sql %'||chr(10)||'@tbs USERS' AS Example, 'tablespace' AS tag FROM dual UNION ALL
' AS Usage, '@tbs.sql %'||chr(10)||'@tbs USERS' AS Example, 'tablespace' AS tag FROM dual UNION ALL
SELECT 'dba_registry.sql' AS name, 'Database registry/components' AS description, '@dba_registry.sql
' AS Usage, '@dba_registry.sql' AS Example, 'registry component' AS tag FROM dual UNION ALL
' AS Usage, '@dba_registry.sql' AS Example, 'registry component' AS tag FROM dual UNION ALL
SELECT 'dba_invalid_objects.sql' AS name, 'List invalid objects' AS description, '@dba_invalid_objects.sql
' AS Usage, '@dba_invalid_objects.sql' AS Example, 'invalid' AS tag FROM dual UNION ALL
' AS Usage, '@dba_invalid_objects.sql' AS Example, 'invalid' AS tag FROM dual UNION ALL
SELECT 'tpardef.sql' AS name, 'Table only partitions definition' AS description, '@tpardef.sql <owner> <table_name> <part_name>
' AS Usage, '@tpardef.sql POC DEMO1 %' AS Example, 'part' AS tag FROM dual UNION ALL
' AS Usage, '@tpardef.sql POC DEMO1 %' AS Example, 'part' AS tag FROM dual UNION ALL
SELECT 'sqlid.sql' AS name, 'SQL_ID details from Library Cache' AS description, '@sqlid.sql <SQL_ID> <CHILD_NUMBER>
' AS Usage, '@sqlid.sql a5ks9fhw2v9s1 %'||chr(10)||'@sqlid.sql a5ks9fhw2v9s1 0' AS Example, 'sqlid cache library' AS tag FROM dual UNION ALL
' AS Usage, '@sqlid.sql a5ks9fhw2v9s1 %'||chr(10)||'@sqlid.sql a5ks9fhw2v9s1 0' AS Example, 'sqlid cache library' AS tag FROM dual UNION ALL
SELECT 'hint.sql' AS name, 'SQL Hint information' AS description, '@hint.sql <hint_pattern>
' AS Usage, '@hint.sql FULL'||chr(10)||'@hint.sql MERGE' AS Example, 'hint' AS tag FROM dual
' AS Usage, '@hint.sql FULL'||chr(10)||'@hint.sql MERGE' AS Example, 'hint' AS tag FROM dual UNION ALL
SELECT 'dblinks.sql' AS name, 'List database links' AS description, 'dblinks.sql
' AS Usage, '@dblinks.sql' AS Example, 'link' AS tag FROM dual UNION ALL
SELECT 'dg_stats.sql' AS name, 'Dataguard Stats' AS description, '@dg_stats.sql
' AS Usage, '@dg_stats.sql' AS Example, 'dataguard standby' AS tag FROM dual UNION ALL
SELECT 'otherxml.sql' AS name, 'Display other_xml value for a SQL_ID' AS description, '@otherxml.sql <sql_id> <child_number>
' AS Usage, '@otherxml.sql a5ks9fhw2v9s1 0' AS Example, 'other_xml otherxml other' AS tag FROM dual UNION ALL
SELECT 'date.sql' AS name, 'Date (sysdate) in different formats' AS description, 'date.sql
' AS Usage, '@date.sql' AS Example, 'date sysdate' AS tag FROM dual UNION ALL
SELECT 'fish.sql' AS name, 'Famous fish script of Tanel Poder' AS description, '@fish.sql
' AS Usage, '@fish.sql' AS Example, 'fish' AS tag FROM dual UNION ALL
SELECT 'blockers.sql' AS name, 'Show blocked sessions and blockers' AS description, '@blockers <where clause> <w.COL1,COL2,...,b.COL1,b.COL2,...,f.COL1,f.COL2...>
' AS Usage, '@blockers 1=1 w.program2,w.sql_id,w.event,b.event,b.program'||chr(10)||'@blockers "w.sql_id=''23k2zf2urpwq0''" w.event,b.event,b.program,b.osuser' AS Example, 'blocker lock' AS tag FROM dual UNION ALL
SELECT 'sed.sql' AS name, 'Show wait event descriptions' AS description, '@sed <event>
' AS Usage, '@sed "%db file%"'||chr(10)||'@sed "PX Deq: Execute Reply"' AS Example, 'event' AS tag FROM dual UNION ALL
SELECT 'xb.sql' AS name, 'Tanel Poder eXplain Better' AS description, '1) alter session set statistics_level = all; (or user GATHER_PLAN_STATISTICS hint instead) 2) Run the statement you want to explain 3) @xb.sql
' AS Usage, '@xb' AS Example, 'explain plan better' AS tag FROM dual UNION ALL
SELECT 'xbi.sql' AS name, 'Tanel Poder eXplain Better for an SQL_ID' AS description, '@xbi <sql_id> <child_number>
' AS Usage, '@xbi 23k2zf2urpwq0 0' AS Example, 'explain sql_id plan better' AS tag FROM dual
)
)
SELECT name,description,usage,example FROM q
@@ -144,3 +164,4 @@ ORDER BY
UNDEFINE search_string
CLEAR COLUMNS
-1
View File
@@ -20,4 +20,3 @@ from v$sql_hint
where lower(name) like lower('%&1%')
/
+46
View File
@@ -0,0 +1,46 @@
set serveroutput ON
declare
sql_text CLOB;
h SYS.SQLPROF_ATTR;
signature NUMBER;
signaturef NUMBER;
begin
/* Replace values as you wish */
h := SYS.SQLPROF_ATTR(
q'[BEGIN_OUTLINE_DATA]',
q'[IGNORE_OPTIM_EMBEDDED_HINTS]',
q'[OPTIMIZER_FEATURES_ENABLE('19.1.0')]',
q'[DB_VERSION('19.1.0')]',
q'[ALL_ROWS]',
q'[OUTLINE_LEAF(@"SEL$1")]',
q'[FULL(@"SEL$1" "D"@"SEL$1")]',
q'[END_OUTLINE_DATA]'
);
select SQL_FULLTEXT into sql_text from gv$sql where sql_id='&&1' and CHILD_NUMBER=0;
signature := DBMS_SQLTUNE.SQLTEXT_TO_SIGNATURE(sql_text);
signaturef := DBMS_SQLTUNE.SQLTEXT_TO_SIGNATURE(sql_text, TRUE);
DBMS_SQLTUNE.IMPORT_SQL_PROFILE (
sql_text => sql_text,
profile => h,
name => 'sqlprof_&&1',
description => 'sqlprof_&&1 '||signature||' '||signaturef||'',
category => 'DEFAULT',
validate => TRUE,
replace => TRUE,
force_match => FALSE /* TRUE:FORCE (match even when different literals in SQL). FALSE:EXACT (similar to CURSOR_SHARING) */ );
exception
when others then
dbms_output.put_line('Getting error: '||sqlerrm);
end;
/
set serveroutput OFF
-2
View File
@@ -54,8 +54,6 @@ def _tpt_tempdir=&SQLPATH/tmp
define day="sysdate-1 sysdate"
define today="TRUNC(sysdate) sysdate"
set errordetails off
-- you should change linesize to match terminal width - 1 only
-- if you don't have a terminal with horizontal scrolling
-- capability (cmd.exe and Terminator terminal do have horizontal scrolling)
+123 -122
View File
@@ -1,122 +1,123 @@
/*
* Author : Vishal Gupta
* Purpose : Displays currently locked objects in database
* Parameters : 1 - owner (% - wildchar, \ - escape char) , this could also be passed as OWNER.OBJECT_NAME
* 2 - Object name (% - wildchar, \ - escape char)
* 3 - Object Type (% - wildchar, \ - escape char)
*
* Revision History:
* ===================
* Date Author Description
* --------- ------------ -----------------------------------------
* 29-Jan-16 Vishal Gupta Switched from gv$locked_objects to gv$lock, as
* earlier view was giving information about locks on
* temporary tables (with preserve on commit rows setting).
* - Also added machine and process in the output
* 06-Sep-12 Vishal Gupta Added where clause to add more filtering
* 09-Aug-12 Vishal Gupta Created
*
*/
/************************************
* INPUT PARAMETERS
************************************/
UNDEFINE owner
UNDEFINE object_name
UNDEFINE object_type
UNDEFINE WHERE_CLAUSE
DEFINE owner="&&1"
DEFINE object_name="&&2"
DEFINE object_type="&&3"
DEFINE WHERE_CLAUSE="&&4"
COLUMN _owner NEW_VALUE owner NOPRINT
COLUMN _object_name NEW_VALUE object_name NOPRINT
COLUMN _object_type NEW_VALUE object_type NOPRINT
set term off
SELECT DECODE(UPPER('&&owner'),'','%','&&owner') "_owner"
, DECODE(UPPER('&&object_name'),'','%','&&object_name') "_object_name"
, DECODE(UPPER('&&object_type'),'','%','&&object_type') "_object_type"
FROM DUAL;
SELECT CASE
WHEN INSTR('&&owner','.') != 0 THEN SUBSTR(UPPER('&&owner'),1,INSTR('&&owner','.')-1)
ELSE DECODE(UPPER('&&owner'),'','%',UPPER('&&owner'))
END "_owner"
, CASE
WHEN INSTR('&&owner','.') != 0 THEN SUBSTR(UPPER('&&owner'),INSTR('&&owner','.')+1)
ELSE DECODE(UPPER('&&object_name'),'','%',UPPER('&&object_name'))
END "_object_name"
FROM DUAL;
set term on
PROMPT **************************************************************
PROMPT * L O C K E D O B J E C T S
PROMPT *
PROMPT * Input Parameters
PROMPT * - Owner = '&&owner'
PROMPT * - Object Name = '&&object_name'
PROMPT * - Object Type = '&&object_type'
PROMPT * - Where Clause = "&&WHERE_CLAUSE"
PROMPT **************************************************************
COLUMN object_name HEADING "ObjectName" FORMAT a40
COLUMN object_type HEADING "ObjectType" FORMAT a10 TRUNCATED
COLUMN locked_mode HEADING "LockedMode" FORMAT a10
COLUMN sid HEADING "SID" FORMAT 99999
COLUMN inst_id HEADING "I#" FORMAT 99
COLUMN spid HEADING "SPID" FORMAT a6
COLUMN status HEADING "Status" FORMAT a8
COLUMN state HEADING "State" FORMAT a12 TRUNCATED
COLUMN logon_time HEADING "Logon Time" FORMAT a18
COLUMN username HEADING "UserName" FORMAT a20
COLUMN osuser HEADING "OS User" FORMAT a15 TRUNCATED
COLUMN MACHINE HEADING "Machine" FORMAT a20 TRUNCATED
COLUMN process HEADING "Process" FORMAT a11
COLUMN program HEADING "Program" FORMAT a18 TRUNCATED
COLUMN event HEADING "Event" FORMAT a30 TRUNCATED
COLUMN last_call_et HEADING "LastCall|(sec)" FORMAT a12
COLUMN sql_child_number HEADING "SQL|Child|No" FORMAT 99
SELECT o.owner || '.' || o.object_name object_name
, o.object_type
, DECODE(l.lmode,
0, 'None', /* Mon Lock equivalent */
1, 'Null', /* N */
2, 'Row-S (SS)', /* L */
3, 'Row-X (SX)', /* R */
4, 'Share', /* S */
5, 'S/Row-X (SSX)', /* C */
6, 'Exclusive', /* X */
TO_CHAR(l.lmode)) locked_mode
, s.sid sid
, s.inst_id
, s.status
, s.username
, s.machine
, s.osuser
, s.program
, s.process
, s.event
FROM gv$lock l
JOIN dba_objects o ON o.object_id = l.id1
JOIN gv$session s ON s.inst_id = l.inst_id AND s.sid = l.sid
WHERE o.owner like '&&owner' ESCAPE '\'
AND o.object_name like '&&object_name' ESCAPE '\'
AND o.object_type like '&&object_type' ESCAPE '\'
&&WHERE_CLAUSE
ORDER BY object_name
;
UNDEFINE owner
UNDEFINE object_name
UNDEFINE object_type
UNDEFINE WHERE_CLAUSE
/*
* Author : Vishal Gupta
* Purpose : Displays currently locked objects in database
* Parameters : 1 - owner (% - wildchar, \ - escape char) , this could also be passed as OWNER.OBJECT_NAME
* 2 - Object name (% - wildchar, \ - escape char)
* 3 - Object Type (% - wildchar, \ - escape char)
*
* Revision History:
* ===================
* Date Author Description
* --------- ------------ -----------------------------------------
* 29-Jan-16 Vishal Gupta Switched from gv$locked_objects to gv$lock, as
* earlier view was giving information about locks on
* temporary tables (with preserve on commit rows setting).
* - Also added machine and process in the output
* 06-Sep-12 Vishal Gupta Added where clause to add more filtering
* 09-Aug-12 Vishal Gupta Created
*
*/
/************************************
* INPUT PARAMETERS
************************************/
UNDEFINE owner
UNDEFINE object_name
UNDEFINE object_type
UNDEFINE WHERE_CLAUSE
DEFINE owner="&&1"
DEFINE object_name="&&2"
DEFINE object_type="&&3"
DEFINE WHERE_CLAUSE="&&4"
COLUMN _owner NEW_VALUE owner NOPRINT
COLUMN _object_name NEW_VALUE object_name NOPRINT
COLUMN _object_type NEW_VALUE object_type NOPRINT
set term off
SELECT DECODE(UPPER('&&owner'),'','%','&&owner') "_owner"
, DECODE(UPPER('&&object_name'),'','%','&&object_name') "_object_name"
, DECODE(UPPER('&&object_type'),'','%','&&object_type') "_object_type"
FROM DUAL;
SELECT CASE
WHEN INSTR('&&owner','.') != 0 THEN SUBSTR(UPPER('&&owner'),1,INSTR('&&owner','.')-1)
ELSE DECODE(UPPER('&&owner'),'','%',UPPER('&&owner'))
END "_owner"
, CASE
WHEN INSTR('&&owner','.') != 0 THEN SUBSTR(UPPER('&&owner'),INSTR('&&owner','.')+1)
ELSE DECODE(UPPER('&&object_name'),'','%',UPPER('&&object_name'))
END "_object_name"
FROM DUAL;
set term on
PROMPT **************************************************************
PROMPT * L O C K E D O B J E C T S
PROMPT *
PROMPT * Input Parameters
PROMPT * - Owner = '&&owner'
PROMPT * - Object Name = '&&object_name'
PROMPT * - Object Type = '&&object_type'
PROMPT * - Where Clause = "&&WHERE_CLAUSE"
PROMPT **************************************************************
COLUMN object_name HEADING "ObjectName" FORMAT a40
COLUMN object_type HEADING "ObjectType" FORMAT a10 TRUNCATED
COLUMN locked_mode HEADING "LockedMode" FORMAT a10
COLUMN sid HEADING "SID" FORMAT 99999
COLUMN inst_id HEADING "I#" FORMAT 99
COLUMN spid HEADING "SPID" FORMAT a6
COLUMN status HEADING "Status" FORMAT a8
COLUMN state HEADING "State" FORMAT a12 TRUNCATED
COLUMN logon_time HEADING "Logon Time" FORMAT a18
COLUMN username HEADING "UserName" FORMAT a20
COLUMN osuser HEADING "OS User" FORMAT a15 TRUNCATED
COLUMN MACHINE HEADING "Machine" FORMAT a20 TRUNCATED
COLUMN process HEADING "Process" FORMAT a11
COLUMN program HEADING "Program" FORMAT a18 TRUNCATED
COLUMN event HEADING "Event" FORMAT a30 TRUNCATED
COLUMN last_call_et HEADING "LastCall|(sec)" FORMAT a12
COLUMN sql_child_number HEADING "SQL|Child|No" FORMAT 99
SELECT o.owner || '.' || o.object_name object_name
, o.object_type
, DECODE(l.lmode,
0, 'None', /* Mon Lock equivalent */
1, 'Null', /* N */
2, 'Row-S (SS)', /* L */
3, 'Row-X (SX)', /* R */
4, 'Share', /* S */
5, 'S/Row-X (SSX)', /* C */
6, 'Exclusive', /* X */
TO_CHAR(l.lmode)) locked_mode
, s.sid sid
, s.inst_id
, s.status
, s.username
, s.machine
, s.osuser
, s.program
, s.process
, s.event
FROM gv$lock l
JOIN dba_objects o ON o.object_id = l.id1
JOIN gv$session s ON s.inst_id = l.inst_id AND s.sid = l.sid
WHERE o.owner like '&&owner' ESCAPE '\'
AND o.object_name like '&&object_name' ESCAPE '\'
AND o.object_type like '&&object_type' ESCAPE '\'
&&WHERE_CLAUSE
ORDER BY object_name
;
UNDEFINE owner
UNDEFINE object_name
UNDEFINE object_type
UNDEFINE WHERE_CLAUSE
+85 -88
View File
@@ -1,88 +1,85 @@
@@header
/*
Author : Vishal Gupta
Purpose : Displays currently locked objects in database
* Revision History:
* ===================
* Date Author Description
* --------- ------------ -----------------------------------------
* 05-Aug-04 Vishal Gupta First Draft
* 25-Sep-09 Vishal Gupta Modified to use v$lock as DBA_LOCK might not
* exist in some databases if rdbms/admin/dbablock.sql
* has not been run.
*/
COLUMN Blocking HEADING "Bl'ing" FORMAT a6
COLUMN Blocked HEADING "Bl'ed" FORMAT a6
COLUMN Since FORMAT a18
COLUMN inst_id HEADING 'I#' FORMAT 99
rem COLUMN sid FORMAT 9999
COLUMN username FORMAT a15
COLUMN osuser FORMAT a11 TRUNC
COLUMN machine FORMAT a15
COLUMN lock_type FORMAT a22 TRUNC
COLUMN mode_held FORMAT a13
COLUMN mode_requested FORMAT a13
COLUMN mode_requested FORMAT a13
COLUMN owner FORMAT a15
COLUMN object_type FORMAT a10
COLUMN object_name FORMAT a25
SELECT /*+ RULE */
DECODE(lk.block,1,'Y',0,' ', lk.block) Blocking
, DECODE(s.lockwait,NULL,' ','Y') Blocked
-- , DECODE(block,
-- 0, 'Not Blocking', /* Not blocking any other processes */
-- 1, 'Blocking', /* This lock blocks other processes */
-- 2, 'Global', /* This lock is global, so we can't tell */
-- TO_CHAR(block)) blocking_others
, TO_CHAR(sysdate - (lk.ctime/24/60/60),'DD-MON-YY hh24:MI:SS') Since
, lk.inst_id
, lk.sid
, s.status
, s.username
, s.osuser
, NVL(t.name, lk.type) lock_type
, DECODE(lk.lmode,
0, 'None', /* Mon Lock equivalent */
1, 'Null', /* N */
2, 'Row-S (SS)', /* L */
3, 'Row-X (SX)', /* R */
4, 'Share', /* S */
5, 'S/Row-X (SSX)', /* C */
6, 'Exclusive', /* X */
TO_CHAR(lmode)) mode_held
, DECODE(request,
0, 'None', /* Mon Lock equivalent */
1, 'Null', /* N */
2, 'Row-S (SS)', /* L */
3, 'Row-X (SX)', /* R */
4, 'Share', /* S */
5, 'S/Row-X (SSX)', /* C */
6, 'Exclusive', /* X */
TO_CHAR(request)) mode_requested
, NVL(ob.object_type,' ') object_type
, NVL(ob.owner,' ') owner
, NVL(ob.object_name,' ') object_name
FROM gv$lock lk
, dba_objects ob
, gv$session s
, v$lock_type t
WHERE lk.inst_id = s.inst_id
AND lk.sid = s.sid
AND lk.id1 = ob.object_id (+)
AND lk.type = t.type (+)
AND lk.type NOT IN
(
'MR' -- Media Recovery
, 'AE' -- Edition Lock
)
-- AND (lk.block = 1 OR s.lockwait IS NOT NULL )
ORDER BY lk.block desc, s.lockwait desc , s.sid, ob.object_name
/
@@footer
/*
Author : Vishal Gupta
Purpose : Displays currently locked objects in database
* Revision History:
* ===================
* Date Author Description
* --------- ------------ -----------------------------------------
* 05-Aug-04 Vishal Gupta First Draft
* 25-Sep-09 Vishal Gupta Modified to use v$lock as DBA_LOCK might not
* exist in some databases if rdbms/admin/dbablock.sql
* has not been run.
*/
COLUMN Blocking HEADING "Bl'ing" FORMAT a6
COLUMN Blocked HEADING "Bl'ed" FORMAT a6
COLUMN Since FORMAT a18
COLUMN inst_id HEADING 'I#' FORMAT 99
rem COLUMN sid FORMAT 9999
COLUMN username FORMAT a15
COLUMN osuser FORMAT a11 TRUNC
COLUMN machine FORMAT a15
COLUMN lock_type FORMAT a22 TRUNC
COLUMN mode_held FORMAT a13
COLUMN mode_requested FORMAT a13
COLUMN mode_requested FORMAT a13
COLUMN owner FORMAT a15
COLUMN object_type FORMAT a10
COLUMN object_name FORMAT a25
SELECT /*+ RULE */
DECODE(lk.block,1,'Y',0,' ', lk.block) Blocking
, DECODE(s.lockwait,NULL,' ','Y') Blocked
-- , DECODE(block,
-- 0, 'Not Blocking', /* Not blocking any other processes */
-- 1, 'Blocking', /* This lock blocks other processes */
-- 2, 'Global', /* This lock is global, so we can't tell */
-- TO_CHAR(block)) blocking_others
, TO_CHAR(sysdate - (lk.ctime/24/60/60),'DD-MON-YY hh24:MI:SS') Since
, lk.inst_id
, lk.sid
, s.status
, s.username
, s.osuser
, NVL(t.name, lk.type) lock_type
, DECODE(lk.lmode,
0, 'None', /* Mon Lock equivalent */
1, 'Null', /* N */
2, 'Row-S (SS)', /* L */
3, 'Row-X (SX)', /* R */
4, 'Share', /* S */
5, 'S/Row-X (SSX)', /* C */
6, 'Exclusive', /* X */
TO_CHAR(lmode)) mode_held
, DECODE(request,
0, 'None', /* Mon Lock equivalent */
1, 'Null', /* N */
2, 'Row-S (SS)', /* L */
3, 'Row-X (SX)', /* R */
4, 'Share', /* S */
5, 'S/Row-X (SSX)', /* C */
6, 'Exclusive', /* X */
TO_CHAR(request)) mode_requested
, NVL(ob.object_type,' ') object_type
, NVL(ob.owner,' ') owner
, NVL(ob.object_name,' ') object_name
FROM gv$lock lk
, dba_objects ob
, gv$session s
, v$lock_type t
WHERE lk.inst_id = s.inst_id
AND lk.sid = s.sid
AND lk.id1 = ob.object_id (+)
AND lk.type = t.type (+)
AND lk.type NOT IN
(
'MR' -- Media Recovery
, 'AE' -- Edition Lock
)
-- AND (lk.block = 1 OR s.lockwait IS NOT NULL )
ORDER BY lk.block desc, s.lockwait desc , s.sid, ob.object_name
/
+96 -96
View File
@@ -1,96 +1,96 @@
/*
Author : Vishal Gupta
Purpose : Displays blocking locks in database
* Revision History:
* ===================
* Date Author Description
* --------- ------------ --------------------------------------------------------
* 19-Oct-12 Vishal Gupta Added ClientProcess in output and changed column sizing
* 18-Apr-12 Vishal Gupta Replace with gv$session with materialize hinted
* sub-query factoring (CTE - common table extression)
* 27-Feb-12 Vishal Gupta Created
*
*/
PROMPT
PROMPT *********************************
PROMPT * B L O C K I N G L O C K S
PROMPT *********************************
PROMPT
COLUMN INST_ID HEADING "I#" FORMAT 99
COLUMN SID FORMAT a30
COLUMN username HEADING "UserName" FORMAT a20 TRUNC
COLUMN lock_type HEADING "Lock|type" FORMAT a4 TRUNC
COLUMN lock_Name HEADING "Lock Name" FORMAT a22 TRUNC
COLUMN lmode HEADING "Lock|Held" FORMAT a10
COLUMN request HEADING "Lock|Request" FORMAT a10
COLUMN osuser HEADING "OSUser" FORMAT a20 TRUNC
COLUMN machine HEADING "Client|Machine" FORMAT a20 TRUNC
COLUMN process HEADING "Client|Process" FORMAT a10
COLUMN program HEADING "Program" FORMAT a30 TRUNC
COLUMN event HEADING "Event" FORMAT a30 TRUNC
--
-- Need to use Subquery for gv$session, otherwise session is disconnected with
-- ORA-07445 [qksopCheckPropOpt] when joining dynamic performance views in heirarichal query.
--
WITH sess as
( select /*+ RULE NO_MERGE */ s1.* from gv$session s1
)
, locks as
(select /*+ RULE NO_MERGE */ *
from gv$lock where lmode = 0
--AND ( lmode = 0 OR (lmode > 0 AND block > 0))
)
SELECT /*+ RULE */
s.inst_id
, DECODE(level
,1 , s.sid || ' (Blocker)'
, ' ' || LPAD('-',(level-1)*4,'|---') || '> ' || s.sid
)
sid
, s.status
, NVL2(lt.type,lt.type || ': ' , NULL)|| lt.name lock_name
, DECODE(l.lmode
,0,'None'
,1,'Null'
,2,'Row-S (SS)'
,3,'Row-X (SX)'
,4,'Share (S)'
,5,'S/Row-X (SSX)'
,6,'Excl (X)'
, l.lmode
) lmode
, DECODE(l.request
,0,'None'
,1,'Null'
,2,'Row-S (SS)'
,3,'Row-X (SX)'
,4,'Share (S)'
,5,'S/Row-X (SSX)'
,6,'Excl (X)'
, l.request
) request
, s.username
, s.sql_id
, s.machine
, s.osuser
, s.process
, s.program
, s.event
FROM sess s
LEFT OUTER JOIN locks l ON l.inst_id = s.inst_id AND l.sid = s.sid
LEFT OUTER JOIN v$lock_type lt ON l.type = lt.type
WHERE ( s.blocking_session IS NOT NULL
OR exists (select 1 from sess s2 where s2.blocking_instance = s.inst_id and s2.blocking_session = s.sid)
)
CONNECT BY PRIOR s.inst_id = s.blocking_instance
AND PRIOR s.sid = s.blocking_session
START WITH s.blocking_session IS NULL
;
/*
Author : Vishal Gupta
Purpose : Displays blocking locks in database
* Revision History:
* ===================
* Date Author Description
* --------- ------------ --------------------------------------------------------
* 19-Oct-12 Vishal Gupta Added ClientProcess in output and changed column sizing
* 18-Apr-12 Vishal Gupta Replace with gv$session with materialize hinted
* sub-query factoring (CTE - common table extression)
* 27-Feb-12 Vishal Gupta Created
*
*/
PROMPT
PROMPT *********************************
PROMPT * B L O C K I N G L O C K S
PROMPT *********************************
PROMPT
COLUMN INST_ID HEADING "I#" FORMAT 99
COLUMN SID FORMAT a30
COLUMN username HEADING "UserName" FORMAT a20 TRUNC
COLUMN lock_type HEADING "Lock|type" FORMAT a4 TRUNC
COLUMN lock_Name HEADING "Lock Name" FORMAT a22 TRUNC
COLUMN lmode HEADING "Lock|Held" FORMAT a10
COLUMN request HEADING "Lock|Request" FORMAT a10
COLUMN osuser HEADING "OSUser" FORMAT a20 TRUNC
COLUMN machine HEADING "Client|Machine" FORMAT a20 TRUNC
COLUMN process HEADING "Client|Process" FORMAT a10
COLUMN program HEADING "Program" FORMAT a30 TRUNC
COLUMN event HEADING "Event" FORMAT a30 TRUNC
--
-- Need to use Subquery for gv$session, otherwise session is disconnected with
-- ORA-07445 [qksopCheckPropOpt] when joining dynamic performance views in heirarichal query.
--
WITH sess as
( select /*+ RULE NO_MERGE */ s1.* from gv$session s1
)
, locks as
(select /*+ RULE NO_MERGE */ *
from gv$lock where lmode = 0
--AND ( lmode = 0 OR (lmode > 0 AND block > 0))
)
SELECT /*+ RULE */
s.inst_id
, DECODE(level
,1 , s.sid || ' (Blocker)'
, ' ' || LPAD('-',(level-1)*4,'|---') || '> ' || s.sid
)
sid
, s.status
, NVL2(lt.type,lt.type || ': ' , NULL)|| lt.name lock_name
, DECODE(l.lmode
,0,'None'
,1,'Null'
,2,'Row-S (SS)'
,3,'Row-X (SX)'
,4,'Share (S)'
,5,'S/Row-X (SSX)'
,6,'Excl (X)'
, l.lmode
) lmode
, DECODE(l.request
,0,'None'
,1,'Null'
,2,'Row-S (SS)'
,3,'Row-X (SX)'
,4,'Share (S)'
,5,'S/Row-X (SSX)'
,6,'Excl (X)'
, l.request
) request
, s.username
, s.sql_id
, s.machine
, s.osuser
, s.process
, s.program
, s.event
FROM sess s
LEFT OUTER JOIN locks l ON l.inst_id = s.inst_id AND l.sid = s.sid
LEFT OUTER JOIN v$lock_type lt ON l.type = lt.type
WHERE ( s.blocking_session IS NOT NULL
OR exists (select 1 from sess s2 where s2.blocking_instance = s.inst_id and s2.blocking_session = s.sid)
)
CONNECT BY PRIOR s.inst_id = s.blocking_instance
AND PRIOR s.sid = s.blocking_session
START WITH s.blocking_session IS NULL
;
+377
View File
@@ -0,0 +1,377 @@
[
{
"filename": "arch_size_hourly.sql",
"path": "unpack/arch_size_hourly.sql",
"lines": 130
},
{
"filename": "arch_size_hourly_detail.sql",
"path": "unpack/arch_size_hourly_detail.sql",
"lines": 93
},
{
"filename": "arch_switch_hist.sql",
"path": "unpack/arch_switch_hist.sql",
"lines": 81
},
{
"filename": "ash_wait_chains.sql",
"path": "unpack/ash_wait_chains.sql",
"lines": 143
},
{
"filename": "ashtop.sql",
"path": "unpack/ashtop.sql",
"lines": 133
},
{
"filename": "asqlmon.sql",
"path": "unpack/asqlmon.sql",
"lines": 111
},
{
"filename": "awr_snapshot.sql",
"path": "unpack/awr_snapshot.sql",
"lines": 2
},
{
"filename": "awr_sql_binds.sql",
"path": "unpack/awr_sql_binds.sql",
"lines": 131
},
{
"filename": "awr_sqlid.sql",
"path": "unpack/awr_sqlid.sql",
"lines": 12
},
{
"filename": "awrsign.sql",
"path": "unpack/awrsign.sql",
"lines": 55
},
{
"filename": "awrsqlid.sql",
"path": "unpack/awrsqlid.sql",
"lines": 53
},
{
"filename": "awrsqlidtabstat.sql",
"path": "unpack/awrsqlidtabstat.sql",
"lines": 48
},
{
"filename": "blockers.sql",
"path": "unpack/blockers.sql",
"lines": 65
},
{
"filename": "coe_xfr_sql_profile.sql",
"path": "unpack/coe_xfr_sql_profile.sql",
"lines": 499
},
{
"filename": "colored_sql_id.sql",
"path": "unpack/colored_sql_id.sql",
"lines": 6
},
{
"filename": "create_spb_from_awr.sql",
"path": "unpack/create_spb_from_awr.sql",
"lines": 110
},
{
"filename": "create_spb_from_cur.sql",
"path": "unpack/create_spb_from_cur.sql",
"lines": 25
},
{
"filename": "dash_wait_chains.sql",
"path": "unpack/dash_wait_chains.sql",
"lines": 137
},
{
"filename": "dashtop.sql",
"path": "unpack/dashtop.sql",
"lines": 146
},
{
"filename": "dasqlmon.sql",
"path": "unpack/dasqlmon.sql",
"lines": 107
},
{
"filename": "date.sql",
"path": "unpack/date.sql",
"lines": 11
},
{
"filename": "dba_invalid_objects.sql",
"path": "unpack/dba_invalid_objects.sql",
"lines": 63
},
{
"filename": "dba_registry.sql",
"path": "unpack/dba_registry.sql",
"lines": 62
},
{
"filename": "dblinks.sql",
"path": "unpack/dblinks.sql",
"lines": 16
},
{
"filename": "dg_stats.sql",
"path": "unpack/dg_stats.sql",
"lines": 82
},
{
"filename": "fish.sql",
"path": "unpack/fish.sql",
"lines": 44
},
{
"filename": "h.sql",
"path": "unpack/h.sql",
"lines": 167
},
{
"filename": "hint.sql",
"path": "unpack/hint.sql",
"lines": 22
},
{
"filename": "i.sql",
"path": "unpack/i.sql",
"lines": 95
},
{
"filename": "imp_sql_profile.sql",
"path": "unpack/imp_sql_profile.sql",
"lines": 46
},
{
"filename": "init.sql",
"path": "unpack/init.sql",
"lines": 203
},
{
"filename": "locked_objects.sql",
"path": "unpack/locked_objects.sql",
"lines": 123
},
{
"filename": "locks.sql",
"path": "unpack/locks.sql",
"lines": 85
},
{
"filename": "locks_blocking.sql",
"path": "unpack/locks_blocking.sql",
"lines": 96
},
{
"filename": "log.sql",
"path": "unpack/log.sql",
"lines": 10
},
{
"filename": "login.sql",
"path": "unpack/login.sql",
"lines": 11
},
{
"filename": "nonshared.sql",
"path": "unpack/nonshared.sql",
"lines": 60
},
{
"filename": "o.sql",
"path": "unpack/o.sql",
"lines": 39
},
{
"filename": "otherxml.sql",
"path": "unpack/otherxml.sql",
"lines": 13
},
{
"filename": "pardef.sql",
"path": "unpack/pardef.sql",
"lines": 88
},
{
"filename": "planx.sql",
"path": "unpack/planx.sql",
"lines": 1379
},
{
"filename": "raclocks.sql",
"path": "unpack/raclocks.sql",
"lines": 78
},
{
"filename": "recovery_area_usage.sql",
"path": "unpack/recovery_area_usage.sql",
"lines": 66
},
{
"filename": "s.sql",
"path": "unpack/s.sql",
"lines": 83
},
{
"filename": "sed.sql",
"path": "unpack/sed.sql",
"lines": 35
},
{
"filename": "sess.sql",
"path": "unpack/sess.sql",
"lines": 72
},
{
"filename": "sessa.sql",
"path": "unpack/sessa.sql",
"lines": 76
},
{
"filename": "sid_details.sql",
"path": "unpack/sid_details.sql",
"lines": 679
},
{
"filename": "sql_plan_baselines.sql",
"path": "unpack/sql_plan_baselines.sql",
"lines": 71
},
{
"filename": "sql_profile.sql",
"path": "unpack/sql_profile.sql",
"lines": 47
},
{
"filename": "sql_profile_detail.sql",
"path": "unpack/sql_profile_detail.sql",
"lines": 56
},
{
"filename": "sql_profile_hints.sql",
"path": "unpack/sql_profile_hints.sql",
"lines": 35
},
{
"filename": "sqlbinds.sql",
"path": "unpack/sqlbinds.sql",
"lines": 42
},
{
"filename": "sqlid.sql",
"path": "unpack/sqlid.sql",
"lines": 80
},
{
"filename": "sqlid_sign.sql",
"path": "unpack/sqlid_sign.sql",
"lines": 6
},
{
"filename": "sqlidtabstat.sql",
"path": "unpack/sqlidtabstat.sql",
"lines": 48
},
{
"filename": "sqltt_sqlid.sql",
"path": "unpack/sqltt_sqlid.sql",
"lines": 38
},
{
"filename": "stats_getpref_table.sql",
"path": "unpack/stats_getpref_table.sql",
"lines": 37
},
{
"filename": "stats_history.sql",
"path": "unpack/stats_history.sql",
"lines": 273
},
{
"filename": "tab_details.sql",
"path": "unpack/tab_details.sql",
"lines": 360
},
{
"filename": "tabstat.sql",
"path": "unpack/tabstat.sql",
"lines": 46
},
{
"filename": "tbs.sql",
"path": "unpack/tbs.sql",
"lines": 182
},
{
"filename": "tpardef.sql",
"path": "unpack/tpardef.sql",
"lines": 45
},
{
"filename": "tpstat.sql",
"path": "unpack/tpstat.sql",
"lines": 55
},
{
"filename": "transaction_long_running.sql",
"path": "unpack/transaction_long_running.sql",
"lines": 136
},
{
"filename": "tspstat.sql",
"path": "unpack/tspstat.sql",
"lines": 59
},
{
"filename": "unusable.sql",
"path": "unpack/unusable.sql",
"lines": 19
},
{
"filename": "usess.sql",
"path": "unpack/usess.sql",
"lines": 60
},
{
"filename": "wrka.sql",
"path": "unpack/wrka.sql",
"lines": 48
},
{
"filename": "wrkasum.sql",
"path": "unpack/wrkasum.sql",
"lines": 71
},
{
"filename": "xawr.sql",
"path": "unpack/xawr.sql",
"lines": 4
},
{
"filename": "xb.sql",
"path": "unpack/xb.sql",
"lines": 358
},
{
"filename": "xbi.sql",
"path": "unpack/xbi.sql",
"lines": 365
},
{
"filename": "xlast.sql",
"path": "unpack/xlast.sql",
"lines": 4
},
{
"filename": "xplan.sql",
"path": "unpack/xplan.sql",
"lines": 48
}
]
+36 -1
View File
@@ -1,4 +1,39 @@
-- Copyright 2018 Tanel Poder. All rights reserved. More info at http://tanelpoder.com
-- Licensed under the Apache License, Version 2.0. See LICENSE.txt for terms & conditions.
@@o2 "%&1%"
col o_owner heading owner for a25
col o_object_name heading object_name for a30
col o_object_type heading object_type for a20
col o_status heading status for a9
select
owner o_owner,
object_name o_object_name,
object_type o_object_type,
status o_status,
object_id oid,
data_object_id d_oid,
created,
last_ddl_time
from
dba_objects
where
upper(object_name) LIKE
upper(CASE
WHEN INSTR('&1','.') > 0 THEN
SUBSTR('&1',INSTR('&1','.')+1)
ELSE
'&1'
END
)
AND owner LIKE
CASE WHEN INSTR('&1','.') > 0 THEN
UPPER(SUBSTR('&1',1,INSTR('&1','.')-1))
ELSE
user
END
order by
o_object_name,
o_owner,
o_object_type
/
+13
View File
@@ -0,0 +1,13 @@
-- Copyright 2018 Tanel Poder. All rights reserved. More info at http://tanelpoder.com
-- Licensed under the Apache License, Version 2.0. See LICENSE.txt for terms & conditions.
select
xmltype(other_xml)
from
gv$sql_plan
where
sql_id = '&1'
and child_number = TO_NUMBER('&2')
and other_xml is not null
/
+14 -11
View File
@@ -1,12 +1,16 @@
/*
2024-01-27 vplesnila: script creation
*/
set lines 256 pages 50
col TABLE_OWNER for a25 heading "Owner"
col TABLE_NAME for a30 heading "Table"
col OWNER for a25 heading "Owner"
col INDEX_NAME for a30 heading "Index"
col INDEX_TYPE for a10 heading "Type"
col PARTITIONED for a3 heading "Par"
col PARTITION_POSITION for 999 heading "P#"
col PARTITION_POSITION for 999 heading "P#"
col PARTITION_NAME for a30 heading "Partition"
col SUBPARTITION_NAME for a30 heading "Subpartition"
col PART_HIGHVAL for a32 trunc heading "Partition|high value"
@@ -25,10 +29,10 @@ prompt
prompt Table
prompt =====
select
select
par.TABLE_OWNER
,par.TABLE_NAME
,par.PARTITION_POSITION
,par.PARTITION_POSITION
,par.PARTITION_NAME
,par.NUM_ROWS
,par.HIGH_VALUE PART_HIGHVAL
@@ -37,13 +41,13 @@ select
,sub.NUM_ROWS
,sub.HIGH_VALUE SUBPART_HIGHVAL
,sub.INTERVAL SUBPART_INTERVAL
from
dba_tab_partitions par
left outer join dba_tab_subpartitions sub
from
dba_tab_partitions par
left outer join dba_tab_subpartitions sub
on (par.TABLE_OWNER=sub.TABLE_OWNER) and (par.TABLE_NAME=sub.TABLE_NAME) and(par.PARTITION_NAME=sub.PARTITION_NAME)
where
where
par.table_owner='&&v_table_owner'
and par.table_name='&&v_table_name'
and par.table_name='&&v_table_name'
order by
par.PARTITION_POSITION asc
,sub.SUBPARTITION_POSITION asc
@@ -55,8 +59,7 @@ prompt =====
select
ind.OWNER
,ind.INDEX_NAME
,ind.INDEX_TYPE
,ind.STATUS
,indpar.STATUS
,ind.PARTITIONED
,ind.NUM_ROWS
,ind.DISTINCT_KEYS
+1379 -1409
View File
File diff suppressed because it is too large Load Diff
+1 -3
View File
@@ -1,7 +1,5 @@
-- https://easyteam.fr/dealing-with-lock-issues-in-oracle-rac-environnement/
@@myheader.sql
col running_session for a20
col machine for a30
col osuser for a20
@@ -77,4 +75,4 @@ rs
JOIN
s ON ltrim(rs.running_session)=s.inst_id || '-' || s.sid;
@@myfooter.sql
+66 -66
View File
@@ -1,66 +1,66 @@
/*
*
* Author : Vishal Gupta
* Purpose : Display Recovery Area Usage
* Compatibility : 11.2 and above
* Parameters : NONE
*
* Revision History:
* ===================
* Date Author Description
* --------- ------------ -----------------------------------------
* 22-Jan-16 Vishal Gupta Added total computation
* 02-May-13 Vishal Gupta Updated to display space used in GB
* 30-Jul-12 Vishal Gupta Created
*
*/
PROMPT *****************************************************************
PROMPT * R E C O V E R Y A R E A U S A G E
PROMPT *****************************************************************
COLUMN inst_id HEADING "I#" FORMAT 99
COLUMN name HEADING "Name" FORMAT a28
COLUMN value HEADING "Value" FORMAT a15
COLUMN type HEADING "Type" FORMAT a10
COLUMN ordinal HEADING "Ordinal" FORMAT 99
COLUMN isdefault HEADING "Def|ault?" FORMAT a5
COLUMN ismodified HEADING "Modi|fied?" FORMAT a8
COLUMN isadjusted HEADING "Adjus|ted?" FORMAT a5
SELECT p.inst_id
, p.name
, TRIM(TO_CHAR(ROUND(p.value / 1024 / 1024 / 1024),'999,999') || ' GB') value
FROM gv$system_parameter p
WHERE p.name = 'db_recovery_file_dest_size'
ORDER BY p.inst_id
;
COLUMN file_type HEADING "File Type" FORMAT a25
COLUMN number_of_files HEADING "Files (#)" FORMAT 999,999,999
COLUMN space_used HEADING "Space|Used|(MB)" FORMAT 999,999,999
COLUMN space_reclaimable HEADING "Space|Reclaimable|(MB)" FORMAT 999,999,999
COLUMN percent_space_used HEADING "Space|Used|(%)" FORMAT 999.99
COLUMN percent_space_reclaimable HEADING "Space|Reclaimable|(%)" FORMAT 999.99
BREAK ON REPORT
COMPUTE SUM LABEL 'Total' OF number_of_files FORMAT 999,999,999 ON REPORT
COMPUTE SUM LABEL 'Total' OF space_used FORMAT 999,999,999 ON REPORT
COMPUTE SUM LABEL 'Total' OF space_reclaimable FORMAT 999,999,999 ON REPORT
COMPUTE SUM LABEL 'Total' OF percent_space_used FORMAT 999.99 ON REPORT
COMPUTE SUM LABEL 'Total' OF percent_space_reclaimable FORMAT 999.99 ON REPORT
SELECT r.file_type
, r.number_of_files
, ROUND(r.percent_space_used * p.value / 100 / 1024 / 1024) space_used
, ROUND(r.percent_space_reclaimable * p.value / 100 / 1024 / 1024) space_reclaimable
, r.percent_space_used
, r.percent_space_reclaimable
FROM v$recovery_area_usage r
, v$system_parameter p
WHERE p.name = 'db_recovery_file_dest_size'
;
/*
*
* Author : Vishal Gupta
* Purpose : Display Recovery Area Usage
* Compatibility : 11.2 and above
* Parameters : NONE
*
* Revision History:
* ===================
* Date Author Description
* --------- ------------ -----------------------------------------
* 22-Jan-16 Vishal Gupta Added total computation
* 02-May-13 Vishal Gupta Updated to display space used in GB
* 30-Jul-12 Vishal Gupta Created
*
*/
PROMPT *****************************************************************
PROMPT * R E C O V E R Y A R E A U S A G E
PROMPT *****************************************************************
COLUMN inst_id HEADING "I#" FORMAT 99
COLUMN name HEADING "Name" FORMAT a28
COLUMN value HEADING "Value" FORMAT a15
COLUMN type HEADING "Type" FORMAT a10
COLUMN ordinal HEADING "Ordinal" FORMAT 99
COLUMN isdefault HEADING "Def|ault?" FORMAT a5
COLUMN ismodified HEADING "Modi|fied?" FORMAT a8
COLUMN isadjusted HEADING "Adjus|ted?" FORMAT a5
SELECT p.inst_id
, p.name
, TRIM(TO_CHAR(ROUND(p.value / 1024 / 1024 / 1024),'999,999') || ' GB') value
FROM gv$system_parameter p
WHERE p.name = 'db_recovery_file_dest_size'
ORDER BY p.inst_id
;
COLUMN file_type HEADING "File Type" FORMAT a25
COLUMN number_of_files HEADING "Files (#)" FORMAT 999,999,999
COLUMN space_used HEADING "Space|Used|(MB)" FORMAT 999,999,999
COLUMN space_reclaimable HEADING "Space|Reclaimable|(MB)" FORMAT 999,999,999
COLUMN percent_space_used HEADING "Space|Used|(%)" FORMAT 999.99
COLUMN percent_space_reclaimable HEADING "Space|Reclaimable|(%)" FORMAT 999.99
BREAK ON REPORT
COMPUTE SUM LABEL 'Total' OF number_of_files FORMAT 999,999,999 ON REPORT
COMPUTE SUM LABEL 'Total' OF space_used FORMAT 999,999,999 ON REPORT
COMPUTE SUM LABEL 'Total' OF space_reclaimable FORMAT 999,999,999 ON REPORT
COMPUTE SUM LABEL 'Total' OF percent_space_used FORMAT 999.99 ON REPORT
COMPUTE SUM LABEL 'Total' OF percent_space_reclaimable FORMAT 999.99 ON REPORT
SELECT r.file_type
, r.number_of_files
, ROUND(r.percent_space_used * p.value / 100 / 1024 / 1024) space_used
, ROUND(r.percent_space_reclaimable * p.value / 100 / 1024 / 1024) space_reclaimable
, r.percent_space_used
, r.percent_space_reclaimable
FROM v$recovery_area_usage r
, v$system_parameter p
WHERE p.name = 'db_recovery_file_dest_size'
;
+4 -1
View File
@@ -26,6 +26,9 @@ col sw_p3 head P3 for a19 justify left word_wrap
col sw_blocking_session head BLOCKING_SID for a12
col sqlid_and_child for a20
col seq# for 999999
select
sid sw_sid,
sql_id || ' '|| TO_CHAR( sql_child_number ) sqlid_and_child,
@@ -68,7 +71,7 @@ select
ELSE NULL END
ELSE NULL END AS sw_p1transl
FROM
v$session
gv$session
WHERE
sid IN (&1)
ORDER BY
+35
View File
@@ -0,0 +1,35 @@
-- Copyright 2018 Tanel Poder. All rights reserved. More info at http://tanelpoder.com
-- Licensed under the Apache License, Version 2.0. See LICENSE.txt for terms & conditions.
prompt Show wait event descriptions matching &1...
col sed_name head EVENT_NAME for a55
col sed_p1 head PARAMETER1 for a25
col sed_p2 head PARAMETER2 for a25
col sed_p3 head PARAMETER3 for a25
col sed_event# head EVENT# for 99999
col sed_req_description HEAD REQ_DESCRIPTION for a100 WORD_WRAP
col sed_req_reason HEAD REQ_REASON for a32 WRAP
col sed_wait_class HEAD WAIT_CLASS for a20
col sed_eq_name HEAD ENQUEUE_NAME for a30
SELECT
e.event# sed_event#
, e.name sed_name
, e.wait_class sed_wait_class
, e.parameter1 sed_p1
, e.parameter2 sed_p2
, e.parameter3 sed_p3
, s.eq_name sed_eq_name
, s.req_reason sed_req_reason
, s.req_description sed_req_description
-- , e.display_name sed_display_name -- 12c
FROM
v$event_name e
, v$enqueue_statistics s
WHERE
e.event# = s.event# (+)
AND lower(e.name) like lower('&1')
ORDER BY
sed_name
/
+1 -1
View File
@@ -28,7 +28,7 @@ SET ECHO OFF
SET FEEDBACK 6
SET HEADING ON
-- SET LINESIZE 180
-- SET PAGESIZE 50000
SET PAGESIZE 50000
SET TERMOUT ON
SET TIMING OFF
SET TRIMOUT ON
+1 -1
View File
@@ -29,7 +29,7 @@ SET ECHO OFF
SET FEEDBACK 6
SET HEADING ON
-- SET LINESIZE 180
-- SET PAGESIZE 50000
SET PAGESIZE 50000
SET TERMOUT ON
SET TIMING OFF
SET TRIMOUT ON
+679 -675
View File
File diff suppressed because it is too large Load Diff
+42 -23
View File
@@ -1,37 +1,54 @@
/*
* vplesnila 2025-05 - creation
* Based on Vishal Gupta script
* and other documents:
* - https://www.linkedin.com/pulse/efficiently-converting-sql-statements-sqlids-oracle-database-pandey-fwmff
* - https://franckpachot.medium.com/oracle-dba-sql-plan-baseline-sql-id-and-plan-hash-value-8ffa811a7c68
*
* Author : Vishal Gupta
* Purpose : Display all SQL PLAN Baselines
* Parameters :
*
*
* Revision History:
* ===================
* Date Author Description
* --------- ------------ -----------------------------------------
* 12-Jun-12 Vishal Gupta First created
*
*
* Usage: @sql_plan_baselines.sql <where_clause>
* Examples:
* @sql_plan_baselines.sql "1=1"
* @sql_plan_baselines.sql "accepted='YES' and Last_Modified >(sysdate-1)"
* @sql_plan_baselines.sql "plan_hash_value=237994299"
* @sql_plan_baselines.sql "sql_id='g3gwhhx6r00qc'"
*/
COLUMN sql_id HEADING "SQL_ID" FORMAT a14
COLUMN sql_handle HEADING "SQL Handle" FORMAT a20
COLUMN plan_hash_value HEADING 'Plan|Hash Value' FORMAT 9999999999
COLUMN plan_name HEADING "Plan Name" FORMAT a30
COLUMN enabled HEADING "Ena|bled" FORMAT a4
COLUMN accepted HEADING "Accep|ted" FORMAT a5
COLUMN fixed HEADING "Fixed" FORMAT a5
COLUMN reproduced HEADING "Repro|duced" FORMAT a5
COLUMN autopurge HEADING "Auto|Purge" FORMAT a5
COLUMN optimizer_cost HEADING "Optimizer|Cost" FORMAT 99999999
COLUMN creator HEADING "Creator" FORMAT a12
COLUMN created HEADING "Created" FORMAT a15
COLUMN last_modified HEADING "LastModified" FORMAT a15
COLUMN last_executed HEADING "LastExecuted" FORMAT a15
COLUMN last_verified HEADING "LastVerified" FORMAT a15
COLUMN creator HEADING "Creator" FORMAT a13
COLUMN created HEADING "Created" FORMAT a19
COLUMN last_modified HEADING "LastModified" FORMAT a19
COLUMN last_executed HEADING "LastExecuted" FORMAT a19
COLUMN last_verified HEADING "LastVerified" FORMAT a19
COLUMN force_matching HEADING "Force|Match" FORMAT a5
COLUMN signature HEADING "Signature" FORMAT 999999999999999999999
COLUMN description HEADING "Description" FORMAT a50
BREAK ON name ON CATEGORY ON created ON last_modified ON type ON status ON force_matching ON signature ON description
SELECT spb.sql_handle
select * from (
SELECT
dbms_sql_translator.sql_id(sql_text) sql_id
,(select
case
when instr(plan_table_output, ':') > 0 then to_number(substr(plan_table_output, instr(plan_table_output, ':', -1) + 1))
else to_number(plan_table_output)
end as last_value
from
(
select * from table(dbms_xplan.DISPLAY_SQL_PLAN_BASELINE(sql_handle,plan_name)) where plan_table_output like 'Plan hash value: %'
)
) plan_hash_value
, spb.sql_handle
, spb.plan_name
, spb.origin
, spb.enabled
@@ -41,12 +58,14 @@ SELECT spb.sql_handle
, spb.autopurge
, spb.optimizer_cost
, spb.creator
, to_char(spb.created,'DD-MON-YY HH24:MI') created
, to_char(spb.last_modified,'DD-MON-YY HH24:MI') last_modified
, to_char(spb.last_executed,'DD-MON-YY HH24:MI') last_executed
, to_char(spb.last_verified,'DD-MON-YY HH24:MI') last_verified
, to_char(spb.created,'YYYY-MM-DD HH24:MI:SS') created
, to_char(spb.last_modified,'YYYY-MM-DD HH24:MI:SS') last_modified
, to_char(spb.last_executed,'YYYY-MM-DD HH24:MI:SS') last_executed
, to_char(spb.last_verified,'YYYY-MM-DD HH24:MI:SS') last_verified
, spb.description
FROM dba_sql_plan_baselines spb
ORDER BY spb.last_modified DESC
)
WHERE
&1
ORDER BY last_modified DESC
;
+2 -1
View File
@@ -1,7 +1,7 @@
/*
*
* Author : Vishal Gupta
* Purpose : Display all SQL Profiles
* Purpose : Display SQL Profiles detail
* Parameters :
*
*
@@ -53,3 +53,4 @@ ORDER BY sp.last_modified DESC
;
set heading on
+42
View File
@@ -0,0 +1,42 @@
-- Copyright 2018 Tanel Poder. All rights reserved. More info at http://tanelpoder.com
-- Licensed under the Apache License, Version 2.0. See LICENSE.txt for terms & conditions.
prompt Show captured binds from GV$SQL_BIND_CAPTURE...
COL sqlbinds_name HEAD NAME FOR A15
COL value_string FOR A100
COL value_anydata FOR A100
COL sqlbinds_pos HEAD POS FOR 9999
COL sqlbinds_chld HEAD CHLD FOR 9999
COL sqlbinds_datatype HEAD DATATYPE FOR A15
BREAK ON sqlbinds_chld SKIP 1
SELECT
-- ADDRESS parent_cursor
-- SQL_ID
CHILD_NUMBER sqlbinds_chld
, POSITION sqlbinds_pos
, NAME sqlbinds_name
--, DUP_POSITION
--, DATATYPE
, DATATYPE_STRING sqlbinds_datatype
, CHARACTER_SID
, MAX_LENGTH
, PRECISION
, SCALE
, VALUE_STRING
, WAS_CAPTURED
, LAST_CAPTURED
, VALUE_ANYDATA
FROM
gv$sql_bind_capture c
WHERE
sql_id like '&1'
AND child_number like '&2'
AND (c.name like '&3' escape '\' OR REGEXP_LIKE(name, '&3', 'i'))
ORDER BY
address
, sql_id
, child_number
, position
/
+7 -3
View File
@@ -12,23 +12,26 @@ col pios_per_exec FOR 9999999999
prompt Show SQL text, child cursors and execution stats for SQLID &1 child &2
select
select
inst_id,
hash_value,
plan_hash_value,
child_number sql_child_number,
sql_text sql_sql_text
from
v$sql
gv$sql
where
sql_id = ('&1')
and child_number like '&2'
order by
inst_id,
sql_id,
hash_value,
child_number
/
select
inst_id,
child_number sql_child_number,
plan_hash_value plan_hash,
parse_calls parses,
@@ -64,11 +67,12 @@ select
, address parent_handle
, child_address object_handle
from
v$sql
gv$sql
where
sql_id = ('&1')
and child_number like '&2'
order by
inst_id,
sql_id,
hash_value,
child_number
+1 -2
View File
@@ -2,6 +2,5 @@ col FORCE_MATCHING_SIGNATURE for 99999999999999999999
select FORCE_MATCHING_SIGNATURE from gv$sql where sql_id='&&1'
union all
select FORCE_MATCHING_SIGNATURE from DBA_HIST_SQLSTAT where sql_id='&&1'
select FORCE_MATCHING_SIGNATURE from DBA_HIST_SQLSTAT where sql_id='&&1'
fetch first 1 rows only;
+4 -5
View File
@@ -11,14 +11,14 @@ column object_type format a40
column owner format a40
with plan_tables as (
select distinct object_name,object_owner, object_type
from gv$sql_plan
where object_type like 'TABLE%'
select distinct object_name,object_owner, object_type
from gv$sql_plan
where object_type like 'TABLE%'
and sql_id = '&1')
select t.object_owner owner,
t.object_name table_name,
t.object_type object_type,
decode(stale_stats,'NO','OK',NULL, 'NO STATS!', 'STALE!') staleness
decode(stale_stats,'NO','OK',NULL, 'NO STATS!', 'STALE!') staleness
from dba_tab_statistics s,
plan_tables t
where s.table_name = t.object_name
@@ -46,4 +46,3 @@ and s.owner = i.object_owner
and s.partition_name is null
and s.subpartition_name is null
order by i.object_owner, i.object_name;
+37
View File
@@ -0,0 +1,37 @@
SET SERVEROUTPUT ON
DECLARE
PROCEDURE display(p_param IN VARCHAR2) AS
l_result VARCHAR2(50);
BEGIN
l_result := DBMS_STATS.get_prefs (pname=>p_param,ownname=>'&1',tabname=>'&2');
DBMS_OUTPUT.put_line(RPAD(p_param, 30, ' ') || ' : ' || l_result);
END;
BEGIN
display('APPROXIMATE_NDV_ALGORITHM');
display('AUTO_STAT_EXTENSIONS');
display('AUTO_TASK_STATUS');
display('AUTO_TASK_MAX_RUN_TIME');
display('AUTO_TASK_INTERVAL');
display('CASCADE');
display('CONCURRENT');
display('DEGREE');
display('ESTIMATE_PERCENT');
display('GLOBAL_TEMP_TABLE_STATS');
display('GRANULARITY');
display('INCREMENTAL');
display('INCREMENTAL_STALENESS');
display('INCREMENTAL_LEVEL');
display('METHOD_OPT');
display('NO_INVALIDATE');
display('OPTIONS');
display('PREFERENCE_OVERRIDES_PARAMETER');
display('PUBLISH');
display('STALE_PERCENT');
display('STAT_CATEGORY');
display('TABLE_CACHED_BLOCKS');
display('STALE_PERCENT');
display('WAIT_TIME_TO_UPDATE_STATS');
END;
/
+273 -273
View File
@@ -1,273 +1,273 @@
/*
*
* Author : Vishal Gupta
* Purpose : Display table statistics history
* Parameters : 1 - OWNER (% - wildchar, \ - escape char)
* 2 - Object Name (% - wildchar, \ - escape char)
* 3 - Partition Name (% - wildchar, \ - escape char)
* 5 - Object Type (% - wildchar, \ - escape char)
*
*
* Revision History:
* ===================
* Date Author Description
* --------- ------------ -----------------------------------------
* 08-Jul-15 Vishal Gupta Removed savetime column from output
* 19-JUN-14 Vishal Gupta Updated AvgRowLength heading
* 28-FEB-14 Vishal Gupta Changed the ordering
* 02-Jul-12 Vishal Gupta Added partition, sub-partition and objecttype as input
* 30-Apr-12 Vishal Gupta Created
*
*/
/************************************
* INPUT PARAMETERS
************************************/
UNDEFINE owner
UNDEFINE object_name
UNDEFINE subobject_name
UNDEFINE object_type
DEFINE owner="&&1"
DEFINE object_name="&&2"
DEFINE subobject_name="&&3"
DEFINE object_type="&&4"
COLUMN _owner NEW_VALUE owner NOPRINT
COLUMN _object_name NEW_VALUE object_name NOPRINT
COLUMN _subobject_name NEW_VALUE subobject_name NOPRINT
COLUMN _object_type NEW_VALUE object_type NOPRINT
set term off
SELECT CASE
WHEN INSTR('&&owner','.') != 0 THEN SUBSTR(UPPER('&&owner'),1,INSTR('&&owner','.')-1)
ELSE DECODE(UPPER('&&owner'),'','%',UPPER('&&owner'))
END "_owner"
, CASE
WHEN INSTR('&&owner','.') != 0 THEN SUBSTR(UPPER('&&owner'),INSTR('&&owner','.')+1)
ELSE DECODE(UPPER('&&object_name'),'','%',UPPER('&&object_name'))
END "_object_name"
, DECODE('&&subobject_name','','%','&&subobject_name') "_subobject_name"
, DECODE('&&object_type','','%','&&object_type') "_object_type"
FROM DUAL
;
set term on
PROMPT
PROMPT ***********************************************************************
PROMPT * S T A T I S T I C S H I S T O R Y
PROMPT *
PROMPT * Input Parameters
PROMPT * - Object Owner = '&&owner'
PROMPT * - Object Name = '&&object_name'
PROMPT * - SubObject Name = '&&subobject_name'
PROMPT * - Object Type = '&&object_type'
PROMPT ***********************************************************************
COLUMN object_name HEADING "ObjectName" FORMAT a60
COLUMN subobject_name HEADING "SubObjectName" FORMAT a30
COLUMN object_type HEADING "Object|Type" FORMAT a18
COLUMN object_type_sort_order NOPRINT
COLUMN savtime HEADING "SaveTime" FORMAT a18
COLUMN ANALYZETIME HEADING "AnalyzeTime" FORMAT a18
COLUMN samplesize HEADING "SampleSize" FORMAT 999,999,999,999
COLUMN rowcnt HEADING "RowCount" FORMAT 999,999,999,999
COLUMN blkcnt HEADING "BlockCount" FORMAT 999,999,999
COLUMN avgrln HEADING "Avg|Row|Length" FORMAT 999,999
COLUMN SizeMB HEADING "Size (MB)" FORMAT 9,999,999
select object_name
, object_type
, object_type_sort_order
--, to_char(savtime,'DD-MON-YY HH24:MI:SS') savtime
, to_char(ANALYZETIME,'DD-MON-YY HH24:MI:SS') ANALYZETIME
, SizeMB
, rowcnt
, avgrln
--, blkcnt
, samplesize
FROM
(
select o.owner || '.' || o.object_name
|| NVL2(o.subobject_name,':' || o.subobject_name, '')
object_name
, o.object_type
, DECODE (o.object_type
, 'TABLE' ,1
, 'TABLE PARTITION' ,2
, 'TABLE SUBPARTITION' ,3
, 'INDEX' ,4
, 'INDEX PARTITION' ,5
, 'INDEX SUBPARTITION' ,6
,9
) object_type_sort_order
, h.savtime
, h.ANALYZETIME
, h.samplesize
, h.rowcnt
, h.avgrln
, (h.blkcnt * p.value) /1024/1024 SizeMB
, h.blkcnt
FROM sys.wri$_optstat_tab_history h
, dba_objects o
, v$system_parameter p
WHERE h.obj# = o.object_id
AND p.name = 'db_block_size'
AND o.owner LIKE upper('&&owner') ESCAPE '\'
AND o.object_name LIKE upper('&&object_name') ESCAPE '\'
AND NVL(o.subobject_name,'%') LIKE upper('&&subobject_name') ESCAPE '\'
AND NVL(DECODE(o.object_type
,'PARTITION','TABLE PARTITION'
,'SUBPARTITION','TABLE SUBPARTITION'
,o.object_type),'%') LIKE upper('&&object_type') ESCAPE '\'
UNION
select s.owner || '.' || s.table_name
|| NVL2(s.partition_name,':' || s.partition_name, '')
object_name
, DECODE(s.object_type
,'PARTITION','TABLE PARTITION'
,'SUBPARTITION','TABLE SUBPARTITION'
,s.object_type) object_type
, DECODE (s.object_type
, 'TABLE' ,1
, 'TABLE PARTITION' ,2
, 'TABLE SUBPARTITION' ,3
, 'INDEX' ,4
, 'INDEX PARTITION' ,5
, 'INDEX SUBPARTITION' ,6
,9
) object_type_sort_order
, NULL savtime
, last_analyzed ANALYZETIME
, sample_size
, num_rows
, avg_row_len
, (s.blocks * p.value) /1024/1024 SizeMB
, s.blocks
FROM dba_tab_statistics s
, v$system_parameter p
WHERE p.name = 'db_block_size'
AND s.owner LIKE upper('&&owner') ESCAPE '\'
AND s.table_name LIKE upper('&&object_name') ESCAPE '\'
AND NVL(s.partition_name,'%') LIKE upper('&&subobject_name') ESCAPE '\'
AND NVL(DECODE(s.object_type
,'PARTITION','TABLE PARTITION'
,'SUBPARTITION','TABLE SUBPARTITION'
,s.object_type),'%') LIKE upper('&&object_type') ESCAPE '\'
) a
ORDER BY a.object_name
, a.object_type_sort_order
, a.savtime NULLS LAST
--, a.ANALYZETIME
/
COLUMN table_name HEADING "IndexName" FORMAT a40
COLUMN object_name HEADING "IndexName" FORMAT a50
COLUMN distinct_keys HEADING "DistinctKeys" FORMAT 99,999,999,999
COLUMN blevel HEADING "BLevel" FORMAT 99999
COLUMN leaf_blocks HEADING "Leaf|Blocks" FORMAT 99,999,999
COLUMN clustering_factor HEADING "Clustering|Factor" FORMAT 99,999,999,999
COLUMN avg_leaf_blocks_per_key HEADING "Avg|LeafBlocks|PerKey" FORMAT 999,999,999
COLUMN avg_data_blocks_per_key HEADING "Avg|DataBlocks|PerKey" FORMAT 999,999,999
select object_name
, object_type
, object_type_sort_order
--, to_char(savtime,'DD-MON-YY HH24:MI:SS') savtime
, to_char(ANALYZETIME,'DD-MON-YY HH24:MI:SS') ANALYZETIME
, SizeMB
, rowcnt
, samplesize
, distinct_keys
, blevel
, clustering_factor
, leaf_blocks
, avg_leaf_blocks_per_key
, avg_data_blocks_per_key
FROM
(
select o.owner || '.' || o.object_name
|| NVL2(o.subobject_name,':' || o.subobject_name, '')
object_name
, o.object_type
, DECODE (o.object_type
, 'TABLE' ,1
, 'TABLE PARTITION' ,2
, 'TABLE SUBPARTITION' ,3
, 'INDEX' ,4
, 'INDEX PARTITION' ,5
, 'INDEX SUBPARTITION' ,6
,9
) object_type_sort_order
, h.savtime
, h.ANALYZETIME
, (h.leafcnt * p.value) /1024/1024 SizeMB
, h.rowcnt
, h.samplesize
, h.distkey distinct_keys
, h.blevel
, h.clufac clustering_factor
, h.leafcnt leaf_blocks
, h.lblkkey avg_leaf_blocks_per_key
, h.dblkkey avg_data_blocks_per_key
--, h.avgrln
FROM sys.wri$_optstat_ind_history h
, dba_objects o
, v$system_parameter p
WHERE h.obj# = o.object_id
AND p.name = 'db_block_size'
AND o.owner LIKE upper('&&owner') ESCAPE '\'
AND o.object_name LIKE upper('&&object_name') ESCAPE '\'
AND NVL(o.subobject_name,'%') LIKE upper('&&subobject_name') ESCAPE '\'
AND NVL(o.object_type,'%') LIKE upper('&&object_type') ESCAPE '\'
UNION ALL
select s.owner || '.' || s.index_name
|| NVL2(s.partition_name,':' || s.partition_name, '')
object_name
, DECODE(s.object_type
,'PARTITION','TABLE PARTITION'
,'SUBPARTITION','TABLE SUBPARTITION'
,s.object_type) object_type
, DECODE (s.object_type
, 'TABLE' ,1
, 'TABLE PARTITION' ,2
, 'TABLE SUBPARTITION' ,3
, 'INDEX' ,4
, 'INDEX PARTITION' ,5
, 'INDEX SUBPARTITION' ,6
,9
) object_type_sort_order
, null savtime
, s.last_analyzed ANALYZETIME
, ROUND((s.leaf_blocks * p.value) /1024/1024 ) SizeMB
, s.num_rows
, s.sample_size
, s.distinct_keys
, s.blevel
, s.clustering_factor
, s.leaf_blocks
, s.avg_leaf_blocks_per_key
, s.avg_data_blocks_per_key
FROM dba_ind_statistics s
, v$system_parameter p
WHERE p.name = 'db_block_size'
AND s.owner LIKE upper('&&owner') ESCAPE '\'
AND s.index_name LIKE upper('&&object_name') ESCAPE '\'
AND NVL(s.partition_name,'%') LIKE upper('&&subobject_name') ESCAPE '\'
AND NVL(DECODE(s.object_type
,'PARTITION','INDEX PARTITION'
,'SUBPARTITION','INDEX SUBPARTITION'
,s.object_type),'%') LIKE upper('&&object_type') ESCAPE '\'
) a
ORDER BY a.object_name
, a.object_type_sort_order
, a.savtime NULLS LAST
--, a.ANALYZETIME
/
/*
*
* Author : Vishal Gupta
* Purpose : Display table statistics history
* Parameters : 1 - OWNER (% - wildchar, \ - escape char)
* 2 - Object Name (% - wildchar, \ - escape char)
* 3 - Partition Name (% - wildchar, \ - escape char)
* 5 - Object Type (% - wildchar, \ - escape char)
*
*
* Revision History:
* ===================
* Date Author Description
* --------- ------------ -----------------------------------------
* 08-Jul-15 Vishal Gupta Removed savetime column from output
* 19-JUN-14 Vishal Gupta Updated AvgRowLength heading
* 28-FEB-14 Vishal Gupta Changed the ordering
* 02-Jul-12 Vishal Gupta Added partition, sub-partition and objecttype as input
* 30-Apr-12 Vishal Gupta Created
*
*/
/************************************
* INPUT PARAMETERS
************************************/
UNDEFINE owner
UNDEFINE object_name
UNDEFINE subobject_name
UNDEFINE object_type
DEFINE owner="&&1"
DEFINE object_name="&&2"
DEFINE subobject_name="&&3"
DEFINE object_type="&&4"
COLUMN _owner NEW_VALUE owner NOPRINT
COLUMN _object_name NEW_VALUE object_name NOPRINT
COLUMN _subobject_name NEW_VALUE subobject_name NOPRINT
COLUMN _object_type NEW_VALUE object_type NOPRINT
set term off
SELECT CASE
WHEN INSTR('&&owner','.') != 0 THEN SUBSTR(UPPER('&&owner'),1,INSTR('&&owner','.')-1)
ELSE DECODE(UPPER('&&owner'),'','%',UPPER('&&owner'))
END "_owner"
, CASE
WHEN INSTR('&&owner','.') != 0 THEN SUBSTR(UPPER('&&owner'),INSTR('&&owner','.')+1)
ELSE DECODE(UPPER('&&object_name'),'','%',UPPER('&&object_name'))
END "_object_name"
, DECODE('&&subobject_name','','%','&&subobject_name') "_subobject_name"
, DECODE('&&object_type','','%','&&object_type') "_object_type"
FROM DUAL
;
set term on
PROMPT
PROMPT ***********************************************************************
PROMPT * S T A T I S T I C S H I S T O R Y
PROMPT *
PROMPT * Input Parameters
PROMPT * - Object Owner = '&&owner'
PROMPT * - Object Name = '&&object_name'
PROMPT * - SubObject Name = '&&subobject_name'
PROMPT * - Object Type = '&&object_type'
PROMPT ***********************************************************************
COLUMN object_name HEADING "ObjectName" FORMAT a60
COLUMN subobject_name HEADING "SubObjectName" FORMAT a30
COLUMN object_type HEADING "Object|Type" FORMAT a18
COLUMN object_type_sort_order NOPRINT
COLUMN savtime HEADING "SaveTime" FORMAT a18
COLUMN ANALYZETIME HEADING "AnalyzeTime" FORMAT a18
COLUMN samplesize HEADING "SampleSize" FORMAT 999,999,999,999
COLUMN rowcnt HEADING "RowCount" FORMAT 999,999,999,999
COLUMN blkcnt HEADING "BlockCount" FORMAT 999,999,999
COLUMN avgrln HEADING "Avg|Row|Length" FORMAT 999,999
COLUMN SizeMB HEADING "Size (MB)" FORMAT 9,999,999
select object_name
, object_type
, object_type_sort_order
--, to_char(savtime,'DD-MON-YY HH24:MI:SS') savtime
, to_char(ANALYZETIME,'DD-MON-YY HH24:MI:SS') ANALYZETIME
, SizeMB
, rowcnt
, avgrln
--, blkcnt
, samplesize
FROM
(
select o.owner || '.' || o.object_name
|| NVL2(o.subobject_name,':' || o.subobject_name, '')
object_name
, o.object_type
, DECODE (o.object_type
, 'TABLE' ,1
, 'TABLE PARTITION' ,2
, 'TABLE SUBPARTITION' ,3
, 'INDEX' ,4
, 'INDEX PARTITION' ,5
, 'INDEX SUBPARTITION' ,6
,9
) object_type_sort_order
, h.savtime
, h.ANALYZETIME
, h.samplesize
, h.rowcnt
, h.avgrln
, (h.blkcnt * p.value) /1024/1024 SizeMB
, h.blkcnt
FROM sys.wri$_optstat_tab_history h
, dba_objects o
, v$system_parameter p
WHERE h.obj# = o.object_id
AND p.name = 'db_block_size'
AND o.owner LIKE upper('&&owner') ESCAPE '\'
AND o.object_name LIKE upper('&&object_name') ESCAPE '\'
AND NVL(o.subobject_name,'%') LIKE upper('&&subobject_name') ESCAPE '\'
AND NVL(DECODE(o.object_type
,'PARTITION','TABLE PARTITION'
,'SUBPARTITION','TABLE SUBPARTITION'
,o.object_type),'%') LIKE upper('&&object_type') ESCAPE '\'
UNION
select s.owner || '.' || s.table_name
|| NVL2(s.partition_name,':' || s.partition_name, '')
object_name
, DECODE(s.object_type
,'PARTITION','TABLE PARTITION'
,'SUBPARTITION','TABLE SUBPARTITION'
,s.object_type) object_type
, DECODE (s.object_type
, 'TABLE' ,1
, 'TABLE PARTITION' ,2
, 'TABLE SUBPARTITION' ,3
, 'INDEX' ,4
, 'INDEX PARTITION' ,5
, 'INDEX SUBPARTITION' ,6
,9
) object_type_sort_order
, NULL savtime
, last_analyzed ANALYZETIME
, sample_size
, num_rows
, avg_row_len
, (s.blocks * p.value) /1024/1024 SizeMB
, s.blocks
FROM dba_tab_statistics s
, v$system_parameter p
WHERE p.name = 'db_block_size'
AND s.owner LIKE upper('&&owner') ESCAPE '\'
AND s.table_name LIKE upper('&&object_name') ESCAPE '\'
AND NVL(s.partition_name,'%') LIKE upper('&&subobject_name') ESCAPE '\'
AND NVL(DECODE(s.object_type
,'PARTITION','TABLE PARTITION'
,'SUBPARTITION','TABLE SUBPARTITION'
,s.object_type),'%') LIKE upper('&&object_type') ESCAPE '\'
) a
ORDER BY a.object_name
, a.object_type_sort_order
, a.savtime NULLS LAST
--, a.ANALYZETIME
/
COLUMN table_name HEADING "IndexName" FORMAT a40
COLUMN object_name HEADING "IndexName" FORMAT a50
COLUMN distinct_keys HEADING "DistinctKeys" FORMAT 99,999,999,999
COLUMN blevel HEADING "BLevel" FORMAT 99999
COLUMN leaf_blocks HEADING "Leaf|Blocks" FORMAT 99,999,999
COLUMN clustering_factor HEADING "Clustering|Factor" FORMAT 99,999,999,999
COLUMN avg_leaf_blocks_per_key HEADING "Avg|LeafBlocks|PerKey" FORMAT 999,999,999
COLUMN avg_data_blocks_per_key HEADING "Avg|DataBlocks|PerKey" FORMAT 999,999,999
select object_name
, object_type
, object_type_sort_order
--, to_char(savtime,'DD-MON-YY HH24:MI:SS') savtime
, to_char(ANALYZETIME,'DD-MON-YY HH24:MI:SS') ANALYZETIME
, SizeMB
, rowcnt
, samplesize
, distinct_keys
, blevel
, clustering_factor
, leaf_blocks
, avg_leaf_blocks_per_key
, avg_data_blocks_per_key
FROM
(
select o.owner || '.' || o.object_name
|| NVL2(o.subobject_name,':' || o.subobject_name, '')
object_name
, o.object_type
, DECODE (o.object_type
, 'TABLE' ,1
, 'TABLE PARTITION' ,2
, 'TABLE SUBPARTITION' ,3
, 'INDEX' ,4
, 'INDEX PARTITION' ,5
, 'INDEX SUBPARTITION' ,6
,9
) object_type_sort_order
, h.savtime
, h.ANALYZETIME
, (h.leafcnt * p.value) /1024/1024 SizeMB
, h.rowcnt
, h.samplesize
, h.distkey distinct_keys
, h.blevel
, h.clufac clustering_factor
, h.leafcnt leaf_blocks
, h.lblkkey avg_leaf_blocks_per_key
, h.dblkkey avg_data_blocks_per_key
--, h.avgrln
FROM sys.wri$_optstat_ind_history h
, dba_objects o
, v$system_parameter p
WHERE h.obj# = o.object_id
AND p.name = 'db_block_size'
AND o.owner LIKE upper('&&owner') ESCAPE '\'
AND o.object_name LIKE upper('&&object_name') ESCAPE '\'
AND NVL(o.subobject_name,'%') LIKE upper('&&subobject_name') ESCAPE '\'
AND NVL(o.object_type,'%') LIKE upper('&&object_type') ESCAPE '\'
UNION ALL
select s.owner || '.' || s.index_name
|| NVL2(s.partition_name,':' || s.partition_name, '')
object_name
, DECODE(s.object_type
,'PARTITION','TABLE PARTITION'
,'SUBPARTITION','TABLE SUBPARTITION'
,s.object_type) object_type
, DECODE (s.object_type
, 'TABLE' ,1
, 'TABLE PARTITION' ,2
, 'TABLE SUBPARTITION' ,3
, 'INDEX' ,4
, 'INDEX PARTITION' ,5
, 'INDEX SUBPARTITION' ,6
,9
) object_type_sort_order
, null savtime
, s.last_analyzed ANALYZETIME
, ROUND((s.leaf_blocks * p.value) /1024/1024 ) SizeMB
, s.num_rows
, s.sample_size
, s.distinct_keys
, s.blevel
, s.clustering_factor
, s.leaf_blocks
, s.avg_leaf_blocks_per_key
, s.avg_data_blocks_per_key
FROM dba_ind_statistics s
, v$system_parameter p
WHERE p.name = 'db_block_size'
AND s.owner LIKE upper('&&owner') ESCAPE '\'
AND s.index_name LIKE upper('&&object_name') ESCAPE '\'
AND NVL(s.partition_name,'%') LIKE upper('&&subobject_name') ESCAPE '\'
AND NVL(DECODE(s.object_type
,'PARTITION','INDEX PARTITION'
,'SUBPARTITION','INDEX SUBPARTITION'
,s.object_type),'%') LIKE upper('&&object_type') ESCAPE '\'
) a
ORDER BY a.object_name
, a.object_type_sort_order
, a.savtime NULLS LAST
--, a.ANALYZETIME
/
+360 -359
View File
@@ -1,359 +1,360 @@
/*
*
* Author : Vishal Gupta
* Purpose : Display Tables details
* Parameters : 1 - Owner (Use % as wild card, \ as ESCAPE)
* 2 - TableName (Use % as wild card, \ as ESCAPE)
*
*
* Revision History:
* ===================
* Date Author Description
* --------- ------------ -----------------------------------------
* 22-Aug-16 Vishal Gupta Added child foreign key constrainst list
* 30-Apr-15 Vishal Gupta Added join to dba_objects to get creation date
* 13-Mar-15 Vishal Gupta Added table's indexes in output
* 24-Apr-13 Vishal Gupta Created
*
*/
/************************************
* INPUT PARAMETERS
************************************/
UNDEFINE owner
UNDEFINE table_name
DEFINE owner="&&1"
DEFINE table_name="&&2"
COLUMN _owner NEW_VALUE owner NOPRINT
COLUMN _table_name NEW_VALUE table_name NOPRINT
set term off
SELECT SUBSTR(UPPER('&&owner'), 1 , CASE INSTR('&&owner','.') WHEN 0 THEN LENGTH ('&&owner') ELSE INSTR('&&owner','.') - 1 END) "_owner"
, CASE
WHEN INSTR('&&owner','.') != 0 THEN SUBSTR(UPPER('&&owner'),INSTR('&&owner','.')+1)
ELSE UPPER('&&table_name')
END "_table_name"
FROM DUAL;
set term on
PROMPT ************************************
PROMPT * T A B L E D E T A I L S
PROMPT ************************************
COLUMN col1 FORMAT a60
COLUMN col2 FORMAT a60
set head off
SELECT 'Owner : ' || t.owner
|| chr(10) || 'Table Name : ' || t.table_name
|| chr(10) || 'Table Comments : ' || c.comments
|| chr(10) || 'Tablespace Name : ' || t.tablespace_name
|| chr(10) || 'Status : ' || t.status
|| chr(10) || 'Temporary : ' || t.temporary
|| chr(10) || 'Partitioned : ' || t.partitioned
|| chr(10) || 'Compression : ' || t.compression
|| chr(10) || 'Compress For : ' || t.compress_for
|| chr(10) || 'Segment Created : ' || t.segment_created
|| chr(10) || 'Degree : ' || TRIM(t.degree)
|| chr(10) || 'IOT Type : ' || t.iot_type
|| chr(10) || 'IOT Name : ' || t.iot_name
|| chr(10) || 'Logging : ' || t.logging
|| chr(10) || 'Backed Up : ' || t.backed_up
|| chr(10) || 'Instances : ' || TRIM(t.instances)
|| chr(10) || 'Table Lock : ' || t.table_lock
|| chr(10) || 'Secondary : ' || t.secondary
|| chr(10) || 'Nested : ' || t.nested
|| chr(10) || 'Row Movement : ' || t.row_movement
|| chr(10) || 'Duration : ' || t.duration
|| chr(10) || 'Skip Corrupt : ' || t.skip_corrupt
|| chr(10) || 'Monitoring : ' || t.monitoring
|| chr(10) || 'Cluster Owner : ' || t.cluster_owner
|| chr(10) || 'Cluster Name : ' || t.cluster_name
|| chr(10) || 'Dependencies : ' || t.dependencies
|| chr(10) || 'Dropped : ' || t.dropped
|| chr(10) || 'Read Only : ' || t.read_only
|| chr(10) || ' '
|| chr(10) || '[ Cache ] '
|| chr(10) || 'Cache : ' || TRIM(t.cache)
|| chr(10) || 'Buffer Pool : ' || t.buffer_pool
|| chr(10) || 'Flash Cache : ' || t.flash_cache
|| chr(10) || 'Cell Flash Cache : ' || t.cell_flash_cache
|| chr(10) || 'Result Cache : ' || t.result_cache
col1
,
'[ Dates ] '
|| chr(10) || 'Created : ' || TO_CHAR(o.created,'DD-MON-YYYY HH24:MI:SS')
|| chr(10) || 'Last DDL : ' || TO_CHAR(o.last_ddl_time,'DD-MON-YY HH24:MI:SS')
|| chr(10) || 'Last Spec Change : ' || TO_CHAR(TO_DATE(o.timestamp,'YYYY-MM-DD HH24:MI:SS'),'DD-MON-YY HH24:MI:SS')
|| chr(10) || ' '
|| chr(10) || '[ Storage ] '
|| chr(10) || 'PCT Free : ' || t.pct_free
|| chr(10) || 'PCT Used : ' || t.pct_used
|| chr(10) || 'PCT Increase : ' || t.pct_increase
|| chr(10) || 'INI Trans : ' || t.ini_trans
|| chr(10) || 'Max Trans : ' || t.max_trans
|| chr(10) || 'Initial Extent Size : ' || t.initial_extent
|| chr(10) || 'Next Extent Size : ' || t.next_extent
|| chr(10) || 'Mininum Extents : ' || t.min_extents
|| chr(10) || 'Max Extents : ' || t.max_extents
|| chr(10) || 'Freelists : ' || t.freelists
|| chr(10) || 'Freelists Group : ' || t.freelist_groups
|| chr(10) || ' '
|| chr(10) || '[ Statistics ] '
|| chr(10) || 'Last Analyzed : ' || to_char(t.last_analyzed,'DD-MON-YY HH24:MI:SS')
|| chr(10) || 'Global Stats : ' || t.global_stats
|| chr(10) || 'User Stats : ' || t.user_stats
|| chr(10) || 'Sample Size : ' || TRIM(TO_CHAR(t.sample_size,'999,999,999,999,999'))
|| chr(10) || 'Num Rows : ' || TRIM(TO_CHAR(t.num_rows,'999,999,999,999,999'))
|| chr(10) || 'Table Size : ' || TRIM(TO_CHAR((t.blocks * (select BLOCK_SIZE from dba_tablespaces tbs where tbs.tablespace_name = t.tablespace_name) )/power(1024,2),'999,999,999,999,999' )) || ' MB'
|| chr(10) || 'Blocks : ' || t.blocks
|| chr(10) || 'Empty Blocks : ' || t.empty_blocks
|| chr(10) || 'Average Row Length : ' || t.avg_row_len
|| chr(10) || 'Average Space : ' || t.avg_space
|| chr(10) || 'Chain Count : ' || t.chain_cnt
|| chr(10) || 'Freelist Blocks : ' || t.num_freelist_blocks
|| chr(10) || 'Avg Space Freelists Blocks: ' || t.avg_space_freelist_blocks
col2
FROM dba_tables t
JOIN dba_objects o ON o.owner = t.owner AND o.object_name = t.table_name AND o.object_type = 'TABLE'
LEFT OUTER JOIN dba_tab_comments c ON c.owner = t.owner AND c.table_name = t.table_name
WHERE t.owner = '&&owner'
AND t.table_name = '&&table_name'
;
set head on
/* Taken from tab_parts_summary.sql */
PROMPT *******************************
PROMPT * Table's Partitions Details
PROMPT *******************************
COLUMN table_name HEADING "Table Name" FORMAT a40
COLUMN partitioning_type HEADING "Part|Type" FORMAT a7
COLUMN partitioning_key_count HEADING "Part|Key|Count" FORMAT 99999
COLUMN interval HEADING "Interval" FORMAT a30
COLUMN subpartitioning_type HEADING "SubPart|Type" FORMAT a10
COLUMN subpartitioning_key_count HEADING "SubPart|Key|Count" FORMAT 99999
COLUMN def_subpartition_count HEADING "Default|Subpart|Count|PerPart" FORMAT 999
COLUMN status HEADING "Status" FORMAT a8
COLUMN partition_count HEADING "Part|Count" FORMAT 999,999
COLUMN subpartition_count HEADING "SubPart|Count" FORMAT 999,999
COLUMN total_count HEADING "Total|Count" FORMAT 999,999
SELECT pt.owner || '.' || pt.table_name table_name
, pt.status
, pt.partitioning_type
, pt.partitioning_key_count
-- for interval RANGE partition, dba_part_tables.partition_count is always 1048575
-- , so we need to take actual partition count from dba_tab_partitions
, count(distinct p.partition_name) partition_count
, pt.interval
, pt.subpartitioning_type
, pt.subpartitioning_key_count
, pt.def_subpartition_count
, count(s.subpartition_name) subpartition_count
, GREATEST(count(distinct p.partition_name) , count(s.subpartition_name)) total_count
FROM dba_part_tables pt
JOIN dba_tab_partitions p ON p.table_owner = pt.owner AND p.table_name = pt.table_name
LEFT OUTER JOIN dba_tab_subpartitions s ON s.table_owner = pt.owner AND s.table_name = pt.table_name AND p.partition_name = s.partition_name
WHERE 1=1
AND pt.owner LIKE '&&owner' ESCAPE '\'
AND pt.table_name LIKE '&&table_name' ESCAPE '\'
GROUP BY
pt.owner
, pt.table_name
, pt.partitioning_type
, pt.interval
, pt.subpartitioning_type
, pt.def_subpartition_count
, pt.partitioning_key_count
, pt.subpartitioning_key_count
, pt.status
--ORDER BY total_count desc
ORDER BY pt.owner
, pt.table_name
;
/* Taken from tab_indexes.sql */
PROMPT
PROMPT ********************
PROMPT * Table's Indices
PROMPT ********************
COLUMN owner HEADING "Index Owner" FORMAT a20
COLUMN table_name HEADING "Table Name" FORMAT a40
COLUMN index_owner HEADING "Index Owner" FORMAT a20
COLUMN index_name HEADING "Index Name" FORMAT a40
COLUMN index_type HEADING "Index Type" FORMAT a10
COLUMN status HEADING "Status" FORMAT a8
COLUMN visibility HEADING "Visible" FORMAT a10
COLUMN uniqueness HEADING "Uniqueness" FORMAT a15
COLUMN Columns HEADING "Index columns" FORMAT a90
BREAK ON TABLE_NAME
SELECT /*+ */
-- i.table_owner || '.' || i.table_name table_name
--,
i.owner || '.' || i.index_name index_name
, i.uniqueness
, i.index_type
, i.status
, i.visibility
-- , column_name
-- , column_position
-- , CONNECT_BY_ISLEAF
-- , LEVEL
--, SUBSTR(SYS_CONNECT_BY_PATH ( NVL(to_char(ie.column_expression),ic.column_name) || DECODE(ic.descend,'ASC','',' (desc) ') , ' , ' ),4) Columns
, SUBSTR(SYS_CONNECT_BY_PATH ( ic.column_name || DECODE(ic.descend,'ASC','',' (desc) ') , ' , ' ),4) Columns
FROM dba_indexes i
, dba_ind_columns ic
, dba_ind_expressions ie
WHERE i.owner = ic.index_owner
AND i.index_name = ic.index_name
AND i.table_owner = ic.table_owner
AND i.table_name = ic.table_name
AND ic.index_owner = ie.index_owner (+)
AND ic.index_name = ie.index_name (+)
AND ic.table_owner = ie.table_owner (+)
AND ic.table_name = ie.table_name (+)
AND ic.column_position = ie.column_position (+)
AND i.table_owner LIKE upper('&&owner') ESCAPE '\'
AND i.table_name LIKE upper('&&table_name') ESCAPE '\'
AND CONNECT_BY_ISLEAF = 1
AND LEVEL = ic.column_position
CONNECT BY ic.table_owner = PRIOR ic.table_owner
AND ic.table_name = PRIOR ic.table_name
AND ic.index_owner = PRIOR ic.index_owner
AND ic.index_name = PRIOR ic.index_name
AND ic.column_position - 1 = PRIOR ic.column_position
START WITH ic.table_owner LIKE upper('&&owner') ESCAPE '\'
AND ic.table_name LIKE upper('&&table_name') ESCAPE '\'
ORDER BY ic.table_owner
, ic.table_name
, ic.index_owner
, ic.index_name
;
-- Taken from columns.sql
/*
PROMPT
PROMPT ********************
PROMPT * Table's Columns
PROMPT ********************
COLUMN object_name HEADING "ObjectName" FORMAT a45
COLUMN object_type HEADING "ObjectType" FORMAT a17
COLUMN column_id HEADING "ColumnId" FORMAT 9999
COLUMN column_name HEADING "ColumnName" FORMAT a30
COLUMN nullable HEADING "Null?" FORMAT a8
COLUMN Type HEADING "ColumnType" FORMAT a20
COLUMN data_default HEADING "Default|Value" FORMAT a40
COLUMN comments HEADING "Comments" FORMAT a60
SELECT
--c.owner || '.' || c.table_name object_name,
c.column_id
, c.column_name
, DECODE(c.nullable,'N','NOT NULL','') nullable
, CASE
WHEN c.data_type = 'NUMBER'
THEN c.data_type || NVL2(c.data_precision||c.data_scale, '(' || NVL(c.data_precision,'38') || ',' || NVL(c.data_scale,'127') || ')','')
WHEN c.data_type = 'FLOAT'
THEN c.data_type || NVL2(c.data_precision,'(' || c.data_precision || ')','')
WHEN c.data_type = 'VARCHAR2' OR c.data_type = 'CHAR'
THEN c.data_type || '(' || c.char_length || ' ' || DECODE(c.char_used,'B','BYTE','CHAR') || ')'
WHEN c.data_type = 'NVARCHAR2' OR c.data_type = 'NCHAR'
THEN c.data_type || '(' || c.char_length || ')'
WHEN c.data_type = 'RAW' OR c.data_type = 'UROWID'
THEN c.data_type || '(' || c.data_length || ')'
ELSE c.data_type
END Type
, c.data_default
, cc.comments
FROM dba_tab_columns c
LEFT OUTER JOIN dba_col_comments cc ON cc.owner = c.owner AND cc.table_name = c.table_name AND cc.column_name = c.column_name
WHERE UPPER(c.owner) like UPPER('&&owner') ESCAPE '\'
AND UPPER(c.table_name) like UPPER('&&table_name') ESCAPE '\'
AND c.table_name NOT LIKE 'BIN$%'
ORDER BY c.column_id ;
*/
PROMPT
PROMPT ****************************
PROMPT * Table's Constraints
PROMPT ****************************
COLUMN constraint_name HEADING "ConstraintName" FORMAT a30
COLUMN constraint_type HEADING "Type" FORMAT a4
COLUMN status HEADING "Status" FORMAT a8
COLUMN delete_rule HEADING "Delete|Rule" FORMAT a9
COLUMN validated HEADING "Validated"
COLUMN generated HEADING "Generated"
COLUMN last_change HEADING "LastChange" FORMAT a18
COLUMN search_condition HEADING "SearchCondition" FORMAT a50
select *
from
xmltable( '/ROWSET/ROW'
passing dbms_xmlgen.getXMLType('
SELECT c.constraint_name
, c.constraint_type
, c.status
, c.delete_rule
, c.validated
, c.generated
, TO_CHAR(last_change,''DD-MON-YY HH24:MI:SS'') last_change
, c.search_condition /* <---- Long Column type*/
FROM dba_constraints c
WHERE UPPER(c.owner) like UPPER(''' || '&&owner' || ''') ESCAPE ''\''
AND UPPER(c.table_name) like UPPER(''' || '&&table_name' || ''') ESCAPE ''\''
')
columns
constraint_name varchar2(30)
, constraint_type varchar2(30)
, status varchar2(30)
, delete_rule varchar2(9)
, validated varchar2(30)
, generated varchar2(30)
, last_change varchar2(30)
, search_condition varchar2(2000)
)
WHERE 1=1
AND NOT (constraint_type = 'C' AND search_condition LIKE '%NOT NULL%' )
;
PROMPT
PROMPT ********************************************
PROMPT * Child Foreign Key Constraints
PROMPT ********************************************
SELECT c.owner
, c.constraint_name
, c.table_name
, c.r_constraint_name
, c.delete_rule
FROM dba_constraints c
WHERE (c.r_owner, c.r_constraint_name) IN (SELECT c2.owner, c2.constraint_name
FROM dba_constraints c2
WHERE UPPER(c2.owner) like UPPER('&&owner') ESCAPE '\'
AND UPPER(c2.table_name) like UPPER('&&table_name') ESCAPE '\'
AND c2.constraint_type in ('P','U')
)
;
/*
*
* Author : Vishal Gupta
* Purpose : Display Tables details
* Parameters : 1 - Owner (Use % as wild card, \ as ESCAPE)
* 2 - TableName (Use % as wild card, \ as ESCAPE)
*
*
* Revision History:
* ===================
* Date Author Description
* --------- ------------ -----------------------------------------
* 22-Aug-16 Vishal Gupta Added child foreign key constrainst list
* 30-Apr-15 Vishal Gupta Added join to dba_objects to get creation date
* 13-Mar-15 Vishal Gupta Added table's indexes in output
* 24-Apr-13 Vishal Gupta Created
*
*/
/************************************
* INPUT PARAMETERS
************************************/
UNDEFINE owner
UNDEFINE table_name
DEFINE owner="&&1"
DEFINE table_name="&&2"
COLUMN _owner NEW_VALUE owner NOPRINT
COLUMN _table_name NEW_VALUE table_name NOPRINT
set term off
SELECT SUBSTR(UPPER('&&owner'), 1 , CASE INSTR('&&owner','.') WHEN 0 THEN LENGTH ('&&owner') ELSE INSTR('&&owner','.') - 1 END) "_owner"
, CASE
WHEN INSTR('&&owner','.') != 0 THEN SUBSTR(UPPER('&&owner'),INSTR('&&owner','.')+1)
ELSE UPPER('&&table_name')
END "_table_name"
FROM DUAL;
set term on
PROMPT ************************************
PROMPT * T A B L E D E T A I L S
PROMPT ************************************
COLUMN col1 FORMAT a60
COLUMN col2 FORMAT a60
set head off
SELECT 'Owner : ' || t.owner
|| chr(10) || 'Table Name : ' || t.table_name
|| chr(10) || 'Table Comments : ' || c.comments
|| chr(10) || 'Tablespace Name : ' || t.tablespace_name
|| chr(10) || 'Status : ' || t.status
|| chr(10) || 'Temporary : ' || t.temporary
|| chr(10) || 'Partitioned : ' || t.partitioned
|| chr(10) || 'Compression : ' || t.compression
|| chr(10) || 'Compress For : ' || t.compress_for
|| chr(10) || 'Segment Created : ' || t.segment_created
|| chr(10) || 'Degree : ' || TRIM(t.degree)
|| chr(10) || 'IOT Type : ' || t.iot_type
|| chr(10) || 'IOT Name : ' || t.iot_name
|| chr(10) || 'Logging : ' || t.logging
|| chr(10) || 'Backed Up : ' || t.backed_up
|| chr(10) || 'Instances : ' || TRIM(t.instances)
|| chr(10) || 'Table Lock : ' || t.table_lock
|| chr(10) || 'Secondary : ' || t.secondary
|| chr(10) || 'Nested : ' || t.nested
|| chr(10) || 'Row Movement : ' || t.row_movement
|| chr(10) || 'Duration : ' || t.duration
|| chr(10) || 'Skip Corrupt : ' || t.skip_corrupt
|| chr(10) || 'Monitoring : ' || t.monitoring
|| chr(10) || 'Cluster Owner : ' || t.cluster_owner
|| chr(10) || 'Cluster Name : ' || t.cluster_name
|| chr(10) || 'Dependencies : ' || t.dependencies
|| chr(10) || 'Dropped : ' || t.dropped
|| chr(10) || 'Read Only : ' || t.read_only
|| chr(10) || ' '
|| chr(10) || '[ Cache ] '
|| chr(10) || 'Cache : ' || TRIM(t.cache)
|| chr(10) || 'Buffer Pool : ' || t.buffer_pool
|| chr(10) || 'Flash Cache : ' || t.flash_cache
|| chr(10) || 'Cell Flash Cache : ' || t.cell_flash_cache
|| chr(10) || 'Result Cache : ' || t.result_cache
col1
,
'[ Dates ] '
|| chr(10) || 'Created : ' || TO_CHAR(o.created,'DD-MON-YYYY HH24:MI:SS')
|| chr(10) || 'Last DDL : ' || TO_CHAR(o.last_ddl_time,'DD-MON-YY HH24:MI:SS')
|| chr(10) || 'Last Spec Change : ' || TO_CHAR(TO_DATE(o.timestamp,'YYYY-MM-DD HH24:MI:SS'),'DD-MON-YY HH24:MI:SS')
|| chr(10) || ' '
|| chr(10) || '[ Storage ] '
|| chr(10) || 'PCT Free : ' || t.pct_free
|| chr(10) || 'PCT Used : ' || t.pct_used
|| chr(10) || 'PCT Increase : ' || t.pct_increase
|| chr(10) || 'INI Trans : ' || t.ini_trans
|| chr(10) || 'Max Trans : ' || t.max_trans
|| chr(10) || 'Initial Extent Size : ' || t.initial_extent
|| chr(10) || 'Next Extent Size : ' || t.next_extent
|| chr(10) || 'Mininum Extents : ' || t.min_extents
|| chr(10) || 'Max Extents : ' || t.max_extents
|| chr(10) || 'Freelists : ' || t.freelists
|| chr(10) || 'Freelists Group : ' || t.freelist_groups
|| chr(10) || ' '
|| chr(10) || '[ Statistics ] '
|| chr(10) || 'Last Analyzed : ' || to_char(t.last_analyzed,'DD-MON-YY HH24:MI:SS')
|| chr(10) || 'Global Stats : ' || t.global_stats
|| chr(10) || 'User Stats : ' || t.user_stats
|| chr(10) || 'Sample Size : ' || TRIM(TO_CHAR(t.sample_size,'999,999,999,999,999'))
|| chr(10) || 'Num Rows : ' || TRIM(TO_CHAR(t.num_rows,'999,999,999,999,999'))
|| chr(10) || 'Table Size : ' || TRIM(TO_CHAR((t.blocks * (select BLOCK_SIZE from dba_tablespaces tbs where tbs.tablespace_name = t.tablespace_name) )/power(1024,2),'999,999,999,999,999' )) || ' MB'
|| chr(10) || 'Blocks : ' || t.blocks
|| chr(10) || 'Empty Blocks : ' || t.empty_blocks
|| chr(10) || 'Average Row Length : ' || t.avg_row_len
|| chr(10) || 'Average Space : ' || t.avg_space
|| chr(10) || 'Chain Count : ' || t.chain_cnt
|| chr(10) || 'Freelist Blocks : ' || t.num_freelist_blocks
|| chr(10) || 'Avg Space Freelists Blocks: ' || t.avg_space_freelist_blocks
col2
FROM dba_tables t
JOIN dba_objects o ON o.owner = t.owner AND o.object_name = t.table_name AND o.object_type = 'TABLE'
LEFT OUTER JOIN dba_tab_comments c ON c.owner = t.owner AND c.table_name = t.table_name
WHERE t.owner = '&&owner'
AND t.table_name = '&&table_name'
;
set head on
/* Taken from tab_parts_summary.sql */
PROMPT *******************************
PROMPT * Table's Partitions Details
PROMPT *******************************
COLUMN table_name HEADING "Table Name" FORMAT a40
COLUMN partitioning_type HEADING "Part|Type" FORMAT a7
COLUMN partitioning_key_count HEADING "Part|Key|Count" FORMAT 99999
COLUMN interval HEADING "Interval" FORMAT a30
COLUMN subpartitioning_type HEADING "SubPart|Type" FORMAT a10
COLUMN subpartitioning_key_count HEADING "SubPart|Key|Count" FORMAT 99999
COLUMN def_subpartition_count HEADING "Default|Subpart|Count|PerPart" FORMAT 999
COLUMN status HEADING "Status" FORMAT a8
COLUMN partition_count HEADING "Part|Count" FORMAT 999,999
COLUMN subpartition_count HEADING "SubPart|Count" FORMAT 999,999
COLUMN total_count HEADING "Total|Count" FORMAT 999,999
SELECT pt.owner || '.' || pt.table_name table_name
, pt.status
, pt.partitioning_type
, pt.partitioning_key_count
-- for interval RANGE partition, dba_part_tables.partition_count is always 1048575
-- , so we need to take actual partition count from dba_tab_partitions
, count(distinct p.partition_name) partition_count
, pt.interval
, pt.subpartitioning_type
, pt.subpartitioning_key_count
, pt.def_subpartition_count
, count(s.subpartition_name) subpartition_count
, GREATEST(count(distinct p.partition_name) , count(s.subpartition_name)) total_count
FROM dba_part_tables pt
JOIN dba_tab_partitions p ON p.table_owner = pt.owner AND p.table_name = pt.table_name
LEFT OUTER JOIN dba_tab_subpartitions s ON s.table_owner = pt.owner AND s.table_name = pt.table_name AND p.partition_name = s.partition_name
WHERE 1=1
AND pt.owner LIKE '&&owner' ESCAPE '\'
AND pt.table_name LIKE '&&table_name' ESCAPE '\'
GROUP BY
pt.owner
, pt.table_name
, pt.partitioning_type
, pt.interval
, pt.subpartitioning_type
, pt.def_subpartition_count
, pt.partitioning_key_count
, pt.subpartitioning_key_count
, pt.status
--ORDER BY total_count desc
ORDER BY pt.owner
, pt.table_name
;
/* Taken from tab_indexes.sql */
PROMPT
PROMPT ********************
PROMPT * Table's Indices
PROMPT ********************
COLUMN owner HEADING "Index Owner" FORMAT a20
COLUMN table_name HEADING "Table Name" FORMAT a40
COLUMN index_owner HEADING "Index Owner" FORMAT a20
COLUMN index_name HEADING "Index Name" FORMAT a40
COLUMN index_type HEADING "Index Type" FORMAT a10
COLUMN status HEADING "Status" FORMAT a8
COLUMN visibility HEADING "Visible" FORMAT a10
COLUMN uniqueness HEADING "Uniqueness" FORMAT a15
COLUMN Columns HEADING "Index columns" FORMAT a90
BREAK ON TABLE_NAME
SELECT /*+ */
-- i.table_owner || '.' || i.table_name table_name
--,
i.owner || '.' || i.index_name index_name
, i.uniqueness
, i.index_type
, i.status
, i.visibility
-- , column_name
-- , column_position
-- , CONNECT_BY_ISLEAF
-- , LEVEL
--, SUBSTR(SYS_CONNECT_BY_PATH ( NVL(to_char(ie.column_expression),ic.column_name) || DECODE(ic.descend,'ASC','',' (desc) ') , ' , ' ),4) Columns
, SUBSTR(SYS_CONNECT_BY_PATH ( ic.column_name || DECODE(ic.descend,'ASC','',' (desc) ') , ' , ' ),4) Columns
FROM dba_indexes i
, dba_ind_columns ic
, dba_ind_expressions ie
WHERE i.owner = ic.index_owner
AND i.index_name = ic.index_name
AND i.table_owner = ic.table_owner
AND i.table_name = ic.table_name
AND ic.index_owner = ie.index_owner (+)
AND ic.index_name = ie.index_name (+)
AND ic.table_owner = ie.table_owner (+)
AND ic.table_name = ie.table_name (+)
AND ic.column_position = ie.column_position (+)
AND i.table_owner LIKE upper('&&owner') ESCAPE '\'
AND i.table_name LIKE upper('&&table_name') ESCAPE '\'
AND CONNECT_BY_ISLEAF = 1
AND LEVEL = ic.column_position
CONNECT BY ic.table_owner = PRIOR ic.table_owner
AND ic.table_name = PRIOR ic.table_name
AND ic.index_owner = PRIOR ic.index_owner
AND ic.index_name = PRIOR ic.index_name
AND ic.column_position - 1 = PRIOR ic.column_position
START WITH ic.table_owner LIKE upper('&&owner') ESCAPE '\'
AND ic.table_name LIKE upper('&&table_name') ESCAPE '\'
ORDER BY ic.table_owner
, ic.table_name
, ic.index_owner
, ic.index_name
;
-- Taken from columns.sql
/*
PROMPT
PROMPT ********************
PROMPT * Table's Columns
PROMPT ********************
COLUMN object_name HEADING "ObjectName" FORMAT a45
COLUMN object_type HEADING "ObjectType" FORMAT a17
COLUMN column_id HEADING "ColumnId" FORMAT 9999
COLUMN column_name HEADING "ColumnName" FORMAT a30
COLUMN nullable HEADING "Null?" FORMAT a8
COLUMN Type HEADING "ColumnType" FORMAT a20
COLUMN data_default HEADING "Default|Value" FORMAT a40
COLUMN comments HEADING "Comments" FORMAT a60
SELECT
--c.owner || '.' || c.table_name object_name,
c.column_id
, c.column_name
, DECODE(c.nullable,'N','NOT NULL','') nullable
, CASE
WHEN c.data_type = 'NUMBER'
THEN c.data_type || NVL2(c.data_precision||c.data_scale, '(' || NVL(c.data_precision,'38') || ',' || NVL(c.data_scale,'127') || ')','')
WHEN c.data_type = 'FLOAT'
THEN c.data_type || NVL2(c.data_precision,'(' || c.data_precision || ')','')
WHEN c.data_type = 'VARCHAR2' OR c.data_type = 'CHAR'
THEN c.data_type || '(' || c.char_length || ' ' || DECODE(c.char_used,'B','BYTE','CHAR') || ')'
WHEN c.data_type = 'NVARCHAR2' OR c.data_type = 'NCHAR'
THEN c.data_type || '(' || c.char_length || ')'
WHEN c.data_type = 'RAW' OR c.data_type = 'UROWID'
THEN c.data_type || '(' || c.data_length || ')'
ELSE c.data_type
END Type
, c.data_default
, cc.comments
FROM dba_tab_columns c
LEFT OUTER JOIN dba_col_comments cc ON cc.owner = c.owner AND cc.table_name = c.table_name AND cc.column_name = c.column_name
WHERE UPPER(c.owner) like UPPER('&&owner') ESCAPE '\'
AND UPPER(c.table_name) like UPPER('&&table_name') ESCAPE '\'
AND c.table_name NOT LIKE 'BIN$%'
ORDER BY c.column_id ;
*/
PROMPT
PROMPT ****************************
PROMPT * Table's Constraints
PROMPT ****************************
COLUMN constraint_name HEADING "ConstraintName" FORMAT a30
COLUMN constraint_type HEADING "Type" FORMAT a4
COLUMN status HEADING "Status" FORMAT a8
COLUMN delete_rule HEADING "Delete|Rule" FORMAT a9
COLUMN validated HEADING "Validated"
COLUMN generated HEADING "Generated"
COLUMN last_change HEADING "LastChange" FORMAT a18
COLUMN search_condition HEADING "SearchCondition" FORMAT a50
select *
from
xmltable( '/ROWSET/ROW'
passing dbms_xmlgen.getXMLType('
SELECT c.constraint_name
, c.constraint_type
, c.status
, c.delete_rule
, c.validated
, c.generated
, TO_CHAR(last_change,''DD-MON-YY HH24:MI:SS'') last_change
, c.search_condition /* <---- Long Column type*/
FROM dba_constraints c
WHERE UPPER(c.owner) like UPPER(''' || '&&owner' || ''') ESCAPE ''\''
AND UPPER(c.table_name) like UPPER(''' || '&&table_name' || ''') ESCAPE ''\''
')
columns
constraint_name varchar2(30)
, constraint_type varchar2(30)
, status varchar2(30)
, delete_rule varchar2(9)
, validated varchar2(30)
, generated varchar2(30)
, last_change varchar2(30)
, search_condition varchar2(2000)
)
WHERE 1=1
AND NOT (constraint_type = 'C' AND search_condition LIKE '%NOT NULL%' )
;
PROMPT
PROMPT ********************************************
PROMPT * Child Foreign Key Constraints
PROMPT ********************************************
SELECT c.owner
, c.constraint_name
, c.table_name
, c.r_constraint_name
, c.delete_rule
FROM dba_constraints c
WHERE (c.r_owner, c.r_constraint_name) IN (SELECT c2.owner, c2.constraint_name
FROM dba_constraints c2
WHERE UPPER(c2.owner) like UPPER('&&owner') ESCAPE '\'
AND UPPER(c2.table_name) like UPPER('&&table_name') ESCAPE '\'
AND c2.constraint_type in ('P','U')
)
;
+5 -5
View File
@@ -1,5 +1,5 @@
/* Statistics details for table partitions/subpartitios
Usage: @tabstat <owner> <table>
vplesnila 2024-01-29: creation
@@ -10,8 +10,8 @@ col table_name for a25 head "Table name"
col last_DML for a20 head "Last DML"
col last_analyzed for a20 head "Last Analyzed"
col STALE_STATS for a7 head "Stale"
col NUM_ROWS head "#Rows"
col INSERTS head "Table|INS"
col NUM_ROWS head "#Rows"
col INSERTS head "Table|INS"
col UPDATES head "Table|UPD"
col DELETES head "Table|DEL"
col TRUNCATED head "Table|TRUN"
@@ -21,7 +21,7 @@ compute sum of INSERTS on report
compute sum of UPDATES on report
compute sum of DELETES on report
select
select
tabstat.OWNER
,tabstat.TABLE_NAME
,tabstat.NUM_ROWS
@@ -32,7 +32,7 @@ select
,tabmod.DELETES
,tabmod.TRUNCATED
,tabmod.TIMESTAMP last_DML
from
from
dba_tab_statistics tabstat
,dba_tab_modifications tabmod
WHERE
-50
View File
@@ -1,50 +0,0 @@
col owner for a20 head "Owner"
col table_name for a25 head "Table name"
col PARTITION_NAME for a25 head "Partition name"
col SUBPARTITION_NAME for a25 head "Subpartition name"
col last_DML for a20 head "Last DML"
col last_analyzed for a20 head "Last Analyzed"
col STALE_STATS for a7 head "Stale"
col NUM_ROWS head "#Rows"
col INSERTS head "Table|INS"
col UPDATES head "Table|UPD"
col DELETES head "Table|DEL"
col TRUNCATED head "Table|TRUN"
break on report skip 1
compute sum of INSERTS on report
compute sum of UPDATES on report
compute sum of DELETES on report
select
tabstat.OWNER
,tabstat.TABLE_NAME
,tabstat.PARTITION_NAME
,tabstat.SUBPARTITION_NAME
,tabstat.NUM_ROWS
,tabstat.STALE_STATS
,tabstat.LAST_ANALYZED
,tabmod.INSERTS
,tabmod.UPDATES
,tabmod.DELETES
,tabmod.TRUNCATED
,tabmod.TIMESTAMP last_DML
from
dba_tab_statistics tabstat
,dba_tab_modifications tabmod
WHERE
tabstat.owner = '&&1'
AND tabstat.table_name = '&&2'
AND (tabstat.partition_name like '%&&3%' or tabstat.partition_name is NULL)
AND (tabstat.subpartition_name like '%&&4%' or tabstat.subpartition_name is NULL)
AND tabstat.owner = tabmod.table_owner(+)
AND tabstat.table_name = tabmod.table_name(+)
AND tabstat.partition_name = tabmod.partition_name(+)
AND tabstat.subpartition_name = tabmod.subpartition_name(+)
ORDER BY
tabstat.owner asc,
tabstat.table_name asc,
tabstat.partition_position asc,
tabstat.subpartition_position asc
/
+182 -182
View File
@@ -1,182 +1,182 @@
/*
*
* Author : Vishal Gupta
* Purpose : Display Tablespace usage
* Parameters : 1 - tablespace_name (Use % as wildcard, Default value '%')
*
* Revision History:
* ===================
* Date Author Description
* --------- ------------ -----------------------------------------
* 14-Jul-15 Vishal Gupta Added tablespace creation_time (Approximated from earliest datafile time)
* 11-Mar-13 Vishal Gupta Fixed temp space calculations
* 02-Apr-12 Vishal Gupta Bug fixes
* 05-Aug-04 Vishal Gupta First Draft
*/
/************************************
* INPUT PARAMETERS
************************************/
UNDEFINE tablespace_name
DEFINE tablespace_name="&&1"
set term off
COLUMN _TABLESPACE_NAME NEW_VALUE TABLESPACE_NAME NOPRINT
SELECT UPPER(DECODE('&&TABLESPACE_NAME','','%','&&TABLESPACE_NAME')) "_TABLESPACE_NAME"
FROM DUAL;
set term on
/************************************
* CONFIGURATION PARAMETERS
************************************/
DEFINE BYTES_FORMAT="999,999"
--DEFINE BYTES_HEADING="KB"
--DEFINE BYTES_DIVIDER="1024"
--DEFINE BYTES_HEADING="MB"
--DEFINE BYTES_DIVIDER="1024/1024"
DEFINE BYTES_HEADING="GB"
DEFINE BYTES_DIVIDER="1024/1024/1024"
DEFINE ROUND_PRECISION=2
DEFINE STAR=4 --Defines how much %usage is represented by one star on Graph
set term off
SET FEED OFF
SELECT (100/&&STAR+2) UsageGraphWidth
FROM DUAL;
SET FEED ON
set term on
PROMPT *****************************************************************
PROMPT * T A B L E S P A C E U S A G E R E P O R T
PROMPT *
PROMPT * Input Parameters
PROMPT * - Tablespace Name = '&&TABLESPACE_NAME'
PROMPT *****************************************************************
COLUMN UsageGraphWidth NOPRINT old_value UGWidth
COLUMN tablespace_name FORMAT a23
COLUMN creation_time HEADING "Creation Time" FORMAT a15
COLUMN alloc HEADING "Alloc(&&BYTES_HEADING)" FORMAT 9,999,999 ON
COLUMN used HEADING "Used&&BYTES_HEADING)" FORMAT 9,999,999 ON
COLUMN free HEADING "Free|(&&BYTES_HEADING)" FORMAT 999,999 ON
COLUMN pct_Used HEADING "%Used" FORMAT 999 ON
COLUMN pct_Free HEADING "%Free" FORMAT 999 ON
COLUMN MAXSIZE HEADING "MaxSize|(&&BYTES_HEADING)" FORMAT 9,999,999 ON
COLUMN Maxfree HEADING "MaxFree|(&&BYTES_HEADING)" FORMAT 9,999,999 ON
COLUMN Max_pct_Used HEADING "MAX|%Used" FORMAT 999 ON
COLUMN Max_pct_Free HEADING "MAX|%Free" FORMAT 999 ON
COLUMN "Usage Graph" FORMAT a27
COLUMN "MaxUsage Graph" FORMAT a27
BREAK ON REPORT
COMPUTE SUM LABEL 'Total' OF alloc FORMAT 99,999,999 ON REPORT
COMPUTE SUM LABEL 'Total' OF used FORMAT 99,999,999.9 ON REPORT
COMPUTE SUM LABEL 'Total' OF free FORMAT 99,999,999.9 ON REPORT
COMPUTE SUM LABEL 'Total' OF maxsize FORMAT 9,999,999.9 ON REPORT
COMPUTE SUM LABEL 'Total' OF maxfree FORMAT 9,999,999.9 ON REPORT
SELECT /*+ CHOOSE */ c.tablespace_name
, c.alloc
, c.used
, c.free
, c.pct_used
, c.pct_free
, '|' || RPAD(NVL(LPAD(' ',CEIL(NVL(c.pct_used,0)/&&STAR),'*'),' '),CEIL(100/&&STAR)) || '|' "Usage Graph"
, c.MAXSIZE
, c.maxfree
, c.max_pct_used
, c.max_pct_free
, '|' || RPAD(NVL(LPAD(' ',CEIL(NVL(c.max_pct_used,0)/&&STAR),'*'),' '),CEIL(100/&&STAR)) || '|' "MaxUsage Graph"
, TO_CHAR(c.creation_time,'DD-MON-YY HH24:MI') creation_time
FROM (
SELECT /*+ CHOOSE */ a.tablespace_name
, c.creation_time
, ROUND(a.bytes_alloc / &&BYTES_DIVIDER, &&ROUND_PRECISION) alloc
, ROUND((a.bytes_alloc - NVL(b.bytes_free, 0)) / &&BYTES_DIVIDER, &&ROUND_PRECISION ) used
, ROUND(NVL(b.bytes_free, 0) / &&BYTES_DIVIDER, &&ROUND_PRECISION) free
, 100 - ROUND((NVL(b.bytes_free, 0) / a.bytes_alloc) * 100, &&ROUND_PRECISION) pct_Used
, ROUND((NVL(b.bytes_free, 0) / a.bytes_alloc) * 100, &&ROUND_PRECISION) pct_Free
, ROUND(a.maxbytes/ &&BYTES_DIVIDER, &&ROUND_PRECISION) MAXSIZE
, ROUND( (maxbytes - a.bytes_alloc + NVL(b.bytes_free, 0) ) / &&BYTES_DIVIDER , &&ROUND_PRECISION) Maxfree
, ROUND(((a.bytes_alloc - NVL(b.bytes_free, 0)) / a.maxbytes) * 100, &&ROUND_PRECISION) Max_pct_Used
, ROUND( ((a.maxbytes - a.bytes_alloc + NVL(b.bytes_free, 0) ) / a.maxbytes) * 100, &&ROUND_PRECISION) Max_pct_Free
FROM ( SELECT /*+ CHOOSE */
f.tablespace_name
, SUM(f.bytes) bytes_alloc
, SUM(DECODE(f.autoextensible, 'YES',GREATEST(f.maxbytes,f.bytes),'NO', f.bytes)) maxbytes
FROM DBA_DATA_FILES f
WHERE f.tablespace_name LIKE '&&tablespace_name'
GROUP BY tablespace_name
) a
, ( SELECT /*+ CHOOSE */
f.tablespace_name
, SUM(f.bytes) bytes_free
FROM DBA_FREE_SPACE f
WHERE f.tablespace_name LIKE '&&tablespace_name'
GROUP BY tablespace_name
) b
, (SELECT t.name tablespace_name, min(creation_time) creation_time
FROM v$tablespace t , v$datafile f
WHERE t.ts# = f.ts#
GROUP BY t.name) c
WHERE a.tablespace_name = b.tablespace_name (+)
AND a.tablespace_name = c.tablespace_name (+)
UNION ALL
SELECT /*+ CHOOSE */
ts.tablespace_name
, c.creation_time
--, ROUND((ts.bytes_used + ts.bytes_free) / &&BYTES_DIVIDER , &&ROUND_PRECISION) alloc
, ROUND( tf.bytes / &&BYTES_DIVIDER , &&ROUND_PRECISION) alloc
, ROUND((ts.bytes_used - ss.free_bytes) / &&BYTES_DIVIDER , &&ROUND_PRECISION) used
, ROUND(((ts.bytes_free) + ss.free_bytes ) / &&BYTES_DIVIDER , &&ROUND_PRECISION) free
, ROUND(((ts.bytes_used - ss.free_bytes ) / (ts.bytes_used + ts.bytes_free))
* 100, &&ROUND_PRECISION) pct_Used
, 100 - ROUND(((ts.bytes_used - ss.free_bytes) / (ts.bytes_used + ts.bytes_free)) * 100, &&ROUND_PRECISION) pct_Free
, ROUND( tf.max_bytes / &&BYTES_DIVIDER , &&ROUND_PRECISION) MaxSize
, ROUND( ((ts.bytes_free) + ss.free_bytes + (tf.max_bytes - (ts.bytes_used + ts.bytes_free) )
) / &&BYTES_DIVIDER , &&ROUND_PRECISION) Maxfree
, ROUND( ( (ts.bytes_used - ss.free_bytes )/tf.max_bytes) * 100, &&ROUND_PRECISION) Max_pct_Used
, 100 - ROUND( ((ts.bytes_used - ss.free_bytes ) /tf.max_bytes )* 100, &&ROUND_PRECISION ) Max_pct_Free
FROM (SELECT tablespace_name
, sum(bytes_used) bytes_used
, sum(bytes_free) bytes_free
FROM v$temp_space_header
WHERE tablespace_name LIKE '&&tablespace_name'
GROUP BY tablespace_name
) ts
, (SELECT tablespace_name
, SUM(bytes) bytes
, SUM(DECODE(autoextensible, 'YES',GREATEST(maxbytes,bytes),'NO', bytes)) max_bytes
FROM dba_temp_files
WHERE tablespace_name LIKE '&&tablespace_name'
GROUP BY tablespace_name
) tf
, (SELECT ss.tablespace_name
, sum(ss.free_blocks * t.block_size) free_bytes
FROM gv$sort_segment ss
, dba_tablespaces t
WHERE ss.tablespace_name = t.tablespace_name
AND ss.tablespace_name LIKE '&&tablespace_name'
GROUP BY ss.tablespace_name
) ss
, dba_tablespaces t
, (SELECT t.name tablespace_name, min(creation_time) creation_time
FROM v$tablespace t , v$tempfile f
WHERE t.ts# = f.ts#
GROUP BY t.name) c
WHERE t.tablespace_name = ts.tablespace_name
AND t.tablespace_name = tf.tablespace_name
AND t.tablespace_name = ss.tablespace_name (+)
AND t.tablespace_name = c.tablespace_name (+)
AND t.tablespace_name LIKE '&&tablespace_name'
) c
ORDER BY 1 asc;
UNDEFINE tablespace_name
/*
*
* Author : Vishal Gupta
* Purpose : Display Tablespace usage
* Parameters : 1 - tablespace_name (Use % as wildcard, Default value '%')
*
* Revision History:
* ===================
* Date Author Description
* --------- ------------ -----------------------------------------
* 14-Jul-15 Vishal Gupta Added tablespace creation_time (Approximated from earliest datafile time)
* 11-Mar-13 Vishal Gupta Fixed temp space calculations
* 02-Apr-12 Vishal Gupta Bug fixes
* 05-Aug-04 Vishal Gupta First Draft
*/
/************************************
* INPUT PARAMETERS
************************************/
UNDEFINE tablespace_name
DEFINE tablespace_name="&&1"
set term off
COLUMN _TABLESPACE_NAME NEW_VALUE TABLESPACE_NAME NOPRINT
SELECT UPPER(DECODE('&&TABLESPACE_NAME','','%','&&TABLESPACE_NAME')) "_TABLESPACE_NAME"
FROM DUAL;
set term on
/************************************
* CONFIGURATION PARAMETERS
************************************/
DEFINE BYTES_FORMAT="999,999"
--DEFINE BYTES_HEADING="KB"
--DEFINE BYTES_DIVIDER="1024"
--DEFINE BYTES_HEADING="MB"
--DEFINE BYTES_DIVIDER="1024/1024"
DEFINE BYTES_HEADING="GB"
DEFINE BYTES_DIVIDER="1024/1024/1024"
DEFINE ROUND_PRECISION=2
DEFINE STAR=4 --Defines how much %usage is represented by one star on Graph
set term off
SET FEED OFF
SELECT (100/&&STAR+2) UsageGraphWidth
FROM DUAL;
SET FEED ON
set term on
PROMPT *****************************************************************
PROMPT * T A B L E S P A C E U S A G E R E P O R T
PROMPT *
PROMPT * Input Parameters
PROMPT * - Tablespace Name = '&&TABLESPACE_NAME'
PROMPT *****************************************************************
COLUMN UsageGraphWidth NOPRINT old_value UGWidth
COLUMN tablespace_name FORMAT a23
COLUMN creation_time HEADING "Creation Time" FORMAT a15
COLUMN alloc HEADING "Alloc(&&BYTES_HEADING)" FORMAT 9,999,999 ON
COLUMN used HEADING "Used&&BYTES_HEADING)" FORMAT 9,999,999 ON
COLUMN free HEADING "Free|(&&BYTES_HEADING)" FORMAT 999,999 ON
COLUMN pct_Used HEADING "%Used" FORMAT 999 ON
COLUMN pct_Free HEADING "%Free" FORMAT 999 ON
COLUMN MAXSIZE HEADING "MaxSize|(&&BYTES_HEADING)" FORMAT 9,999,999 ON
COLUMN Maxfree HEADING "MaxFree|(&&BYTES_HEADING)" FORMAT 9,999,999 ON
COLUMN Max_pct_Used HEADING "MAX|%Used" FORMAT 999 ON
COLUMN Max_pct_Free HEADING "MAX|%Free" FORMAT 999 ON
COLUMN "Usage Graph" FORMAT a27
COLUMN "MaxUsage Graph" FORMAT a27
BREAK ON REPORT
COMPUTE SUM LABEL 'Total' OF alloc FORMAT 99,999,999 ON REPORT
COMPUTE SUM LABEL 'Total' OF used FORMAT 99,999,999.9 ON REPORT
COMPUTE SUM LABEL 'Total' OF free FORMAT 99,999,999.9 ON REPORT
COMPUTE SUM LABEL 'Total' OF maxsize FORMAT 9,999,999.9 ON REPORT
COMPUTE SUM LABEL 'Total' OF maxfree FORMAT 9,999,999.9 ON REPORT
SELECT /*+ CHOOSE */ c.tablespace_name
, c.alloc
, c.used
, c.free
, c.pct_used
, c.pct_free
, '|' || RPAD(NVL(LPAD(' ',CEIL(NVL(c.pct_used,0)/&&STAR),'*'),' '),CEIL(100/&&STAR)) || '|' "Usage Graph"
, c.MAXSIZE
, c.maxfree
, c.max_pct_used
, c.max_pct_free
, '|' || RPAD(NVL(LPAD(' ',CEIL(NVL(c.max_pct_used,0)/&&STAR),'*'),' '),CEIL(100/&&STAR)) || '|' "MaxUsage Graph"
, TO_CHAR(c.creation_time,'DD-MON-YY HH24:MI') creation_time
FROM (
SELECT /*+ CHOOSE */ a.tablespace_name
, c.creation_time
, ROUND(a.bytes_alloc / &&BYTES_DIVIDER, &&ROUND_PRECISION) alloc
, ROUND((a.bytes_alloc - NVL(b.bytes_free, 0)) / &&BYTES_DIVIDER, &&ROUND_PRECISION ) used
, ROUND(NVL(b.bytes_free, 0) / &&BYTES_DIVIDER, &&ROUND_PRECISION) free
, 100 - ROUND((NVL(b.bytes_free, 0) / a.bytes_alloc) * 100, &&ROUND_PRECISION) pct_Used
, ROUND((NVL(b.bytes_free, 0) / a.bytes_alloc) * 100, &&ROUND_PRECISION) pct_Free
, ROUND(a.maxbytes/ &&BYTES_DIVIDER, &&ROUND_PRECISION) MAXSIZE
, ROUND( (maxbytes - a.bytes_alloc + NVL(b.bytes_free, 0) ) / &&BYTES_DIVIDER , &&ROUND_PRECISION) Maxfree
, ROUND(((a.bytes_alloc - NVL(b.bytes_free, 0)) / a.maxbytes) * 100, &&ROUND_PRECISION) Max_pct_Used
, ROUND( ((a.maxbytes - a.bytes_alloc + NVL(b.bytes_free, 0) ) / a.maxbytes) * 100, &&ROUND_PRECISION) Max_pct_Free
FROM ( SELECT /*+ CHOOSE */
f.tablespace_name
, SUM(f.bytes) bytes_alloc
, SUM(DECODE(f.autoextensible, 'YES',GREATEST(f.maxbytes,f.bytes),'NO', f.bytes)) maxbytes
FROM DBA_DATA_FILES f
WHERE f.tablespace_name LIKE '&&tablespace_name'
GROUP BY tablespace_name
) a
, ( SELECT /*+ CHOOSE */
f.tablespace_name
, SUM(f.bytes) bytes_free
FROM DBA_FREE_SPACE f
WHERE f.tablespace_name LIKE '&&tablespace_name'
GROUP BY tablespace_name
) b
, (SELECT t.name tablespace_name, min(creation_time) creation_time
FROM v$tablespace t , v$datafile f
WHERE t.ts# = f.ts#
GROUP BY t.name) c
WHERE a.tablespace_name = b.tablespace_name (+)
AND a.tablespace_name = c.tablespace_name (+)
UNION ALL
SELECT /*+ CHOOSE */
ts.tablespace_name
, c.creation_time
--, ROUND((ts.bytes_used + ts.bytes_free) / &&BYTES_DIVIDER , &&ROUND_PRECISION) alloc
, ROUND( tf.bytes / &&BYTES_DIVIDER , &&ROUND_PRECISION) alloc
, ROUND((ts.bytes_used - ss.free_bytes) / &&BYTES_DIVIDER , &&ROUND_PRECISION) used
, ROUND(((ts.bytes_free) + ss.free_bytes ) / &&BYTES_DIVIDER , &&ROUND_PRECISION) free
, ROUND(((ts.bytes_used - ss.free_bytes ) / (ts.bytes_used + ts.bytes_free))
* 100, &&ROUND_PRECISION) pct_Used
, 100 - ROUND(((ts.bytes_used - ss.free_bytes) / (ts.bytes_used + ts.bytes_free)) * 100, &&ROUND_PRECISION) pct_Free
, ROUND( tf.max_bytes / &&BYTES_DIVIDER , &&ROUND_PRECISION) MaxSize
, ROUND( ((ts.bytes_free) + ss.free_bytes + (tf.max_bytes - (ts.bytes_used + ts.bytes_free) )
) / &&BYTES_DIVIDER , &&ROUND_PRECISION) Maxfree
, ROUND( ( (ts.bytes_used - ss.free_bytes )/tf.max_bytes) * 100, &&ROUND_PRECISION) Max_pct_Used
, 100 - ROUND( ((ts.bytes_used - ss.free_bytes ) /tf.max_bytes )* 100, &&ROUND_PRECISION ) Max_pct_Free
FROM (SELECT tablespace_name
, sum(bytes_used) bytes_used
, sum(bytes_free) bytes_free
FROM v$temp_space_header
WHERE tablespace_name LIKE '&&tablespace_name'
GROUP BY tablespace_name
) ts
, (SELECT tablespace_name
, SUM(bytes) bytes
, SUM(DECODE(autoextensible, 'YES',GREATEST(maxbytes,bytes),'NO', bytes)) max_bytes
FROM dba_temp_files
WHERE tablespace_name LIKE '&&tablespace_name'
GROUP BY tablespace_name
) tf
, (SELECT ss.tablespace_name
, sum(ss.free_blocks * t.block_size) free_bytes
FROM gv$sort_segment ss
, dba_tablespaces t
WHERE ss.tablespace_name = t.tablespace_name
AND ss.tablespace_name LIKE '&&tablespace_name'
GROUP BY ss.tablespace_name
) ss
, dba_tablespaces t
, (SELECT t.name tablespace_name, min(creation_time) creation_time
FROM v$tablespace t , v$tempfile f
WHERE t.ts# = f.ts#
GROUP BY t.name) c
WHERE t.tablespace_name = ts.tablespace_name
AND t.tablespace_name = tf.tablespace_name
AND t.tablespace_name = ss.tablespace_name (+)
AND t.tablespace_name = c.tablespace_name (+)
AND t.tablespace_name LIKE '&&tablespace_name'
) c
ORDER BY 1 asc;
UNDEFINE tablespace_name
+12 -9
View File
@@ -1,10 +1,14 @@
/*
2024-01-27 vplesnila: script creation
*/
col TABLE_OWNER for a25 heading "Owner"
col TABLE_NAME for a30 heading "Table"
col OWNER for a25 heading "Owner"
col INDEX_NAME for a30 heading "Index"
col INDEX_TYPE for a10 heading "Type"
col PARTITIONED for a3 heading "Par"
col PARTITION_POSITION for 999 heading "P#"
col PARTITION_POSITION for 999 heading "P#"
col PARTITION_NAME for a30 heading "Partition"
col SUBPARTITION_NAME for a30 heading "Subpartition"
col PART_HIGHVAL for a32 trunc heading "Partition|high value"
@@ -16,10 +20,10 @@ col NUM_ROWS heading "Rows"
define v_table_owner=&&1
define v_table_name=&&2
select
select
par.TABLE_OWNER
,par.TABLE_NAME
,par.PARTITION_POSITION
,par.PARTITION_POSITION
,par.PARTITION_NAME
,par.NUM_ROWS
,par.HIGH_VALUE PART_HIGHVAL
@@ -28,15 +32,14 @@ select
,sub.NUM_ROWS
,sub.HIGH_VALUE SUBPART_HIGHVAL
,sub.INTERVAL SUBPART_INTERVAL
from
dba_tab_partitions par
left outer join dba_tab_subpartitions sub
from
dba_tab_partitions par
left outer join dba_tab_subpartitions sub
on (par.TABLE_OWNER=sub.TABLE_OWNER) and (par.TABLE_NAME=sub.TABLE_NAME) and(par.PARTITION_NAME=sub.PARTITION_NAME)
where
where
par.table_owner='&&v_table_owner'
and par.table_name='&&v_table_name'
and par.table_name='&&v_table_name'
order by
par.PARTITION_POSITION asc
,sub.SUBPARTITION_POSITION asc
;
+8 -8
View File
@@ -1,5 +1,5 @@
/* Statistics details for table partitions
Usage: @tpstat <owner> <table> <partition>
vplesnila 2024-01-29: creation
@@ -11,9 +11,9 @@ col PARTITION_NAME for a20 head "Partition name"
col last_DML for a20 head "Last DML"
col last_analyzed for a20 head "Last Analyzed"
col STALE_STATS for a7 head "Stale"
col NUM_ROWS head "#Rows"
col PARTITION_POSITION head "P#" for 999
col INSERTS head "Table|INS"
col NUM_ROWS head "#Rows"
col PARTITION_POSITION head "P#" for 999
col INSERTS head "Table|INS"
col UPDATES head "Table|UPD"
col DELETES head "Table|DEL"
col TRUNCATED head "Table|TRUN"
@@ -23,10 +23,10 @@ compute sum of INSERTS on report
compute sum of UPDATES on report
compute sum of DELETES on report
select
select
tabstat.OWNER
,tabstat.TABLE_NAME
,tabstat.PARTITION_POSITION
,tabstat.PARTITION_POSITION
,tabstat.PARTITION_NAME
,tabstat.NUM_ROWS
,tabstat.STALE_STATS
@@ -36,13 +36,13 @@ select
,tabmod.DELETES
,tabmod.TRUNCATED
,tabmod.TIMESTAMP last_DML
from
from
dba_tab_statistics tabstat
,dba_tab_modifications tabmod
WHERE
tabstat.owner = '&&1'
AND tabstat.table_name = '&&2'
AND (tabstat.partition_name like '%&&3%' or tabstat.partition_name is NULL)
AND (tabstat.partition_name like '%&&3%' or tabstat.partition_name is NULL)
AND tabstat.owner = tabmod.table_owner(+)
AND tabstat.table_name = tabmod.table_name(+)
AND tabstat.partition_name = tabmod.partition_name(+)
+1
View File
@@ -79,6 +79,7 @@ COLUMN locked_mode HEADING "Lock Mode" FORMAT a10
COLUMN object_name HEADING "ObjectName" FORMAT a35
SELECT
-- t.xid xid
--, t.ptx_xid
+11 -11
View File
@@ -1,20 +1,20 @@
/* Statistics details for table partitions/subpartitios
Usage: @tspstat <owner> <table> <partition>
vplesnila 2024-01-29: creation
*/
col owner for a20 head "Owner"
col table_name for a25 head "Table name"
col PARTITION_POSITION for 999 heading "P#"
col owner for a20 head "Owner"
col table_name for a25 head "Table name"
col PARTITION_POSITION for 999 heading "P#"
col PARTITION_NAME for a25 head "Partition name"
col SUBPARTITION_NAME for a25 head "Subpartition name"
col last_DML for a20 head "Last DML"
col last_analyzed for a20 head "Last Analyzed"
col STALE_STATS for a7 head "Stale"
col NUM_ROWS head "#Rows"
col INSERTS head "Table|INS"
col NUM_ROWS head "#Rows"
col INSERTS head "Table|INS"
col UPDATES head "Table|UPD"
col DELETES head "Table|DEL"
col TRUNCATED head "Table|TRUN"
@@ -24,10 +24,10 @@ compute sum of INSERTS on report
compute sum of UPDATES on report
compute sum of DELETES on report
select
select
tabstat.OWNER
,tabstat.TABLE_NAME
,tabstat.PARTITION_POSITION
,tabstat.PARTITION_POSITION
,tabstat.PARTITION_NAME
,tabstat.SUBPARTITION_NAME
,tabstat.NUM_ROWS
@@ -38,14 +38,14 @@ select
,tabmod.DELETES
,tabmod.TRUNCATED
,tabmod.TIMESTAMP last_DML
from
from
dba_tab_statistics tabstat
,dba_tab_modifications tabmod
WHERE
tabstat.owner = '&&1'
AND tabstat.table_name = '&&2'
AND (tabstat.partition_name like '%&&3%' or tabstat.partition_name is NULL)
AND (tabstat.subpartition_name like '%&&4%' or tabstat.subpartition_name is NULL)
AND (tabstat.partition_name like '%&&3%' or tabstat.partition_name is NULL)
AND (tabstat.subpartition_name like '%&&4%' or tabstat.subpartition_name is NULL)
AND tabstat.owner = tabmod.table_owner(+)
AND tabstat.table_name = tabmod.table_name(+)
AND tabstat.partition_name = tabmod.partition_name(+)
+19
View File
@@ -0,0 +1,19 @@
col OWNER for a30
col INDEX_OWNER for a30
col INDEX_NAME for a30
col PARTITION_NAME for a30
col SUBPARTITION_NAME for a30
select OWNER,INDEX_NAME from dba_indexes where STATUS='UNUSABLE';
select INDEX_OWNER,INDEX_NAME,PARTITION_NAME from dba_ind_partitions where STATUS='UNUSABLE';
select INDEX_OWNER,INDEX_NAME,SUBPARTITION_NAME from dba_ind_subpartitions where STATUS='UNUSABLE';
select distinct status from dba_indexes
union
select distinct status from dba_ind_partitions
union
select distinct status from dba_ind_subpartitions
/
+8 -9
View File
@@ -1,5 +1,5 @@
/*
based on Jeffrey M. Hunter jhunter@idevelopment.info script / www.idevelopment.info
based on Jeffrey M. Hunter jhunter@idevelopment.info script / www.idevelopment.info
*/
SET ECHO OFF
@@ -47,15 +47,14 @@ SELECT
, s.event event
, s.module module
, s.action action
FROM
gv$session s
INNER JOIN gv$process p ON (s.paddr = p.addr AND s.inst_id = p.inst_id)
INNER JOIN gv$instance i ON (p.inst_id = i.inst_id)
FROM
gv$session s
INNER JOIN gv$process p ON (s.paddr = p.addr AND s.inst_id = p.inst_id)
INNER JOIN gv$instance i ON (p.inst_id = i.inst_id)
WHERE
(&1)
AND s.username IS NOT null
AND s.username not in ('SYS','SYSRAC')
(&1)
AND s.username IS NOT null
AND s.username not in ('SYS','SYSRAC')
ORDER BY
i.instance_name
, s.sid;
+9 -5
View File
@@ -15,6 +15,10 @@
prompt Show Active workarea memory usage for where &1....
COL wrka_operation_type HEAD OPERATION_TYPE FOR A30
col actual_mem_used for 999,999.99
col max_mem_used for 999,999.99
col work_area_size for 999,999.99
col tempseg_size_MB for 999,999.99
SELECT
inst_id
@@ -22,16 +26,16 @@ SELECT
, qcinst_id
, qcsid
, sql_id
-- , sql_exec_start -- 11g+
, sql_exec_start
, operation_type wrka_operation_type
, operation_id plan_line
, policy
, ROUND(active_time/1000000,1) active_sec
, actual_mem_used
, max_mem_used
, work_area_size
, actual_mem_used/1024/1024 actual_mem_used
, max_mem_used/1024/1024 max_mem_used
, work_area_size/1024/1024 work_area_size
, number_passes
, tempseg_size
, tempseg_size/1024/1024 tempseg_size_MB
, tablespace
FROM
gv$sql_workarea_active
+358
View File
@@ -0,0 +1,358 @@
-- Copyright 2018 Tanel Poder. All rights reserved. More info at http://tanelpoder.com
-- Licensed under the Apache License, Version 2.0. See LICENSE.txt for terms & conditions.
--------------------------------------------------------------------------------
--
-- File name: xb (eXplain Better)
--
-- Purpose: Explain a SQL statements execution plan with execution
-- profile directly from library cache - for the last
-- SQL executed in current session (see also xbi.sql)
--
-- Author: Tanel Poder
-- Copyright: (c) https://blog.tanelpoder.com
--
-- Usage: 1) alter session set statistics_level = all;
-- 2) Run the statement you want to explain
-- 3) @xb.sql
--
-- Other: You can add a GATHER_PLAN_STATISTICS hint to the statement instead
-- if you dont want to use "alter session set statistics_level"
-- for some reason (this hint works on Oracle 10.2 and higher)
--
-- TODO: Noteworthy outstanding items are:
-- * formatting, decide what columns to show by default
-- * clone to an @xbx.sql (eXtended version) with wider output and stuff like plan outline hints shown etc
-- currently you can just comment/uncomment sections in this script
-- * clone to @xbad.sql for showing full adaptive plans
-- * add an option to gather/report metrics of all PX slaves
--
--------------------------------------------------------------------------------
prompt -- xb.sql: eXplain Better v1.01 for prev SQL in the current session - by Tanel Poder (https://blog.tanelpoder.com)
set verify off pagesize 5000 tab off lines 999
column xbi_child_number heading "Ch|ld" format 999
column xbi_sql_id heading "SQL_ID" for a13
column xbi_sql_child_number heading "CHLD" for 9999
column xbi_sql_addr heading "ADDRESS"
column xbi_sql_id_text heading ""
column xbi_seconds_ago heading "First Load Time"
column xbi_id heading "Op|ID" for 9999 justify right
column xbi_parent_id heading "Par.|ID" for 9999 justify right
column xbi_id2 heading "Op|ID" for a5 justify right
column xbi_pred heading "Pred|#Col" for a5 justify right
column xbi_pos heading "#Sib|ling" for 9999
column xbi_optimizer heading "Optimizer|Mode" format a10
column xbi_plan_step heading "Operation" for a55
column xbi_plan_line heading "Row Source" for a72
column xbi_qblock_name heading "Query Block|name" for a20 PRINT
column xbi_object_name heading "Object|Name" for a30
column xbi_object_node heading "Object|Node" for a10
column xbi_opt_cost heading "Optimizer|Cost" for 9999999999
column xbi_opt_card heading "Est. rows|per Start" for 999999999999
column xbi_opt_card_times_starts heading "Est. rows|total" for 999999999999
column xbi_opt_card_misestimate heading "Opt. Card.|misestimate" for a15 justify right
column xbi_opt_bytes heading "Estimated|output bytes" for 999999999999
column xbi_predicate_info heading "Predicate Information (identified by operation id):" format a100 word_wrap
column xbi_cpu_cost heading "CPU|Cost" for 9999999
column xbi_io_cost heading "IO|Cost" for 9999999
column xbi_last_output_rows heading "Real #rows|returned" for 9999999999
column xbi_last_starts heading "Rowsource|starts" for 999999999
column xbi_last_rows_start heading "#Rows ret/|per start" for 999999999
column xbi_last_cr_buffer_gets heading "Consistent|gets" for 999999999
column xbi_last_cr_buffer_gets_row heading "Consistent|gets/row" for 999999999
column xbi_last_cu_buffer_gets heading "Current|gets" for 999999999
column xbi_last_cu_buffer_gets_row heading "Current|gets/row" for 999999999
column xbi_last_disk_reads heading "Physical|read blks" for 999999999
column xbi_last_disk_writes heading "Physical|write blks" for 999999999
column xbi_last_elapsed_time_ms heading "cumulative ms|spent in branch" for 9,999,999.99 noprint
column xbi_self_elapsed_time_ms heading "ms spent in|this operation" for 9,999,999.99
column xbi_self_cr_buffer_gets heading "Consistent|gets" for 999999999
column xbi_self_cr_buffer_gets_row heading "Consistent|gets/row" for 999999999
column xbi_self_cu_buffer_gets heading "Current|gets" for 999999999
column xbi_self_cu_buffer_gets_row heading "Current|gets/row" for 999999999
column xbi_self_disk_reads heading "Physical|read blks" for 999999999
column xbi_self_disk_writes heading "Physical|write blks" for 999999999
column xbi_last_memory_used heading "Memory|used (MB)" for 9,999,999.99
column xbi_last_execution heading "Workarea|Passes" for a13
column xbi_sql_plan_hash_value heading "Plan Hash Value" for 9999999999
column xbi_plan_hash_value_text noprint
column xbi_outline_hints heading "Outline Hints" for a120 word_wrap
column xbi_notes heading "Plan|Notes" for a120 word_wrap
column xbi_sql_id heading "SQL_ID" for a13 new_value xbi_sql_id
column xbi_sql_child_number heading "CHLD" for 9999 new_value xbi_sql_child_number
column xbi_sql_addr heading "ADDRESS" new_value xbi_sql_addr
set feedback off
select
'Cursor: ' xbi_sql_id_text,
sql.sql_id xbi_sql_id,
sql.child_number xbi_sql_child_number,
sql.address xbi_sql_addr,
' PLAN_HASH_VALUE: ' xbi_plan_hash_value_text,
sql.plan_hash_value xbi_sql_plan_hash_value,
'Statement first parsed at: '|| sql.first_load_time ||' - '||
round( (sysdate - to_date(sql.first_load_time,'YYYY-MM-DD/HH24:MI:SS'))*86400 ) || ' seconds ago' xbi_seconds_ago
from
v$sql sql,
all_users usr
where
sql.parsing_user_id = usr.user_id
and (sql.sql_id,sql.child_number,sql.address) = (SELECT prev_sql_id,prev_child_number,prev_sql_addr
FROM v$session WHERE sid = USERENV('SID'))
/
WITH sq AS (
SELECT
sp.id, sp.parent_id, sp.operation, sp.options, sp.object_owner, sp.object_name
, ss.last_elapsed_time, ss.last_cr_buffer_gets, ss.last_cu_buffer_gets, ss.last_disk_reads, ss.last_disk_writes
FROM v$sql_plan_statistics_all ss INNER JOIN
v$sql_plan sp
ON (
sp.sql_id=ss.sql_id
AND sp.child_number=ss.child_number
AND sp.address=ss.address
AND sp.id=ss.id
)
AND sp.sql_id='&xbi_sql_id'
AND sp.child_number = TO_NUMBER('&xbi_sql_child_number')
AND sp.address = hextoraw('&xbi_sql_addr')
), deltas AS (
SELECT
par.id
, par.last_elapsed_time - SUM(chi.last_elapsed_time ) self_elapsed_time
, par.last_cr_buffer_gets - SUM(chi.last_cr_buffer_gets) self_cr_buffer_gets
, par.last_cu_buffer_gets - SUM(chi.last_cu_buffer_gets) self_cu_buffer_gets
, par.last_disk_reads - SUM(chi.last_disk_reads ) self_disk_reads
, par.last_disk_writes - SUM(chi.last_disk_writes ) self_disk_writes
FROM sq par LEFT OUTER JOIN
sq chi
ON chi.parent_id = par.id
GROUP BY
par.id
, par.last_elapsed_time, par.last_cr_buffer_gets, par.last_cu_buffer_gets, par.last_disk_reads, par.last_disk_writes
), combined AS (
SELECT sq.id, sq.parent_id, sq.operation, sq.options
, sq.object_owner, sq.object_name
, sq.last_elapsed_time
, sq.last_cr_buffer_gets
, sq.last_cu_buffer_gets
, sq.last_disk_reads
, sq.last_disk_writes
, NVL(deltas.self_elapsed_time , sq.last_elapsed_time) self_elapsed_time
, NVL(deltas.self_cr_buffer_gets , sq.last_cr_buffer_gets) self_cr_buffer_gets
, NVL(deltas.self_cu_buffer_gets , sq.last_cu_buffer_gets) self_cu_buffer_gets
, NVL(deltas.self_disk_reads , sq.last_disk_reads) self_disk_reads
, NVL(deltas.self_disk_writes , sq.last_disk_writes) self_disk_writes
FROM
sq, deltas
WHERE
sq.id = deltas.id
),
adaptive_display_map AS (
SELECT
TO_NUMBER(EXTRACT(column_value, '/row/@op' )) id
, TO_NUMBER(EXTRACT(column_value, '/row/@par')) parent_id
, TO_NUMBER(EXTRACT(column_value, '/row/@dis')) display_id
, TO_NUMBER(EXTRACT(column_value, '/row/@dep')) depth
, TO_NUMBER(EXTRACT(column_value, '/row/@skp')) skip
FROM
v$sql_plan
, TABLE(XMLSEQUENCE(EXTRACT(XMLTYPE(other_xml),'/*/display_map/row')))
WHERE
sql_id = '&xbi_sql_id'
AND child_number = TO_NUMBER('&xbi_sql_child_number')
AND address = hextoraw('&xbi_sql_addr')
AND other_xml IS NOT NULL
)
select
LPAD(
CASE WHEN p.filter_predicates IS NOT NULL THEN 'F' ELSE ' ' END ||
CASE WHEN p.access_predicates IS NOT NULL THEN CASE WHEN p.options LIKE 'STORAGE %' THEN 'S' ELSE 'A' END ELSE '' END ||
CASE p.search_columns WHEN 0 THEN NULL ELSE '#'||TO_CHAR(p.search_columns) END
, 5) xbi_pred,
NVL(CASE WHEN adm.skip IS NULL THEN NULL
WHEN adm.skip = 0 THEN adm.display_id
WHEN adm.skip = 1 THEN NULL
END
, p.id) xbi_id,
nvl(adm2.parent_id, p.parent_id) xbi_parent_id,
CASE WHEN p.id != 0 THEN p.position END xbi_pos,
LPAD(' ',NVL(adm.depth,p.depth),' ')|| p.operation || ' ' || p.options ||' '
||nvl2(p.object_name, '['||p.object_name||']', null)
xbi_plan_line,
CASE WHEN p.id = 0 THEN '>>> Plan totals >>>' ELSE p.qblock_name END xbi_qblock_name,
-- p.object_node xbi_object_node,
-- p.distribution xbi_distribution,
-- lpad(decode(p.id,0,'T ','')||trim(to_char(round(decode(p.id,0,c.last_elapsed_time,c.self_elapsed_time) /1000,2),'9,999,999.00')), 14) xbi_self_elapsed_time_ms,
round(decode(p.id,0,c.last_elapsed_time,c.self_elapsed_time) /1000,2) xbi_self_elapsed_time_ms,
decode(p.id,0,c.last_cr_buffer_gets,c.self_cr_buffer_gets) xbi_self_cr_buffer_gets,
ps.last_starts xbi_last_starts,
ps.last_output_rows xbi_last_output_rows,
p.cardinality * ps.last_starts xbi_opt_card_times_starts,
regexp_replace(lpad(to_char(round(
CASE WHEN (DECODE(ps.last_output_rows,0,1,ps.last_output_rows) / DECODE(p.cardinality*ps.last_starts,0,1,p.cardinality*ps.last_starts)) > 1 THEN -(DECODE(ps.last_output_rows,0,1,ps.last_output_rows) / DECODE(p.cardinality*ps.last_starts,0,1,p.cardinality*ps.last_starts))
WHEN (DECODE(ps.last_output_rows,0,1,ps.last_output_rows) / DECODE(p.cardinality*ps.last_starts,0,1,p.cardinality*ps.last_starts)) < 1 THEN 1/(DECODE(ps.last_output_rows,0,1,ps.last_output_rows) / DECODE(p.cardinality*ps.last_starts,0,1,p.cardinality*ps.last_starts))
WHEN (DECODE(ps.last_output_rows,0,1,ps.last_output_rows) / DECODE(p.cardinality*ps.last_starts,0,1,p.cardinality*ps.last_starts)) = 1 THEN 1
ELSE null
END
,0))||'x',15),'^ *x$') xbi_opt_card_misestimate,
-- c.self_cr_buffer_gets xbi_self_cr_buffer_gets,
-- c.self_cr_buffer_gets / DECODE(ps.last_output_rows,0,1,ps.last_output_rows) xbi_self_cr_buffer_gets_row,
decode(p.id,0,c.last_cu_buffer_gets,c.self_cu_buffer_gets) xbi_self_cu_buffer_gets,
-- c.self_cu_buffer_gets / DECODE(ps.last_output_rows,0,1,ps.last_output_rows) xbi_self_cu_buffer_gets_row,
decode(p.id,0,c.last_disk_reads,c.self_disk_reads) xbi_self_disk_reads,
decode(p.id,0,c.last_disk_writes,c.self_disk_writes) xbi_self_disk_writes,
round(ps.last_elapsed_time/1000,2) xbi_last_elapsed_time_ms,
-- ps.last_cr_buffer_gets xbi_last_cr_buffer_gets,
-- ps.last_cr_buffer_gets / DECODE(ps.last_output_rows,0,1,ps.last_output_rows) xbi_last_cr_buffer_gets_row,
-- ps.last_cu_buffer_gets xbi_last_cu_buffer_gets,
-- ps.last_cu_buffer_gets / DECODE(ps.last_output_rows,0,1,ps.last_output_rows) xbi_last_cu_buffer_gets_row,
-- ps.last_disk_reads xbi_last_disk_reads,
-- ps.last_disk_writes xbi_last_disk_writes,
ps.last_memory_used/1048576 xbi_last_memory_used,
ps.last_execution xbi_last_execution,
p.cost xbi_opt_cost
-- p.bytes xbi_opt_bytes,
-- p.cpu_cost xbi_cpu_cost,
-- p.io_cost xbi_io_cost,
-- p.other_tag,
-- p.other,
-- p.access_predicates,
-- p.filter_predicates,
from
v$sql_plan p
, v$sql_plan_statistics_all ps
, combined c
, adaptive_display_map adm
, adaptive_display_map adm2
where
p.address = ps.address (+)
and p.sql_id = ps.sql_id (+)
and p.plan_hash_value = ps.plan_hash_value (+)
and p.child_number = ps.child_number (+)
and p.id = ps.id (+)
and p.id = adm.id (+)
and adm.id = adm2.id (+)
and (adm.id IS NULL or adm.skip = 0)
and p.sql_id = '&xbi_sql_id'
and p.address = hextoraw('&xbi_sql_addr')
and p.child_number = TO_NUMBER(&xbi_sql_child_number)
and ps.id = c.id (+)
order by
p.id asc
/
WITH adaptive_display_map AS (
SELECT
TO_NUMBER(EXTRACT(column_value, '/row/@op' )) id
, TO_NUMBER(EXTRACT(column_value, '/row/@dis')) display_id
, TO_NUMBER(EXTRACT(column_value, '/row/@skp')) skip
FROM
v$sql_plan
, TABLE(XMLSEQUENCE(EXTRACT(XMLTYPE(other_xml),'/*/display_map/row')))
WHERE
sql_id = '&xbi_sql_id'
AND child_number = TO_NUMBER('&xbi_sql_child_number')
AND address = hextoraw('&xbi_sql_addr')
AND other_xml IS NOT NULL
AND TO_NUMBER(EXTRACT(column_value, '/row/@skp')) != 1
)
select
xbi_id2,
xbi_qblock_name,
substr(dummy,1,0)||'-' " ", -- there's an ugly reason (bug) for this hack
xbi_predicate_info
from (
select
sp.sql_id xbi_sql_id,
LPAD(NVL(CASE WHEN adm.skip IS NULL THEN NULL
WHEN adm.skip = 0 THEN adm.display_id
WHEN adm.skip = 1 THEN NULL
END
, sp.id), 5, ' ') xbi_id2,
sp.filter_predicates dummy, -- looks like there's a bug in 11.2.0.3 where both pred cols have to be selected
CASE WHEN sp.options LIKE 'STORAGE %' THEN 'storage' ELSE 'access' END||'('|| substr(sp.access_predicates,1,3989) || ')' xbi_predicate_info,
sp.qblock_name xbi_qblock_name
from
v$sql_plan sp
, adaptive_display_map adm
where
sp.sql_id = '&xbi_sql_id'
and sp.child_number = TO_NUMBER(&xbi_sql_child_number)
AND sp.address = HEXTORAW('&xbi_sql_addr')
and sp.access_predicates is not null
and sp.id = adm.id (+)
union all
select
sp.sql_id xbi_sql_id,
--lpad(sp.id, 5, ' ') xbi_id2,
LPAD(NVL(CASE WHEN adm.skip IS NULL THEN NULL
WHEN adm.skip = 0 THEN adm.display_id
WHEN adm.skip = 1 THEN NULL
END
, sp.id), 5, ' ') xbi_id2,
sp.access_predicates dummy,
'filter('|| substr(sp.filter_predicates,1,3989) || ')' xbi_predicate_info,
sp.qblock_name xbi_qblock_name
from
v$sql_plan sp
, adaptive_display_map adm
where
sp.sql_id = '&xbi_sql_id'
and sp.child_number = TO_NUMBER(&xbi_sql_child_number)
and sp.address = HEXTORAW('&xbi_sql_addr')
and sp.filter_predicates is not null
and sp.id = adm.id (+)
)
order by
xbi_id2 asc,
xbi_predicate_info asc
/
-- this query can return ORA-600 in Oracle 10.2 due to Bug 5497611 - OERI[qctVCO:csform] from Xquery using XMLType constructor (Doc ID 5497611.8)
WITH sq AS (
SELECT other_xml
FROM v$sql_plan p
WHERE
p.sql_id = '&xbi_sql_id'
AND p.child_number = &xbi_sql_child_number
AND p.address = hextoraw('&xbi_sql_addr')
AND p.other_xml IS NOT NULL -- (the other_xml is not guaranteed to always be on plan line 1)
)
SELECT ' *' " ", 'Cardinality feedback = yes' xbi_notes FROM sq WHERE extractvalue(xmltype(sq.other_xml), '/*/info[@type = "cardinality_feedback"]') = 'yes'
UNION ALL SELECT ' *', 'SQL Stored Outline used = ' ||extractvalue(xmltype(sq.other_xml), '/*/info[@type = "outline"]') FROM sq WHERE extractvalue(xmltype(sq.other_xml), '/*/info[@type = "outline"]') IS NOT NULL
UNION ALL SELECT ' *', 'SQL Patch used = ' ||extractvalue(xmltype(sq.other_xml), '/*/info[@type = "sql_patch"]') FROM sq WHERE extractvalue(xmltype(sq.other_xml), '/*/info[@type = "sql_patch"]') IS NOT NULL
UNION ALL SELECT ' *', 'SQL Profile used = ' ||extractvalue(xmltype(sq.other_xml), '/*/info[@type = "sql_profile"]') FROM sq WHERE extractvalue(xmltype(sq.other_xml), '/*/info[@type = "sql_profile"]') IS NOT NULL
UNION ALL SELECT ' *', 'SQL Plan Baseline used = ' ||extractvalue(xmltype(sq.other_xml), '/*/info[@type = "baseline"]') FROM sq WHERE extractvalue(xmltype(sq.other_xml), '/*/info[@type = "baseline"]') IS NOT NULL
UNION ALL SELECT ' *', 'Adaptive Plan = ' ||extractvalue(xmltype(sq.other_xml), '/*/info[@type = "adaptive_plan"]') FROM sq WHERE extractvalue(xmltype(sq.other_xml), '/*/info[@type = "adaptive_plan"]') IS NOT NULL
/
-- === Outline Hints ===
WITH sq AS (
SELECT other_xml
FROM v$sql_plan p
WHERE
p.sql_id = '&xbi_sql_id'
AND p.child_number = &xbi_sql_child_number
AND p.address = hextoraw('&xbi_sql_addr')
AND p.other_xml IS NOT NULL
)
SELECT
SUBSTR(EXTRACTVALUE(VALUE(d), '/hint'),1,4000) xbi_outline_hints
FROM
sq
, TABLE(XMLSEQUENCE(EXTRACT(XMLTYPE(sq.other_xml), '/*/outline_data/hint'))) D
/
set feedback on
PROMPT
+365
View File
@@ -0,0 +1,365 @@
-- Copyright 2018 Tanel Poder. All rights reserved. More info at http://tanelpoder.com
-- Licensed under the Apache License, Version 2.0. See LICENSE.txt for terms & conditions.
--------------------------------------------------------------------------------
--
-- File name: xb (eXplain Better)
--
-- Purpose: Explain a SQL statements execution plan with execution
-- profile directly from library cache - for the last
-- SQL executed in current session (see also xbi.sql)
--
-- Author: Tanel Poder
-- Copyright: (c) https://blog.tanelpoder.com
--
-- Usage: 1) alter session set statistics_level = all;
-- 2) Run the statement you want to explain
-- 3) @xb.sql
--
-- Other: You can add a GATHER_PLAN_STATISTICS hint to the statement instead
-- if you dont want to use "alter session set statistics_level"
-- for some reason (this hint works on Oracle 10.2 and higher)
--
-- TODO: Noteworthy outstanding items are:
-- * formatting, decide what columns to show by default
-- * clone to an @xbx.sql (eXtended version) with wider output and stuff like plan outline hints shown etc
-- currently you can just comment/uncomment sections in this script
-- * clone to @xbad.sql for showing full adaptive plans
-- * add an option to gather/report metrics of all PX slaves
--
--------------------------------------------------------------------------------
def xbi_sql_id=&1
def xbi_sql_child_number=&2
def xbi_sql_addr="TODO"
prompt -- xbi.sql: eXplain Better v1.01 for sql_id=&xbi_sql_id child=&xbi_sql_child_number - by Tanel Poder (https://blog.tanelpoder.com)
set verify off pagesize 5000 tab off lines 999
column xbi_child_number heading "Ch|ld" format 999
column xbi_sql_id heading "SQL_ID" for a13
column xbi_sql_child_number heading "CHLD" for 9999
column xbi_sql_addr heading "ADDRESS"
column xbi_sql_id_text heading ""
column xbi_seconds_ago heading "First Load Time"
column xbi_id heading "Op|ID" for 9999 justify right
column xbi_parent_id heading "Par.|ID" for 9999 justify right
column xbi_id2 heading "Op|ID" for a5 justify right
column xbi_pred heading "Pred|#Col" for a5 justify right
column xbi_pos heading "#Sib|ling" for 9999
column xbi_optimizer heading "Optimizer|Mode" format a10
column xbi_plan_step heading "Operation" for a55
column xbi_plan_line heading "Row Source" for a72
column xbi_qblock_name heading "Query Block|name" for a20 PRINT
column xbi_object_name heading "Object|Name" for a30
column xbi_object_node heading "Object|Node" for a10
column xbi_opt_cost heading "Optimizer|Cost" for 9999999999
column xbi_opt_card heading "Est. rows|per Start" for 999999999999
column xbi_opt_card_times_starts heading "Est. rows|total" for 999999999999
column xbi_opt_card_misestimate heading "Opt. Card.|misestimate" for a15 justify right
column xbi_opt_bytes heading "Estimated|output bytes" for 999999999999
column xbi_predicate_info heading "Predicate Information (identified by operation id):" format a100 word_wrap
column xbi_cpu_cost heading "CPU|Cost" for 9999999
column xbi_io_cost heading "IO|Cost" for 9999999
column xbi_last_output_rows heading "Real #rows|returned" for 9999999999
column xbi_last_starts heading "Rowsource|starts" for 999999999
column xbi_last_rows_start heading "#Rows ret/|per start" for 999999999
column xbi_last_cr_buffer_gets heading "Consistent|gets" for 999999999
column xbi_last_cr_buffer_gets_row heading "Consistent|gets/row" for 999999999
column xbi_last_cu_buffer_gets heading "Current|gets" for 999999999
column xbi_last_cu_buffer_gets_row heading "Current|gets/row" for 999999999
column xbi_last_disk_reads heading "Physical|read blks" for 999999999
column xbi_last_disk_writes heading "Physical|write blks" for 999999999
column xbi_last_elapsed_time_ms heading "cumulative ms|spent in branch" for 9,999,999.99 noprint
column xbi_self_elapsed_time_ms heading "ms spent in|this operation" for 9,999,999.99
column xbi_self_cr_buffer_gets heading "Consistent|gets" for 999999999
column xbi_self_cr_buffer_gets_row heading "Consistent|gets/row" for 999999999
column xbi_self_cu_buffer_gets heading "Current|gets" for 999999999
column xbi_self_cu_buffer_gets_row heading "Current|gets/row" for 999999999
column xbi_self_disk_reads heading "Physical|read blks" for 999999999
column xbi_self_disk_writes heading "Physical|write blks" for 999999999
column xbi_last_memory_used heading "Memory|used (MB)" for 9,999,999.99
column xbi_last_execution heading "Workarea|Passes" for a13
column xbi_sql_plan_hash_value heading "Plan Hash Value" for 9999999999
column xbi_plan_hash_value_text noprint
column xbi_outline_hints heading "Outline Hints" for a120 word_wrap
column xbi_notes heading "Plan|Notes" for a120 word_wrap
column xbi_sql_id heading "SQL_ID" for a13 new_value xbi_sql_id
column xbi_sql_child_number heading "CHLD" for 9999 new_value xbi_sql_child_number
column xbi_sql_addr heading "ADDRESS" new_value xbi_sql_addr
set feedback off
select
'Cursor: ' xbi_sql_id_text,
sql.sql_id xbi_sql_id,
sql.child_number xbi_sql_child_number,
sql.address xbi_sql_addr,
' PLAN_HASH_VALUE: ' xbi_plan_hash_value_text,
sql.plan_hash_value xbi_sql_plan_hash_value,
'Statement first parsed at: '|| sql.first_load_time ||' - '||
round( (sysdate - to_date(sql.first_load_time,'YYYY-MM-DD/HH24:MI:SS'))*86400 ) || ' seconds ago' xbi_seconds_ago
from
v$sql sql,
all_users usr
where
sql.parsing_user_id = usr.user_id
and (sql.sql_id,sql.child_number) = (('&xbi_sql_id', TO_NUMBER('&xbi_sql_child_number')))
and is_obsolete = 'N'
/
WITH sq AS (
SELECT
sp.id, sp.parent_id, sp.operation, sp.options, sp.object_owner, sp.object_name
, ss.last_elapsed_time, ss.last_cr_buffer_gets, ss.last_cu_buffer_gets, ss.last_disk_reads, ss.last_disk_writes
FROM v$sql_plan_statistics_all ss INNER JOIN
v$sql_plan sp
ON (
sp.sql_id=ss.sql_id
AND sp.child_number=ss.child_number
AND sp.address=ss.address
AND sp.id=ss.id
)
AND sp.sql_id='&xbi_sql_id'
AND sp.child_number = TO_NUMBER('&xbi_sql_child_number')
AND sp.address = hextoraw('&xbi_sql_addr')
), deltas AS (
SELECT
par.id
, par.last_elapsed_time - SUM(chi.last_elapsed_time ) self_elapsed_time
, par.last_cr_buffer_gets - SUM(chi.last_cr_buffer_gets) self_cr_buffer_gets
, par.last_cu_buffer_gets - SUM(chi.last_cu_buffer_gets) self_cu_buffer_gets
, par.last_disk_reads - SUM(chi.last_disk_reads ) self_disk_reads
, par.last_disk_writes - SUM(chi.last_disk_writes ) self_disk_writes
FROM sq par LEFT OUTER JOIN
sq chi
ON chi.parent_id = par.id
GROUP BY
par.id
, par.last_elapsed_time, par.last_cr_buffer_gets, par.last_cu_buffer_gets, par.last_disk_reads, par.last_disk_writes
), combined AS (
SELECT sq.id, sq.parent_id, sq.operation, sq.options
, sq.object_owner, sq.object_name
, sq.last_elapsed_time
, sq.last_cr_buffer_gets
, sq.last_cu_buffer_gets
, sq.last_disk_reads
, sq.last_disk_writes
, NVL(deltas.self_elapsed_time , sq.last_elapsed_time) self_elapsed_time
, NVL(deltas.self_cr_buffer_gets , sq.last_cr_buffer_gets) self_cr_buffer_gets
, NVL(deltas.self_cu_buffer_gets , sq.last_cu_buffer_gets) self_cu_buffer_gets
, NVL(deltas.self_disk_reads , sq.last_disk_reads) self_disk_reads
, NVL(deltas.self_disk_writes , sq.last_disk_writes) self_disk_writes
FROM
sq, deltas
WHERE
sq.id = deltas.id
),
adaptive_display_map AS (
SELECT
TO_NUMBER(EXTRACT(column_value, '/row/@op' )) id
, TO_NUMBER(EXTRACT(column_value, '/row/@par')) parent_id
, TO_NUMBER(EXTRACT(column_value, '/row/@dis')) display_id
, TO_NUMBER(EXTRACT(column_value, '/row/@dep')) depth
, TO_NUMBER(EXTRACT(column_value, '/row/@skp')) skip
FROM
v$sql_plan
, TABLE(XMLSEQUENCE(EXTRACT(XMLTYPE(other_xml),'/*/display_map/row')))
WHERE
sql_id = '&xbi_sql_id'
AND child_number = TO_NUMBER('&xbi_sql_child_number')
AND address = hextoraw('&xbi_sql_addr')
AND other_xml IS NOT NULL
)
select
LPAD(
CASE WHEN p.filter_predicates IS NOT NULL THEN 'F' ELSE ' ' END ||
CASE WHEN p.access_predicates IS NOT NULL THEN CASE WHEN p.options LIKE 'STORAGE %' THEN 'S' ELSE 'A' END ELSE '' END ||
CASE p.search_columns WHEN 0 THEN NULL ELSE '#'||TO_CHAR(p.search_columns) END
, 5) xbi_pred,
NVL(CASE WHEN adm.skip IS NULL THEN NULL
WHEN adm.skip = 0 THEN adm.display_id
WHEN adm.skip = 1 THEN NULL
END
, p.id) xbi_id,
nvl(adm2.parent_id, p.parent_id) xbi_parent_id,
CASE WHEN p.id != 0 THEN p.position END xbi_pos,
LPAD(' ',NVL(adm.depth,p.depth),' ')|| p.operation || ' ' || p.options ||' '
||nvl2(p.object_name, '['||p.object_name||']', null)
xbi_plan_line,
CASE WHEN p.id = 0 THEN '>>> Plan totals >>>' ELSE p.qblock_name END xbi_qblock_name,
-- p.object_node xbi_object_node,
-- p.object_owner,
-- p.object_name,
-- p.object_alias,
-- p.distribution xbi_distribution,
-- lpad(decode(p.id,0,'T ','')||trim(to_char(round(decode(p.id,0,c.last_elapsed_time,c.self_elapsed_time) /1000,2),'9,999,999.00')), 14) xbi_self_elapsed_time_ms,
round(decode(p.id,0,c.last_elapsed_time,c.self_elapsed_time) /1000,2) xbi_self_elapsed_time_ms,
decode(p.id,0,c.last_cr_buffer_gets,c.self_cr_buffer_gets) xbi_self_cr_buffer_gets,
ps.last_starts xbi_last_starts,
ps.last_output_rows xbi_last_output_rows,
p.cardinality * ps.last_starts xbi_opt_card_times_starts,
regexp_replace(lpad(to_char(round(
CASE WHEN (NULLIF(ps.last_output_rows / NULLIF(p.cardinality * ps.last_starts, 0),0)) > 1 THEN -(NULLIF(ps.last_output_rows / NULLIF(p.cardinality * ps.last_starts, 0),0))
WHEN (NULLIF(ps.last_output_rows / NULLIF(p.cardinality * ps.last_starts, 0),0)) < 1 THEN 1/(NULLIF(ps.last_output_rows / NULLIF(p.cardinality * ps.last_starts, 0),0))
WHEN (NULLIF(ps.last_output_rows / NULLIF(p.cardinality * ps.last_starts, 0),0)) = 1 THEN 1
ELSE null
END
,0))||'x',15),'^ *x$') xbi_opt_card_misestimate,
-- c.self_cr_buffer_gets xbi_self_cr_buffer_gets,
-- c.self_cr_buffer_gets / DECODE(ps.last_output_rows,0,1,ps.last_output_rows) xbi_self_cr_buffer_gets_row,
decode(p.id,0,c.last_cu_buffer_gets,c.self_cu_buffer_gets) xbi_self_cu_buffer_gets,
-- c.self_cu_buffer_gets / DECODE(ps.last_output_rows,0,1,ps.last_output_rows) xbi_self_cu_buffer_gets_row,
decode(p.id,0,c.last_disk_reads,c.self_disk_reads) xbi_self_disk_reads,
decode(p.id,0,c.last_disk_writes,c.self_disk_writes) xbi_self_disk_writes,
round(ps.last_elapsed_time/1000,2) xbi_last_elapsed_time_ms,
-- ps.last_cr_buffer_gets xbi_last_cr_buffer_gets,
-- ps.last_cr_buffer_gets / DECODE(ps.last_output_rows,0,1,ps.last_output_rows) xbi_last_cr_buffer_gets_row,
-- ps.last_cu_buffer_gets xbi_last_cu_buffer_gets,
-- ps.last_cu_buffer_gets / DECODE(ps.last_output_rows,0,1,ps.last_output_rows) xbi_last_cu_buffer_gets_row,
-- ps.last_disk_reads xbi_last_disk_reads,
-- ps.last_disk_writes xbi_last_disk_writes,
ps.last_memory_used/1048576 xbi_last_memory_used,
ps.last_execution xbi_last_execution,
p.cost xbi_opt_cost
-- p.bytes xbi_opt_bytes,
-- p.cpu_cost xbi_cpu_cost,
-- p.io_cost xbi_io_cost,
-- p.other_tag,
-- p.other,
-- p.access_predicates,
-- p.filter_predicates,
from
v$sql_plan p
, v$sql_plan_statistics_all ps
, combined c
, adaptive_display_map adm
, adaptive_display_map adm2
where
p.address = ps.address (+)
and p.sql_id = ps.sql_id (+)
and p.plan_hash_value = ps.plan_hash_value (+)
and p.child_number = ps.child_number (+)
and p.id = ps.id (+)
and p.id = adm.id (+)
and adm.id = adm2.id (+)
and (adm.id IS NULL or adm.skip = 0)
and p.sql_id = '&xbi_sql_id'
and p.address = hextoraw('&xbi_sql_addr')
and p.child_number = TO_NUMBER(&xbi_sql_child_number)
and ps.id = c.id (+)
order by
p.id asc
/
WITH adaptive_display_map AS (
SELECT
TO_NUMBER(EXTRACT(column_value, '/row/@op' )) id
, TO_NUMBER(EXTRACT(column_value, '/row/@dis')) display_id
, TO_NUMBER(EXTRACT(column_value, '/row/@skp')) skip
FROM
v$sql_plan
, TABLE(XMLSEQUENCE(EXTRACT(XMLTYPE(other_xml),'/*/display_map/row')))
WHERE
sql_id = '&xbi_sql_id'
AND child_number = TO_NUMBER('&xbi_sql_child_number')
AND address = hextoraw('&xbi_sql_addr')
AND other_xml IS NOT NULL
AND TO_NUMBER(EXTRACT(column_value, '/row/@skp')) != 1
)
select
xbi_id2,
xbi_qblock_name,
substr(dummy,1,0)||'-' " ", -- there's an ugly reason (bug) for this hack
xbi_predicate_info
from (
select
sp.sql_id xbi_sql_id,
LPAD(NVL(CASE WHEN adm.skip IS NULL THEN NULL
WHEN adm.skip = 0 THEN adm.display_id
WHEN adm.skip = 1 THEN NULL
END
, sp.id), 5, ' ') xbi_id2,
sp.filter_predicates dummy, -- looks like there's a bug in 11.2.0.3 where both pred cols have to be selected
CASE WHEN sp.options LIKE 'STORAGE %' THEN 'storage' ELSE 'access' END||'('|| substr(sp.access_predicates,1,3989) || ')' xbi_predicate_info,
sp.qblock_name xbi_qblock_name
from
v$sql_plan sp
, adaptive_display_map adm
where
sp.sql_id = '&xbi_sql_id'
and sp.child_number = TO_NUMBER(&xbi_sql_child_number)
AND sp.address = HEXTORAW('&xbi_sql_addr')
and sp.access_predicates is not null
and sp.id = adm.id (+)
union all
select
sp.sql_id xbi_sql_id,
--lpad(sp.id, 5, ' ') xbi_id2,
LPAD(NVL(CASE WHEN adm.skip IS NULL THEN NULL
WHEN adm.skip = 0 THEN adm.display_id
WHEN adm.skip = 1 THEN NULL
END
, sp.id), 5, ' ') xbi_id2,
sp.access_predicates dummy,
'filter('|| substr(sp.filter_predicates,1,3989) || ')' xbi_predicate_info,
sp.qblock_name xbi_qblock_name
from
v$sql_plan sp
, adaptive_display_map adm
where
sp.sql_id = '&xbi_sql_id'
and sp.child_number = TO_NUMBER(&xbi_sql_child_number)
and sp.address = HEXTORAW('&xbi_sql_addr')
and sp.filter_predicates is not null
and sp.id = adm.id (+)
)
order by
xbi_id2 asc,
xbi_predicate_info asc
/
-- this query can return ORA-600 in Oracle 10.2 due to Bug 5497611 - OERI[qctVCO:csform] from Xquery using XMLType constructor (Doc ID 5497611.8)
WITH sq AS (
SELECT other_xml
FROM v$sql_plan p
WHERE
p.sql_id = '&xbi_sql_id'
AND p.child_number = &xbi_sql_child_number
AND p.address = hextoraw('&xbi_sql_addr')
AND p.other_xml IS NOT NULL -- (the other_xml is not guaranteed to always be on plan line 1)
)
SELECT ' *' " ", 'Cardinality feedback = yes' xbi_notes FROM sq WHERE extractvalue(xmltype(sq.other_xml), '/*/info[@type = "cardinality_feedback"]') = 'yes'
UNION ALL SELECT ' *', 'SQL Stored Outline used = ' ||extractvalue(xmltype(sq.other_xml), '/*/info[@type = "outline"]') FROM sq WHERE extractvalue(xmltype(sq.other_xml), '/*/info[@type = "outline"]') IS NOT NULL
UNION ALL SELECT ' *', 'SQL Patch used = ' ||extractvalue(xmltype(sq.other_xml), '/*/info[@type = "sql_patch"]') FROM sq WHERE extractvalue(xmltype(sq.other_xml), '/*/info[@type = "sql_patch"]') IS NOT NULL
UNION ALL SELECT ' *', 'SQL Profile used = ' ||extractvalue(xmltype(sq.other_xml), '/*/info[@type = "sql_profile"]') FROM sq WHERE extractvalue(xmltype(sq.other_xml), '/*/info[@type = "sql_profile"]') IS NOT NULL
UNION ALL SELECT ' *', 'SQL Plan Baseline used = ' ||extractvalue(xmltype(sq.other_xml), '/*/info[@type = "baseline"]') FROM sq WHERE extractvalue(xmltype(sq.other_xml), '/*/info[@type = "baseline"]') IS NOT NULL
UNION ALL SELECT ' *', 'Adaptive Plan = ' ||extractvalue(xmltype(sq.other_xml), '/*/info[@type = "adaptive_plan"]') FROM sq WHERE extractvalue(xmltype(sq.other_xml), '/*/info[@type = "adaptive_plan"]') IS NOT NULL
/
-- === Outline Hints ===
WITH sq AS (
SELECT other_xml
FROM v$sql_plan p
WHERE
p.sql_id = '&xbi_sql_id'
AND p.child_number = &xbi_sql_child_number
AND p.address = hextoraw('&xbi_sql_addr')
AND p.other_xml IS NOT NULL
)
SELECT
SUBSTR(EXTRACTVALUE(VALUE(d), '/hint'),1,4000) xbi_outline_hints
FROM
sq
, TABLE(XMLSEQUENCE(EXTRACT(XMLTYPE(sq.other_xml), '/*/outline_data/hint'))) D
/
set feedback on
PROMPT
-1
View File
@@ -2,4 +2,3 @@ prompt Display execution plan for last statement for this session from library c
select * from table(dbms_xplan.display_cursor(null,null,'ALLSTATS LAST +ALIAS +PEEKED_BINDS +PARALLEL +PARTITION +COST +BYTES +HINT_REPORT'));
+48 -48
View File
@@ -1,48 +1,48 @@
/*
*
* Author : Vishal Gupta
* Purpose : Display Execution plan from cursor cache
* Parameters : 1 - SQL_ID
*
*
* Revision History:
* ===================
* Date Author Description
* --------- ------------ -----------------------------------------
* 18-Mar-12 Vishal Gupta Intial version
*
*
*/
DEFINE sql_id="&&1"
DEFINE child_number="&&2"
COLUMN _sql_id NEW_VALUE sql_id NOPRINT
COLUMN _child_number NEW_VALUE child_number NOPRINT
SELECT DECODE('&&sql_id','','%','&&sql_id') "_sql_id"
, DECODE('&&child_number','','NULL','&&child_number') "_child_number"
FROM DUAL
;
SET long 4000
SET longchunksize 4000
SET pagesize 0
SELECT *
FROM table(DBMS_XPLAN.display_cursor( sql_id => '&&sql_id'
, cursor_child_no => &&child_number
, format => 'ADVANCED ALLSTATS LAST'
)
)
;
UNDEFINE sql_id
UNDEFINE child_number
/*
*
* Author : Vishal Gupta
* Purpose : Display Execution plan from cursor cache
* Parameters : 1 - SQL_ID
*
*
* Revision History:
* ===================
* Date Author Description
* --------- ------------ -----------------------------------------
* 18-Mar-12 Vishal Gupta Intial version
*
*
*/
DEFINE sql_id="&&1"
DEFINE child_number="&&2"
COLUMN _sql_id NEW_VALUE sql_id NOPRINT
COLUMN _child_number NEW_VALUE child_number NOPRINT
SELECT DECODE('&&sql_id','','%','&&sql_id') "_sql_id"
, DECODE('&&child_number','','NULL','&&child_number') "_child_number"
FROM DUAL
;
-- SET long 4000
-- SET longchunksize 4000
-- SET pagesize 0
SELECT *
FROM table(DBMS_XPLAN.display_cursor( sql_id => '&&sql_id'
, cursor_child_no => &&child_number
, format => 'ADVANCED ALLSTATS LAST'
)
)
;
UNDEFINE sql_id
UNDEFINE child_number