Protected: Shell : Automate killing Blocking Sessions
There is no excerpt because this is a protected post.
There is no excerpt because this is a protected post.
Oracle :Batch updates using PLSQL Blocks. In this article , we will learn how to update million records in a table using plsql blocks. Aim : To avoid Undo errors –> For every 200 transactions we are keeping commit to avoid snapshot too old error.… Read More
There is no excerpt because this is a protected post.
Oracle:HEALTH CHECK REPORT(Capturing Archive information). In this article we will implement to capture the Archive information using Shell script. Lets create a table which can store Archive information. Connect to SYS user and execute below statement.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
CREATE TABLE DBMON.ARCHIVE_USAGE_HISTORY ( GENERATION_DATE DATE NOT NULL, INST_ID NUMBER NOT NULL, TOTAL_DAY_GB NUMBER ) TABLESPACE DATA01 RESULT_CACHE (MODE DEFAULT) PCTUSED 0 PCTFREE 10 INITRANS 1 MAXTRANS 255 STORAGE ( INITIAL 64K NEXT 1M MAXSIZE UNLIMITED MINEXTENTS 1 MAXEXTENTS UNLIMITED PCTINCREASE 0 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT ) LOGGING NOCOMPRESS NOCACHE NOPARALLEL MONITORING; |
Create unique index and primary key on ARCHIVE_USAGE_HISTORY… Read More
Dear Readers, In this article, we will see the following Multiple Indexes On the Same Set Of Column in Oracle 12c. You can create multiple indexes on the same set of columns but only one of the indexes can be visible at a time and… Read More
Oracle :How to find Historical TOP SQL’s. In this article we will see how to find out historical TOP SQL’s. The SQL Query to find Historical Top SQL’s.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
set lines 235 set numwidth 20 set pages 3000 col execs for 999,999,999 col avg_etime for 999,999.999 col avg_lio for 999,999,999.9 col begin_interval_time for a30 col node for 99999 set feedback off break on plan_hash_value on startup_time skip 1 break on plan_hash_value on TIME break on TIME col time for a30 select * from ( select ss.instance_number node,sql_id, to_Char(begin_interval_time,'MM-DD-YY HH24:MI') Time, sum(nvl(executions_delta,0)) execs, round(sum((elapsed_time_delta/decode(nvl(executions_delta,0),0,1,executions_delta))/1000000 ),2) avg_etime, round(sum((buffer_gets_delta/decode(nvl(buffer_gets_delta,0),0,1,executions_delta))),2) AVG_LIO, round(sum((DISK_READS_DELTA/decode(nvl(DISK_READS_DELTA,0),0,1,executions_delta))),2) AVG_PHR , round(sum((ROWS_PROCESSED_DELTA/decode(nvl(ROWS_PROCESSED_DELTA,0),0,1,executions_delta))),2) AVG_ROWS , round(sum((CPU_TIME_DELTA/decode(nvl(CPU_TIME_DELTA,0),0,1,executions_delta))/1000000),2) AVG_CPU, round(sum(CPU_TIME_DELTA)/1000000,2) TOTAL_CPU_TIME, RANK() OVER (PARTITION BY to_Char(begin_interval_time,'MM-DD-YY HH24:MI') ORDER BY sum(CPU_TIME_DELTA)*1000000 desc ) RANK from DBA_HIST_SQLSTAT S, DBA_HIST_SNAPSHOT SS where ss.snap_id = S.snap_id and ss.snap_id > (select max(snap_id)-1000 from DBA_HIST_SNAPSHOT ) and ss.instance_number = S.instance_number and executions_delta > 0 and begin_interval_time between to_date('27-JAN-2019 04:20','DD-MON-YYYY HH24:MI') and to_date('31-JAN-2019 06:30','DD-MON-YYYY HH24:MI') group by ss.instance_number,sql_id, to_Char(begin_interval_time,'MM-DD-YY HH24:MI') order by to_Char(begin_interval_time, 'MM-DD-YY HH24:MI'),sum(CPU_TIME_DELTA)*1000000,sum((CPU_TIME_DELTA/decode(nvl(CPU_TIME_DELTA,0),0,1,executions_delta))/1000000) ) where RANK<=10; |
Output : In screenshot Output in Text Format :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
NODE SQL_ID TIME EXECS AVG_ETIME AVG_LIO AVG_PHR AVG_ROWS AVG_CPU TOTAL_CPU_TIME RANK ------ ------------- ------------------------------ ------------ ------------ -------------- -------------------- -------------------- -------------------- -------------------- -------------------- 1 7kmbrw7q8hn4g 01-27-19 14:00 60 .010 78.0 0 1 .01 .32 10 1 3wrrjm9qtr2my 1 .390 482.0 0 2 .37 .37 9 1 4y1y43113gv8f 601 .000 50.6 0 15.18 0 .54 8 1 7hu2k3a31b6j7 614 .000 79.2 0 15.45 0 .57 7 1 6wrwqq7jkmv3w 1 .730 506.0 0 6 .72 .72 6 1 3xjw1ncw5vh27 21 .040 24,029.0 0 0 .04 .85 5 1 74cpnuu24wmx7 3 .470 18,446.3 0 2 .42 1.27 4 1 6mcpb06rctk0x 1 3.180 594,799.0 9 0 3.03 3.03 3 1 381t19fqhxdgp 1 5.180 28,698.0 2 75 5.07 5.07 2 1 b6usrg82hwsa3 1 11.360 314,544.0 22 0 11.21 11.21 1 1 39k4gf5t0831y 01-27-19 15:00 14 .000 10.4 0 0 0 .02 10 1 22356bkgsdcnh 12 .000 .0 0 1 0 .03 9 1 357cru8xpxh55 60 .000 3.0 0 0 0 .04 8 1 c9umxngkc3byq 60 .000 .0 0 0 0 .05 7 1 6ajkhukk78nsr 1 .060 1,156.0 0 1 .06 .06 6 1 d9vzav10pcpfh 60 .000 60.0 0 1 0 .06 5 1 fuws5bqghb2qh 60 .000 9.0 0 0 0 .07 4 1 772s25v1y0x8k 120 .000 .0 0 28 0 .1 3 1 79vddxwy7qz3b 3 .070 3,009.3 0 6.67 .07 .2 2 1 7kmbrw7q8hn4g 60 .010 78.0 0 1 .01 .32 1 1 2fh3rvu66aaqa 01-30-19 18:09 1 .210 369.0 11 1 .1 .1 10 1 7kmbrw7q8hn4g 11 .040 309.7 18.09 1 .01 .11 9 1 a6ygk0r9s5xuj 10 .010 71.5 1.2 0 .01 .12 8 1 02577v815yp77 1 .220 4,909.0 244 1 .13 .13 7 1 4phvdvx32a3mf 10 .020 162.4 3.3 1 .02 .18 6 1 bxywuzvtp6wjg 1 .400 4,753.0 166 0 .24 .24 5 1 3wrrjm9qtr2my 1 .840 1,232.0 56 2 .39 .39 4 1 644jqx2hk7qg0 1 .600 .0 0 1 .6 .6 3 1 12a2xbmwn5v6z 1 1.720 881,392.0 2643 3796 .71 .71 2 1 f6cz4n8y72xdc 1 2.510 914,468.0 2673 1 1.5 1.5 1 |
Comparing parameter files from two different databases. In this article we will learn how to compare two parameter files from two different databases. AIM : To make changes on orcl to look like prod we need to follow below procedure Source : Server name … Read More
There is no excerpt because this is a protected post.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 |
/********************************************************************** * File: sqlhistory.sql * Type: SQL*Plus script * Author: Tim Gorman (Evergreen Database Technologies, Inc.) * Date: 29sep08 * * Description: * SQL*Plus script to query the "history" of a specified SQL * statement, using its "SQL ID" across all database instances * in a database, using the AWR repository. This report is useful * for obtaining an hourly perspective on SQL statements seen in * more aggregated reports. * * Modifications: * TGorman 29sep08 adapted from the earlier STATSPACK-based * "sphistory.sql" script *********************************************************************/ set echo off set feedback off timing off verify off pagesize 100 linesize 130 recsep off set serveroutput on size 1000000 format wrapped trimout on trimspool on col phv heading "Plan|Hash Value" col snap_time format a12 truncate heading "Snapshot|Time" col execs format 999,990 heading "Execs" col lio_per_exec format 999,999,999,990.00 heading "Avg LIO|Per Exec" col pio_per_exec format 999,999,999,990.00 heading "Avg PIO|Per Exec" col cpu_per_exec format 999,999,999,990.00 heading "Avg|CPU (secs)|Per Exec" col ela_per_exec format 999,999,999,990.00 heading "Avg|Elapsed (secs)|Per Exec" col sql_text format a64 heading "Text of SQL statement" clear breaks computes ttitle off btitle off accept V_SQL_ID prompt "Enter the SQL_ID: " accept V_NBR_DAYS prompt "Enter number of days (backwards from this hour) to report (default: ALL): " variable v_nbr_days number spool sqlhistory_&&V_SQL_ID declare cursor get_phv(in_sql_id in varchar2, in_days in integer) is select ss.plan_hash_value, min(s.begin_interval_time) min_time, max(s.begin_interval_time) max_time, min(s.snap_id) min_snap, max(s.snap_id) max_snap, sum(ss.executions_delta) sum_execs, sum(ss.disk_reads_delta) sum_disk_reads, sum(ss.buffer_gets_delta) sum_buffer_gets, sum(ss.cpu_time_delta)/1000000 sum_cpu_time, sum(ss.elapsed_time_delta)/1000000 sum_elapsed_time from dba_hist_sqlstat ss, dba_hist_snapshot s where ss.dbid = s.dbid and ss.instance_number = s.instance_number and ss.snap_id = s.snap_id and ss.sql_id = in_sql_id and ss.executions_delta > 0 and s.begin_interval_time >= sysdate-in_days group by ss.plan_hash_value order by sum_elapsed_time desc; -- cursor get_xplan(in_sql_id in varchar2, in_phv in number) is select plan_table_output from table(dbms_xplan.display_awr(in_sql_id, in_phv, null, 'ALL -ALIAS')); -- v_prev_plan_hash_value number := -1; v_text_lines number := 0; v_errcontext varchar2(100); v_errmsg varchar2(100); v_display_sql_text boolean; -- begin -- v_errcontext := 'query NBR_DAYS from DUAL'; select decode('&&V_NBR_DAYS','',10,to_number(nvl('&&V_NBR_DAYS','10'))) into :v_nbr_days from dual; -- v_errcontext := 'open/fetch get_phv'; for phv in get_phv('&&V_SQL_ID', :v_nbr_days) loop -- if get_phv%rowcount = 1 then -- dbms_output.put_line('+'|| rpad('-',12,'-')|| rpad('-',10,'-')|| rpad('-',10,'-')|| rpad('-',12,'-')|| rpad('-',15,'-')|| rpad('-',15,'-')|| rpad('-',12,'-')|| rpad('-',12,'-')||'+'); dbms_output.put_line('|'|| rpad('Plan HV',12,' ')|| rpad('Min Snap',10,' ')|| rpad('Max Snap',10,' ')|| rpad('Execs',12,' ')|| rpad('LIO',15,' ')|| rpad('PIO',15,' ')|| rpad('CPU',12,' ')|| rpad('Elapsed',12,' ')||'|'); dbms_output.put_line('+'|| rpad('-',12,'-')|| rpad('-',10,'-')|| rpad('-',10,'-')|| rpad('-',12,'-')|| rpad('-',15,'-')|| rpad('-',15,'-')|| rpad('-',12,'-')|| rpad('-',12,'-')||'+'); -- end if; -- dbms_output.put_line('|'|| rpad(trim(to_char(phv.plan_hash_value)),12,' ')|| rpad(trim(to_char(phv.min_snap)),10,' ')|| rpad(trim(to_char(phv.max_snap)),10,' ')|| rpad(trim(to_char(phv.sum_execs,'999,999,990')),12,' ')|| rpad(trim(to_char(phv.sum_buffer_gets,'999,999,999,990')),15,' ')|| rpad(trim(to_char(phv.sum_disk_reads,'999,999,999,990')),15,' ')|| rpad(trim(to_char(phv.sum_cpu_time,'999,990.00')),12,' ')|| rpad(trim(to_char(phv.sum_elapsed_time,'999,990.00')),12,' ')||'|'); -- v_errcontext := 'fetch/close get_phv'; -- end loop; dbms_output.put_line('+'|| rpad('-',12,'-')|| rpad('-',10,'-')|| rpad('-',10,'-')|| rpad('-',12,'-')|| rpad('-',15,'-')|| rpad('-',15,'-')|| rpad('-',12,'-')|| rpad('-',12,'-')||'+'); -- v_errcontext := 'open/fetch get_phv'; for phv in get_phv('&&V_SQL_ID', :v_nbr_days) loop -- if v_prev_plan_hash_value <> phv.plan_hash_value then -- v_prev_plan_hash_value := phv.plan_hash_value; v_display_sql_text := FALSE; -- v_text_lines := 0; v_errcontext := 'open/fetch get_xplan'; for s in get_xplan('&&V_SQL_ID', phv.plan_hash_value) loop -- if v_text_lines = 0 then dbms_output.put_line('.'); dbms_output.put_line('========== PHV = ' || phv.plan_hash_value || '=========='); dbms_output.put_line('First seen from "'|| to_char(phv.min_time,'MM/DD/YY HH24:MI:SS') || '" (snap #'||phv.min_snap||')'); dbms_output.put_line('Last seen from "'|| to_char(phv.max_time,'MM/DD/YY HH24:MI:SS') || '" (snap #'||phv.max_snap||')'); dbms_output.put_line('.'); dbms_output.put_line( rpad('Execs',15,' ')|| rpad('LIO',15,' ')|| rpad('PIO',15,' ')|| rpad('CPU',15,' ')|| rpad('Elapsed',15,' ')); dbms_output.put_line( rpad('=====',15,' ')|| rpad('===',15,' ')|| rpad('===',15,' ')|| rpad('===',15,' ')|| rpad('=======',15,' ')); dbms_output.put_line( rpad(trim(to_char(phv.sum_execs,'999,999,999,990')),15,' ')|| rpad(trim(to_char(phv.sum_disk_reads,'999,999,999,990')),15,' ')|| rpad(trim(to_char(phv.sum_buffer_gets,'999,999,999,990')),15,' ')|| rpad(trim(to_char(phv.sum_cpu_time,'999,999,990.00')),15,' ')|| rpad(trim(to_char(phv.sum_elapsed_time,'999,999,990.00')),15,' ')); dbms_output.put_line('.'); end if; -- if v_display_sql_text = FALSE and s.plan_table_output like 'Plan hash value: %' then -- v_display_sql_text := TRUE; -- end if; -- if v_display_sql_text = TRUE then -- dbms_output.put_line(s.plan_table_output); -- end if; -- v_text_lines := v_text_lines + 1; -- end loop; -- end if; -- v_errcontext := 'fetch/close get_phv'; -- end loop; -- exception when others then v_errmsg := sqlerrm; raise_application_error(-20000, v_errcontext || ': ' || v_errmsg); end; / break on report compute sum of execs on report compute avg of lio_per_exec on report compute avg of pio_per_exec on report compute avg of cpu_per_exec on report compute avg of ela_per_exec on report ttitle center 'Summary Execution Statistics Over Time' select to_char(s.begin_interval_time, 'DD-MON HH24:MI') snap_time, ss.executions_delta execs, ss.buffer_gets_delta/decode(ss.executions_delta,0,1,ss.executions_delta) lio_per_exec, ss.disk_reads_delta/decode(ss.executions_delta,0,1,ss.executions_delta) pio_per_exec, (ss.cpu_time_delta/1000000)/decode(ss.executions_delta,0,1,ss.executions_delta) cpu_per_exec, (ss.elapsed_time_delta/1000000)/decode(ss.executions_delta,0,1,ss.executions_delta) ela_per_exec from dba_hist_snapshot s, dba_hist_sqlstat ss where ss.dbid = s.dbid and ss.instance_number = s.instance_number and ss.snap_id = s.snap_id and ss.sql_id = '&&V_SQL_ID' and ss.executions_delta > 0 and s.begin_interval_time >= sysdate - :v_nbr_days order by s.snap_id; clear breaks computes break on phv skip 1 on report compute sum of execs on phv compute avg of lio_per_exec on phv compute avg of pio_per_exec on phv compute avg of cpu_per_exec on phv compute avg of ela_per_exec on phv ttitle center 'Per-Plan Execution Statistics Over Time' select ss.plan_hash_value phv, to_char(s.begin_interval_time, 'DD-MON HH24:MI') snap_time, ss.executions_delta execs, ss.buffer_gets_delta/decode(ss.executions_delta,0,1,ss.executions_delta) lio_per_exec, ss.disk_reads_delta/decode(ss.executions_delta,0,1,ss.executions_delta) pio_per_exec, (ss.cpu_time_delta/1000000)/decode(ss.executions_delta,0,1,ss.executions_delta) cpu_per_exec, (ss.elapsed_time_delta/1000000)/decode(ss.executions_delta,0,1,ss.executions_delta) ela_per_exec from dba_hist_snapshot s, dba_hist_sqlstat ss where ss.dbid = s.dbid and ss.instance_number = s.instance_number and ss.snap_id = s.snap_id and ss.sql_id = '&&V_SQL_ID' and ss.executions_delta > 0 and s.begin_interval_time >= sysdate - :v_nbr_days order by ss.plan_hash_value, s.snap_id; clear breaks computes spool off set verify on echo on feedback on ttitle off |
DIFFERENCE BETWEEN ORACLE AND MySQL -07 Please refer my previous articles. Oracle vs MySQL DBA Checklist/Tasks(Article -06) Differences between Oracle and MySQL SNO ORACLE MySQL 1 In Oracle we have different ways of backup like Logical Backup and Physical backups In MySQL also we have… Read More