Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1083f08

Browse files
committed
v20171007
1 parent 29ac8e5 commit 1083f08

82 files changed

Lines changed: 3948 additions & 523 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

readme.txt

100644100755
Lines changed: 2 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,5 @@
11
Carlos Sierra's Shared Scripts
22
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3-
last update: 2017/01/02
3+
last update: 2017/10/07
44

5-
Feel free to use these scripts. They are mostly useful in the scope of SQL performance
6-
diagnostics. Keep original names please.
7-
8-
Script Name YY/MM/DD Purpose
9-
~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10-
act.sql 14/10/13 Active Sessions (lite)
11-
active_sessions.sql 14/10/31 Active Sessions (more columns)
12-
active_sql.sql 14/10/31 Simple list of Active SQL (just sql id and text)
13-
alter_plans.sql 13/12/28 Alter attributes of a SQL Plan Baseline
14-
awr_ash_pre_check.sql 16/12/18 Analyzes state of ASH on AWR and computes how long eDB360 would take to execute
15-
chained_rows.sql 16/04/18 Chained rows analysis for one table
16-
columns_multiple_types.sql 15/07/07 List Columns with multiple data types
17-
constraints_nonindexed.sql 15/07/05 List FK Constrains with no index to supportthem
18-
data_files_usage.sql 14/02/12 Reports Datafiles and Tablespaces usage
19-
dba_hist_ash_summaries.sql 13/12/19 ASH summaries by timed events then by plan operation
20-
display.sql 16/06/22 Display explain plan for most recent EXPLAIN PLAN FOR
21-
display_cursor.sql 16/06/22 Display execution plan for most recent cursor executed on current session
22-
estimate_index_size.sql 16/03/22 Reports Indexes with an Actual size > Estimated size for over 1 MB
23-
evolve.sql 13/12/18 Evolve SQL Plan Baselines
24-
execution_plan_v.sql 16/06/21 Creates a view displaying execution plan for most recent cursor
25-
explain_plan_v.sql 16/06/21 Creates a view displaying explain plan for most recent EXPLAIN PLAN FOR
26-
find_apex.sql 14/09/03 Finds APEX related expensive SQL for given application user and session
27-
gather_stats_wr_sys.sql 15/10/15 Gather fresh CBO statistics for AWR Tables and Indexes
28-
get_my_trace1.sql 16/06/24 Copy trace file on DB server from trace directory into local
29-
get_my_trace2.sql 16/06/24 Copy trace file from DB server into local directory using all_directories
30-
identification.sql 16/05/27 System identification with global info such as versions
31-
largest_200_objects.sql 14/01/23 Reports 200 largest objects as per segments bytes
32-
line_chart.sql 16/08/19 Sample script to generate a Google line chart
33-
list_plans.sql 13/12/28 Lists SQL Plan Baselines
34-
mon subdirectory 16/02/29 A set of scripts to monitor executions taking over X time
35-
mystat_reset.sql 13/10/04 Resets snaps credated by mystat.sql
36-
mystat.sql 14/01/11 Reports delta of current sessions stats before and after a SQL
37-
one_sql_time_series.sql 14/10/31 Performance History for one SQL
38-
planx.sql 17/01/02 Gets execution plan for given SQL_ID
39-
plan_prev.sql 16/08/29 Execution Plan for last SQL executed in current session
40-
prev.sql 16/06/21 Most recent SQL_ID and CHILD_NUMBER for current SID
41-
profiler.sql 15/12/28 Generates HTML report out of DBMS_PROFILER data
42-
recent.sql 15/07/09 List of SQL on execution or recently executed
43-
planx.sql 16/07/14 Reports Execution Plans for one SQL_ID from RAC and AWR(opt)
44-
sql_perf_change_by_date.sql 14/11/28 Lists SQL Statements with Elapsed Time per Execution changing over time (passing date)
45-
sql_performance_changed.sql 14/11/28 Lists SQL Statements with Elapsed Time per Execution changing over time
46-
sql_with_multiple_plans.sql 14/11/28 Lists SQL Statements with multiple Execution Plans performing significantly different
47-
sqlash.sql 13/12/18 ASH Reports for one SQL_ID
48-
spm subdirectory 16/02/29 Several scripts to manage SQL Plan Baselines
49-
sqlmon.sql 16/04/19 SQL Monitor Reports for one SQL_ID
50-
sqlpch.sql 15/01/28 Create Diagnostics SQL Patch for one SQL_ID
51-
spm directory 16/01/01 SQL Plan Management scripts
52-
tablex.sql 14/01/24 Reports CBO Statistics for a given Table
53-
tkprof.sql 13/10/15 Turns trace off and generates a TKPROF for trace under current session
54-
trace_off.sql 16/06/19 Turns sql trace off
55-
trace_on.sql 16/06/19 Turns sql trace on using event 10046 level 12 (include binds and waits)
56-
verify_stats_wr_sys.sql 16/11/23 Verify CBO statistics for AWR Tables and Indexes
5+
Feel free to use these scripts. They are mostly useful in the scope of SQL performance.

sql/act.sql

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ COL sql_id_and_child FOR A16;
2020
COL serv_mod_act_client_info FOR A50;
2121
COL sql_text FOR A80;
2222

23-
-- execute 10 consecutive times
2423
SELECT /* exclude_me */
2524
s.sid||','||s.serial# sid_serial,
2625
s.sql_id||','||s.sql_child_number sql_id_and_child,
@@ -40,15 +39,5 @@ SELECT /* exclude_me */
4039
ORDER BY
4140
1,2
4241
/
43-
/
44-
/
45-
/
46-
/
47-
48-
/
49-
/
50-
/
51-
/
52-
/
5342

5443
SPO OFF;

sql/active_sql.sql

100644100755
Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,27 @@
1-
CL COL;
2-
31
SET FEED ON VER OFF HEA ON LIN 32767 PAGES 100 TIMI OFF LONG 80 LONGC 80 TRIMS ON AUTOT OFF;
42
COL current_time NEW_V current_time FOR A15 NOPRI;
53
SELECT 'current_time: ' x, TO_CHAR(SYSDATE, 'YYYYMMDD_HH24MISS') current_time FROM DUAL;
64
SPO active_sql_&&current_time..txt
75

8-
WITH /* active_sql */
9-
unique_sql AS (
10-
SELECT DISTINCT sq.sql_id,
11-
REPLACE(SUBSTR(sq.sql_text, 1, 60), CHR(10)) sql_text
6+
COL sql_text_100 FOR A100;
7+
8+
SELECT sq.sql_id,
9+
SUM(sq.executions) executions,
10+
ROUND(SUM(sq.elapsed_time)/1e6) elapsed_time_secs,
11+
ROUND(SUM(sq.elapsed_time)/1e3/SUM(sq.executions),3) ms_per_exec,
12+
SUBSTR(sq.sql_text, 1, 100) sql_text_100
1213
FROM gv$session se,
1314
gv$sql sq
1415
WHERE se.status = 'ACTIVE'
1516
AND sq.inst_id = se.inst_id
1617
AND sq.sql_id = se.sql_id
1718
AND sq.child_number = se.sql_child_number
18-
AND sq.sql_text NOT LIKE 'WITH /* active_sql */%'
19-
)
20-
SELECT sql_id, sql_text
21-
FROM unique_sql
22-
ORDER BY
23-
sql_id;
19+
AND sq.executions > 0
20+
GROUP BY
21+
sq.sql_id,
22+
SUBSTR(sq.sql_text, 1, 100)
23+
HAVING
24+
ROUND(SUM(sq.elapsed_time)/1e6) > 60 OR SUM(sq.executions) > 1000
25+
/
2426

2527
SPO OFF;
26-
SET FEED ON VER ON LIN 80 PAGES 14 LONG 80 LONGC 80 TRIMS OFF;

sql/active_user_sessions.sql

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
SELECT sid, serial#, module, action, sql_id, last_call_et last_call_secs
2+
FROM v$session
3+
WHERE status = 'ACTIVE'
4+
AND type = 'USER'
5+
ORDER BY
6+
sid, serial#
7+
/
8+

sql/alter_plans.sql

100644100755
File mode changed.

sql/ash_awr_date.sql

Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
ACC date PROMPT 'YYYY-MM-DD: '
2+
ACC sql_id PROMPT 'SQL_ID (opt): ';
3+
4+
SET TERM OFF HEA OFF LIN 32767 NEWP NONE PAGES 0 FEED OFF ECHO OFF VER OFF LONG 32000 LONGC 2000 WRA ON TRIMS ON TRIM ON TI OFF TIMI OFF ARRAY 100 NUM 20 SQLBL ON BLO . RECSEP OFF;
5+
COL query_date NEW_V query_date;
6+
SELECT NVL('&&date.', TO_CHAR(SYSDATE, 'YYYY-MM-DD')) query_date FROM DUAL;
7+
COL current_time NEW_V current_time FOR A15;
8+
SELECT 'current_time: ' x, TO_CHAR(SYSDATE, 'YYYYMMDD_HH24MISS') current_time FROM DUAL;
9+
PRO
10+
DEF report_title = "Active Sessions";
11+
DEF report_abstract_1 = "<br>Active Sessions on CPU or Timed Wait Class.";
12+
DEF report_abstract_2 = "<br>SQL_ID: &&sql_id.";
13+
DEF report_abstract_3 = "";
14+
DEF report_abstract_4 = "";
15+
DEF chart_title = "Active Sessions";
16+
DEF xaxis_title = "Active Sessions around &&query_date.";
17+
DEF vaxis_title = "Active Sessions";
18+
COL cpu_count NEW_V cpu_count;
19+
SELECT TO_CHAR(ROUND(TO_NUMBER(value) * 0.7)) cpu_count FROM v$parameter WHERE name = 'cpu_count';
20+
DEF vaxis_baseline = ", baseline:&&cpu_count.";
21+
DEF vaxis_baseline = "";;
22+
DEF chart_foot_note_1 = "<br>1) Drag to Zoom, and right click to reset Chart.";
23+
DEF chart_foot_note_2 = "<br>2) ";
24+
DEF chart_foot_note_3 = "";
25+
DEF chart_foot_note_4 = "";
26+
DEF report_foot_note = "Active Sessions for &&query_date.";
27+
PRO
28+
SPO ash_awr_date_&&current_time..html;
29+
PRO <html>
30+
PRO <!-- $Header: line_chart.sql 2014-07-27 carlos.sierra $ -->
31+
PRO <head>
32+
PRO <title>line_chart.html</title>
33+
PRO
34+
PRO <style type="text/css">
35+
PRO body {font:10pt Arial,Helvetica,Geneva,sans-serif; color:black; background:white;}
36+
PRO h1 {font-size:16pt; font-weight:bold; color:#336699; border-bottom:1px solid #336699; margin-top:0pt; margin-bottom:0pt; padding:0px 0px 0px 0px;}
37+
PRO h2 {font-size:14pt; font-weight:bold; color:#336699; margin-top:4pt; margin-bottom:0pt;}
38+
PRO h3 {font-size:12pt; font-weight:bold; color:#336699; margin-top:4pt; margin-bottom:0pt;}
39+
PRO pre {font:8pt monospace,Monaco,"Courier New",Courier;}
40+
PRO a {color:#663300;}
41+
PRO table {font-size:8pt; border-collapse:collapse; empty-cells:show; white-space:nowrap; border:1px solid #336699;}
42+
PRO li {font-size:8pt; color:black; padding-left:4px; padding-right:4px; padding-bottom:2px;}
43+
PRO th {font-weight:bold; color:white; background:#0066CC; padding-left:4px; padding-right:4px; padding-bottom:2px;}
44+
PRO tr {color:black; background:white;}
45+
PRO tr:hover {color:white; background:#0066CC;}
46+
PRO tr.main {color:black; background:white;}
47+
PRO tr.main:hover {color:black; background:white;}
48+
PRO td {vertical-align:top; border:1px solid #336699;}
49+
PRO td.c {text-align:center;}
50+
PRO font.n {font-size:8pt; font-style:italic; color:#336699;}
51+
PRO font.f {font-size:8pt; color:#999999; border-top:1px solid #336699; margin-top:30pt;}
52+
PRO div.google-chart {width:809px; height:500px;}
53+
PRO </style>
54+
PRO
55+
PRO <script type="text/javascript" src="https://www.google.com/jsapi"></script>
56+
PRO <script type="text/javascript">
57+
PRO google.load("visualization", "1", {packages:["corechart"]})
58+
PRO google.setOnLoadCallback(drawChart)
59+
PRO
60+
PRO function drawChart() {
61+
PRO var data = google.visualization.arrayToDataTable([
62+
PRO [
63+
PRO 'Date Column' ,
64+
PRO 'ON CPU' ,
65+
PRO 'User I/O' ,
66+
PRO 'System I/O' ,
67+
PRO 'Cluster' ,
68+
PRO 'Commit' ,
69+
PRO 'Concurrency' ,
70+
PRO 'Application' ,
71+
PRO 'Administrative' ,
72+
PRO 'Configuration' ,
73+
PRO 'Network' ,
74+
PRO 'Queueing' ,
75+
PRO 'Scheduler' ,
76+
PRO 'Other' ,
77+
PRO ]
78+
/****************************************************************************************/
79+
WITH
80+
my_query AS (
81+
/* query below selects one date_column and a small set of number_columns */
82+
SELECT sample_id,
83+
sample_time,
84+
SUM(CASE session_state WHEN 'ON CPU' THEN 1 ELSE 0 END) as_on_cpu,
85+
SUM(CASE wait_class WHEN 'User I/O' THEN 1 ELSE 0 END) as_user_io,
86+
SUM(CASE wait_class WHEN 'System I/O' THEN 1 ELSE 0 END) as_system_io,
87+
SUM(CASE wait_class WHEN 'Cluster' THEN 1 ELSE 0 END) as_cluster,
88+
SUM(CASE wait_class WHEN 'Commit' THEN 1 ELSE 0 END) as_commit,
89+
SUM(CASE wait_class WHEN 'Concurrency' THEN 1 ELSE 0 END) as_concurrency,
90+
SUM(CASE wait_class WHEN 'Application' THEN 1 ELSE 0 END) as_application,
91+
SUM(CASE wait_class WHEN 'Administrative' THEN 1 ELSE 0 END) as_administrative,
92+
SUM(CASE wait_class WHEN 'Configuration' THEN 1 ELSE 0 END) as_configuration,
93+
SUM(CASE wait_class WHEN 'Network' THEN 1 ELSE 0 END) as_network,
94+
SUM(CASE wait_class WHEN 'Queueing' THEN 1 ELSE 0 END) as_queueing,
95+
SUM(CASE wait_class WHEN 'Scheduler' THEN 1 ELSE 0 END) as_scheduler,
96+
SUM(CASE wait_class WHEN 'Other' THEN 1 ELSE 0 END) as_other
97+
FROM dba_hist_active_sess_history
98+
WHERE sample_time BETWEEN TO_DATE('&&query_date.', 'YYYY-MM-DD') - 3 AND TO_DATE('&&query_date.', 'YYYY-MM-DD') + 4 - (1/24/60/60)
99+
AND ('&&sql_id.' IS NULL OR sql_id = '&&sql_id.')
100+
GROUP BY
101+
sample_id,
102+
sample_time
103+
/* end of query */
104+
)
105+
/****************************************************************************************/
106+
/* no need to modify the date column below, but you may need to add some number columns */
107+
SELECT ', [new Date('||
108+
TO_CHAR(q.sample_time, 'YYYY')|| /* year */
109+
','||(TO_NUMBER(TO_CHAR(q.sample_time, 'MM')) - 1)|| /* month - 1 */
110+
','||TO_CHAR(q.sample_time, 'DD')|| /* day */
111+
','||TO_CHAR(q.sample_time, 'HH24')|| /* hour */
112+
','||TO_CHAR(q.sample_time, 'MI')|| /* minute */
113+
','||TO_CHAR(q.sample_time, 'SS')|| /* second */
114+
')'||
115+
','||q.as_on_cpu||
116+
','||q.as_user_io||
117+
','||q.as_system_io||
118+
','||q.as_cluster||
119+
','||q.as_commit||
120+
','||q.as_concurrency||
121+
','||q.as_application||
122+
','||q.as_administrative||
123+
','||q.as_configuration||
124+
','||q.as_network||
125+
','||q.as_queueing||
126+
','||q.as_scheduler||
127+
','||q.as_other||
128+
']'
129+
FROM my_query q
130+
ORDER BY
131+
q.sample_time
132+
/
133+
/****************************************************************************************/
134+
PRO ]);
135+
PRO
136+
PRO var options = {isStacked: true,
137+
PRO chartArea:{left:90, top:75, width:'65%', height:'70%'},
138+
PRO backgroundColor: {fill: 'white', stroke: '#336699', strokeWidth: 1},
139+
PRO explorer: {actions: ['dragToZoom', 'rightClickToReset'], maxZoomIn: 0.01},
140+
PRO title: '&&chart_title.',
141+
PRO titleTextStyle: {fontSize: 18, bold: false},
142+
PRO focusTarget: 'category',
143+
PRO legend: {position: 'right', textStyle: {fontSize: 14}},
144+
PRO tooltip: {textStyle: {fontSize: 14}},
145+
PRO hAxis: {title: '&&xaxis_title.', gridlines: {count: -1}, titleTextStyle: {fontSize: 16, bold: false}},
146+
PRO series: { 0: { color :'#34CF27'}, 1: { color :'#0252D7'}, 2: { color :'#1E96DD'}, 3: { color :'#CEC3B5'}, 4: { color :'#EA6A05'}, 5: { color :'#871C12'}, 6: { color :'#C42A05'}, 7: {color :'#75763E'},
147+
PRO 8: { color :'#594611'}, 9: { color :'#989779'}, 10: { color :'#C6BAA5'}, 11: { color :'#9FFA9D'}, 12: { color :'#F571A0'}, 13: { color :'#000000'}, 14: { color :'#ff0000'}},
148+
PRO vAxis: {title: '&&vaxis_title.' &&vaxis_baseline., gridlines: {count: -1}, titleTextStyle: {fontSize: 16, bold: false}}
149+
PRO }
150+
PRO
151+
PRO var chart = new google.visualization.LineChart(document.getElementById('chart_div'))
152+
PRO chart.draw(data, options)
153+
PRO }
154+
PRO </script>
155+
PRO </head>
156+
PRO <body>
157+
PRO <h1>&&report_title.</h1>
158+
PRO &&report_abstract_1.
159+
PRO &&report_abstract_2.
160+
PRO &&report_abstract_3.
161+
PRO &&report_abstract_4.
162+
PRO <div id="chart_div" class="google-chart"></div>
163+
PRO <font class="n">Notes:</font>
164+
PRO <font class="n">&&chart_foot_note_1.</font>
165+
PRO <font class="n">&&chart_foot_note_2.</font>
166+
PRO <font class="n">&&chart_foot_note_3.</font>
167+
PRO <font class="n">&&chart_foot_note_4.</font>
168+
PRO <pre>
169+
L
170+
PRO </pre>
171+
PRO <br>
172+
PRO <font class="f">&&report_foot_note.</font>
173+
PRO </body>
174+
PRO </html>
175+
SPO OFF;
176+
SET TERM ON HEA ON LIN 80 NEWP 1 PAGES 14 FEED ON ECHO OFF VER ON LONG 80 LONGC 80 WRA ON TRIMS OFF TRIM OFF TI OFF TIMI OFF ARRAY 15 NUM 10 NUMF "" SQLBL OFF BLO ON RECSEP WR;

0 commit comments

Comments
 (0)