Tuesday, December 25, 2018

How can we process iostat information and print timestamp sample, avg run queue, await, %util and a max function

objecvtive: Let us see how can we process iostat information and print in summary, the below
    a) timestamp of the sample
    b) Avg run queue for the sample from all the devices
    c) Avg of await for the sample from all the devices
    d) Avg of the %util for the sample from all the devices
    e) print the max util% and print its corresponding device name,await,runqueue

Step 1) Decide the iostat format

1 Sample of iostat look like below...

12/15/2018 04:28:15 PM
avg-cpu:  %user   %nice %system %iowait  %steal   %idle
           0.00    0.00   66.99   32.52    0.00    0.49

Device:         rrqm/s   wrqm/s     r/s     w/s    rkB/s    wkB/s avgrq-sz avgqu-sz   await  svctm  %util
sdb            4117.00     0.00 3338.00    0.00 29892.00     0.00    17.91     1.35    0.41   0.24  78.80
sda            4065.00     0.00 3812.00    0.00 31612.00     0.00    16.59     1.54    0.40   0.24  89.90
sdc               0.00     0.00    0.00    0.00     0.00     0.00     0.00     0.00    0.00   0.00   0.00
scd0              0.00     0.00    0.00    0.00     0.00     0.00     0.00     0.00    0.00   0.00   0.00

Step 2) process each sample seperately

#!/bin/ksh
if [ $# -ne 1 ]
then
echo "please give valid input file to process as command line arg"
exit 1
fi
grep "12/15/2018" $1 > tmp_stp1.out
while read line
do
i=`echo $line|cut -d ' ' -f 2-3`
if [ -z $j ]
then
j=$i
prl=$line
else
## in this step we break the file into working piece with only necessary content using sed & awk
##first break the file into 1 sample @ a time
##delete the timestamps used for sample break
##delete trailing line
sed -n "/$j/,/$i/p" $1|sed '/$^/d' > tmp_stp2.out
j=$i
k=`grep -n Device tmp_stp2.out|cut -d ':' -f 1`
l=`grep -n "$i" tmp_stp2.out|cut -d ':' -f 1`
## further trimdown here, keep only necessary device information
awk -v m=$k -v n=$l 'NR>m && NR<n{print}' tmp_stp2.out > tmp_stp3.out
## process here
awk '{OFS=","}$10<=.1{cnt+=1;a+=$10;b+=$9;c+=$11}END{printf "rangeupto100ms: %d,%.2f,%.2f,%.2f\n",cnt,(a*1000)/((cnt>0)?cnt:1),(b*1000)/((cnt>0)?cnt:1),(c*1000)/((cnt>0)?cnt:1)}' tmp_stp3.out > tmp_stp4.out
awk '{OFS=","}$10<=1 && $10>.1{cnt+=1;a+=$10;b+=$9;c+=$11}END{printf "range100to1000ms: %d,%.2f,%.2f,%.2f\n",cnt,(a*1000)/((cnt>0)?cnt:1),(b*1000)/((cnt>0)?cnt:1),(c*1000)/((cnt>0)?cnt:1)}' tmp_stp3.out >> tmp_stp4.out
awk '{OFS=","}$10<=10 && $10>1{cnt+=1;a+=$10;b+=$9;c+=$11}END{printf "range1to10s: %d,%.2f,%.2f,%.2f\n",cnt,(a*1000)/((cnt>0)?cnt:1),(b*1000)/((cnt>0)?cnt:1),(c*1000)/((cnt>0)?cnt:1)}' tmp_stp3.out >> tmp_stp4.out
awk '{OFS=","}$10>10{cnt+=1;a+=$10;b+=$9;c+=$11}END{printf "rangeabove10s: %d,%.2f,%.2f,%.2f\n",cnt,(a*1000)/((cnt>0)?cnt:1),(b*1000)/((cnt>0)?cnt:1),(c*1000)/((cnt>0)?cnt:1)}' tmp_stp3.out >> tmp_stp4.out
while read line2
do
echo $prl,$line2
done < tmp_stp4.out
prl=$line
fi
done < tmp_stp1.out

sed -n "/$j/,/$i/p" iostat_rpt3.out|sed "$i/d;$j/d"|sed -e :a -e '/./,$!d;/^\n*$/{$d;N;};/\n$/ba' > tmp_stp2.out

Step 3) Also there is a scope for examining the max util% and print its corresponding device name,await,runqueue

let us do this only for 100 to 1000ms range of ios which is predominant...


#!/bin/ksh
if [ $# -ne 1 ]
then
echo "please give valid input file to process as command line arg"
exit 1
fi
grep "12/15/2018" $1 > tmp_stp1.out
while read line
do
i=`echo $line|cut -d ' ' -f 2-3`
if [ -z $j ]
then
j=$i
prl=$line
else
## in this step we break the file into working piece with only necessary content using sed & awk
##first break the file into 1 sample @ a time
##delete the timestamps used for sample break
##delete trailing line
sed -n "/$j/,/$i/p" $1|sed '/$^/d' > tmp_stp2.out
j=$i
k=`grep -n Device tmp_stp2.out|cut -d ':' -f 1`
l=`grep -n "$i" tmp_stp2.out|cut -d ':' -f 1`
## further trimdown here, keep only necessary device information
awk -v m=$k -v n=$l 'NR>m && NR<n{print}' tmp_stp2.out > tmp_stp3.out
## process here
awk     -v max=0 '{OFS=","}
    $10<=1 && $10>.1
    {cnt+=1;a+=$10;b+=$9;c+=$12}
    {if(max<$12){max=$12; udvn=$1; uawt=$10; uqu=$9}}
    END {printf "range100to1000ms: %d,%.2f,%.2f,%.2f,%.2f,%s,%.2f,%.2f\n",cnt,(a*1000)/((cnt>0)?cnt:1),b/((cnt>0)?cnt:1),c/((cnt>0)?cnt:1),max,udvn,uawt,uqu}' tmp_stp3.out > tmp_stp4.out
while read line2
do
echo $prl,$line2
done < tmp_stp4.out
prl=$line
fi
done < tmp_stp1.out

One anamoly, if there is only 1 device found with matching record for the data selection, it prints the whole line as well, need to troubleshoot that further.

input:
12/15/2018 04:17:36 PM
avg-cpu:  %user   %nice %system %iowait  %steal   %idle
           0.16    0.00    1.14    0.72    0.00   97.98

Device:         rrqm/s   wrqm/s     r/s     w/s    rkB/s    wkB/s avgrq-sz avgqu-sz   await  svctm  %util
sdb               0.37     0.00   10.05    0.00   335.22     0.02    66.65     0.50   49.84   0.94   0.95
sda               0.26     0.00   10.08    0.00   335.11     0.00    66.50     0.50   49.50   0.98   0.99
sdc               1.02     0.16    1.12    0.53    26.50     2.73    35.42     0.01    6.05   2.92   0.48
scd0              0.00     0.00    0.01    0.00     0.04     0.00     8.00     0.00   94.11  94.11   0.10

12/15/2018 04:17:37 PM

Output:
12/15/2018 04:17:36 PM,range100to1000ms: 5,39900.00,0.20,0.50,0.99,sda,49.50,0.50

39900ms = 39.9secs avg wait time.

So the anamoly...

input:
12/15/2018 04:17:38 PM
avg-cpu:  %user   %nice %system %iowait  %steal   %idle
           0.00    0.00    0.51    0.51    0.00   98.98

Device:         rrqm/s   wrqm/s     r/s     w/s    rkB/s    wkB/s avgrq-sz avgqu-sz   await  svctm  %util
sdb               0.00     0.00    0.00    0.00     0.00     0.00     0.00     0.00    0.00   0.00   0.00
sda               0.00     0.00    1.00    0.00     1.00     0.00     2.00     0.00    1.00   1.00   0.10
sdc               0.00     0.00    0.00    0.00     0.00     0.00     0.00     0.00    0.00   0.00   0.00
scd0              0.00     0.00    0.00    0.00     0.00     0.00     0.00     0.00    0.00   0.00   0.00


output:
12/15/2018 04:17:38 PM,sda 0.00 0.00 1.00 0.00 1.00 0.00 2.00 0.00 1.00 1.00 0.10    <<<<<<<<< this is that extra line.
12/15/2018 04:17:38 PM,range100to1000ms: 5,200.00,0.00,0.02,0.10,sda,1.00,0.00    <<<<<<<<< this is wrong as well, its not 5 devices.its just 1 device.

Need to check this further.

Sunday, December 23, 2018

version 2 - Write a query to find out how many new connections or session were connected in db from dba_hist_active_sess_history

objective: Write a query to find out how many new connections or session were connected in db from dba_hist_active_sess_history.
There is already way to mine listener to find this detail + there is already blog written, now in this blog we will try simplify the query to reduce the run duration and fetch results.

step 1)
Get out the existing query...

select a.sample_time
,count(1)
from dba_hist_active_sess_history a
,(select samp_time,lag(samp_time,1) over (order by samp_time) lag_time
from
(
select distinct(sample_time) samp_time
from dba_hist_active_sess_history
order by 1)) c
where a.sample_time=c.samp_time
and (a.session_id,a.SESSION_SERIAL#) not in (select session_id,sESSION_SERIAL# from dba_hist_active_sess_history where sample_time=c.lag_time)
group by a.sample_time
order by 1;

step 2)
Observe the query above, we are fetching from the same table 3 times, so we better find a way to reduce it. let us try to materialize all the needed columns from the desired table, this way we reduce the result set and query less data.

set lines 300
set pages 3000
set colsep ,

variable d1 varchar2(20);
variable d2 varchar2(20);
prompt enter date in format "DD/MM/YYYY HH24:MI:SS" d1:
exec :d1:=&d1
prompt enter date in format "DD/MM/YYYY HH24:MI:SS" d2:
exec :d2:=&d2


with dhash as
(select instance_number,sample_time,session_id,session_serial#
from dba_hist_active_sess_history
where sample_time between to_date(:d1,'DD/MM/YYYY HH24:MI:SS') and to_date(:d2,'DD/MM/YYYY HH24:MI:SS')
order by instance_number,sample_time,session_id,session_serial#)
select a.instance_number,a.sample_time,count(1)
from dhash a
,(select instance_number,samp_time,lag(samp_time,1) over (order by samp_time) lag_time
from
(
select instance_number,sample_time samp_time
from dhash
group by instance_number,sample_time
order by 1,2)) c
where a.sample_time=c.samp_time
and a.instance_number=c.instance_number
and (a.instance_number,a.session_id,a.SESSION_SERIAL#) not in (select instance_number,session_id,sESSION_SERIAL# from dhash where sample_time=c.lag_time and instance_number=c.instance_number)
group by a.instance_number,a.sample_time
order by 1,2;

step 3) test..

Result:

SQL> @check_sess.sql
enter date in format "DD/MM/YYYY HH24:MI:SS" d1:
Enter value for d1: '23/12/2018 12:50:00'

PL/SQL procedure successfully completed.

enter date in format "DD/MM/YYYY HH24:MI:SS" d2:
Enter value for d2: '23/12/2018 13:15:00'

PL/SQL procedure successfully completed.


INSTANCE_NUMBER,SAMPLE_TIME                                                                ,  COUNT(1)
---------------,---------------------------------------------------------------------------,----------
              1,23-DEC-18 12.56.33.462 PM                                                  ,         1
              1,23-DEC-18 01.07.24.256 PM                                                  ,         1



To test its effectiveness, let us query v$active_session_history..

with dhash as
(select inst_id instance_number,sample_time,session_id,session_serial#
from gv$active_session_history
where sample_time between to_date(:d1,'DD/MM/YYYY HH24:MI:SS') and to_date(:d2,'DD/MM/YYYY HH24:MI:SS')
order by instance_number,sample_time,session_id,session_serial#)
select a.instance_number,a.sample_time,count(1)
from dhash a
,(select instance_number,samp_time,lag(samp_time,1) over (order by samp_time) lag_time
from
(
select instance_number,sample_time samp_time
from dhash
group by instance_number,sample_time
order by 1,2)) c
where a.sample_time=c.samp_time
and a.instance_number=c.instance_number
and (a.instance_number,a.session_id,a.SESSION_SERIAL#) not in (select instance_number,session_id,sESSION_SERIAL# from dhash where sample_time=c.lag_time and instance_number=c.instance_number)
group by a.instance_number,a.sample_time
order by 1,2;

SQL> @check_sess_eff.sql
enter date in format "DD/MM/YYYY HH24:MI:SS" d1:
Enter value for d1: '23/12/2018 12:50:00'

PL/SQL procedure successfully completed.

enter date in format "DD/MM/YYYY HH24:MI:SS" d2:
Enter value for d2: '23/12/2018 13:39:00'

PL/SQL procedure successfully completed.


INSTANCE_NUMBER,SAMPLE_TIME                                                                ,  COUNT(1)
---------------,---------------------------------------------------------------------------,----------
              1,23-DEC-18 12.51.44.123 PM                                                  ,         1
              1,23-DEC-18 12.56.17.452 PM                                                  ,         1
              1,23-DEC-18 12.56.29.462 PM                                                  ,         1
              1,23-DEC-18 01.00.45.758 PM                                                  ,         2
              1,23-DEC-18 01.01.45.838 PM                                                  ,         1
              1,23-DEC-18 01.02.29.888 PM                                                  ,         1
              1,23-DEC-18 01.07.24.256 PM                                                  ,         1
              1,23-DEC-18 01.11.47.603 PM                                                  ,         2
              1,23-DEC-18 01.16.04.913 PM                                                  ,         1
              1,23-DEC-18 01.17.30.013 PM                                                  ,         1
              1,23-DEC-18 01.22.49.395 PM                                                  ,         1
              1,23-DEC-18 01.23.10.415 PM                                                  ,         1
              1,23-DEC-18 01.26.56.704 PM                                                  ,         1
              1,23-DEC-18 01.27.45.771 PM                                                  ,         2
              1,23-DEC-18 01.29.46.017 PM                                                  ,         1
              1,23-DEC-18 01.29.51.027 PM                                                  ,         2
              1,23-DEC-18 01.29.57.027 PM                                                  ,         1
              1,23-DEC-18 01.30.03.037 PM                                                  ,         1
              1,23-DEC-18 01.30.09.037 PM                                                  ,         1
              1,23-DEC-18 01.30.15.047 PM                                                  ,         1
              1,23-DEC-18 01.30.21.057 PM                                                  ,         1
              1,23-DEC-18 01.30.27.067 PM                                                  ,         1
              1,23-DEC-18 01.30.28.067 PM                                                  ,         1
              1,23-DEC-18 01.30.33.077 PM                                                  ,         1
              1,23-DEC-18 01.30.38.077 PM                                                  ,         1
              1,23-DEC-18 01.37.08.690 PM                                                  ,         1
              1,23-DEC-18 01.37.15.690 PM                                                  ,         1
              1,23-DEC-18 01.37.21.700 PM                                                  ,         1
              1,23-DEC-18 01.37.25.710 PM                                                  ,         3
              1,23-DEC-18 01.37.28.782 PM                                                  ,         2
              1,23-DEC-18 01.37.29.802 PM                                                  ,         1
              1,23-DEC-18 01.37.30.802 PM                                                  ,         1
              1,23-DEC-18 01.37.38.812 PM                                                  ,         1
              1,23-DEC-18 01.37.44.842 PM                                                  ,         1
              1,23-DEC-18 01.37.51.862 PM                                                  ,         1
              1,23-DEC-18 01.37.57.872 PM                                                  ,         1
              1,23-DEC-18 01.38.04.872 PM                                                  ,         1
              1,23-DEC-18 01.38.11.892 PM                                                  ,         1
              1,23-DEC-18 01.38.52.942 PM                                                  ,         1

39 rows selected.

step 4) validate...

select inst_id,sample_time,session_id,session_serial#
from gv$active_session_history
where sample_Time between sysdate-1/24 and sysdate-.5/24
order by inst_id,sample_time,session_id,session_serial#
/

   INST_ID,SAMPLE_TIME                                                                ,SESSION_ID,SESSION_SERIAL#
----------,---------------------------------------------------------------------------,----------,---------------
...
         1,23-DEC-18 01.37.20.700 PM                                                  ,       133,            135
         1,23-DEC-18 01.37.21.700 PM                                                  ,       133,            137    << new record 1
         1,23-DEC-18 01.37.22.710 PM                                                  ,       133,            137
         1,23-DEC-18 01.37.23.710 PM                                                  ,       133,            137
         1,23-DEC-18 01.37.24.710 PM                                                  ,       133,            137
         1,23-DEC-18 01.37.25.710 PM                                                  ,        15,            136    << new record 1
         1,23-DEC-18 01.37.25.710 PM                                                  ,       132,              1    << new record 2
         1,23-DEC-18 01.37.25.710 PM                                                  ,       133,            137    << repeat record
         1,23-DEC-18 01.37.25.710 PM                                                  ,       142,            277    << new record 3
         1,23-DEC-18 01.37.26.720 PM                                                  ,       133,            137
         1,23-DEC-18 01.37.26.720 PM                                                  ,       142,            277
         1,23-DEC-18 01.37.27.762 PM                                                  ,       133,            137
         1,23-DEC-18 01.37.27.762 PM                                                  ,       142,            277
         1,23-DEC-18 01.37.28.782 PM                                                  ,        19,             13
         1,23-DEC-18 01.37.28.782 PM                                                  ,       132,              1
         1,23-DEC-18 01.37.28.782 PM                                                  ,       133,            137
         1,23-DEC-18 01.37.28.782 PM                                                  ,       142,            277
         1,23-DEC-18 01.37.29.802 PM                                                  ,       139,             47
         1,23-DEC-18 01.37.29.802 PM                                                  ,       142,            277
         1,23-DEC-18 01.37.30.802 PM                                                  ,        19,             17

so it works fine.
There is one use case of this method of printing the session count is - the sessions which are established locally from the server are also traced where as listener doesnt know them.

If your intrested in knowing the cost difference between version 1 & 2 of this blog is...

version 1:

PLAN_TABLE_OUTPUT
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Plan hash value: 2908163802

------------------------------------------------------------------------------------------------------------------------------
| Id  | Operation                      | Name                        | Rows  | Bytes | Cost (%CPU)| Time     | Pstart| Pstop |
------------------------------------------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT               |                             |    61 |  5612 |   167   (2)| 00:00:03 |       |       |
|   1 |  SORT GROUP BY NOSORT          |                             |    61 |  5612 |   167   (2)| 00:00:03 |       |       |
|*  2 |   FILTER                       |                             |       |       |            |          |       |       |
|   3 |    NESTED LOOPS                |                             |    62 |  5704 |    13  (24)| 00:00:01 |       |       |

version 2:
PLAN_TABLE_OUTPUT
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Plan hash value: 386194343

--------------------------------------------------------------------------------------------------------------------------
| Id  | Operation                  | Name                        | Rows  | Bytes | Cost (%CPU)| Time     | Pstart| Pstop |
--------------------------------------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT           |                             |     2 |    98 |    16  (32)| 00:00:01 |       |       |
|   1 |  TEMP TABLE TRANSFORMATION |                             |       |       |            |          |       |       |
|   2 |   LOAD AS SELECT           | SYS_TEMP_0FD9D6610_42F9DE   |       |       |            |          |       |       |
|   3 |    SORT ORDER BY           |                             |     2 |   136 |     6  (17)| 00:00:01 |       |       |
|*  4 |     FILTER                 |                             |       |       |            |          |       |       |

There is a huge difference in cost, I am sure the run duration of version 2 will be far better than the first one.

Thank you & best wishes.

Thursday, December 20, 2018

version 1: query to find out how many new connections or session were connected in db from dba_hist_active_sess_history.

objective: Write a query to find out how many new connections or session were connected in db from dba_hist_active_sess_history.
There is already way to mine listener to find this detail, but let us try this for fun.


step 1) Write a query to get the sample time.

select distinct(sample_time)
from dba_hist_active_sess_history
order by 1;

Step 2) Write a wrapper on top of step 1 to fetch sample time and its lag

select samp_time,lag(samp_time,1) over (order by samp_time) lag_time
from
(
select distinct(sample_time) samp_time
from dba_hist_active_sess_history
order by 1);

Step 3) Write a wrapper on top of the step 2 to fetch sid,serial# from dba_hist_active_Sess_history for both lag and actual sample time and count the difference.

select a.sample_time
,count(1)
from dba_hist_active_sess_history a
,(select samp_time,lag(samp_time,1) over (order by samp_time) lag_time
from
(
select distinct(sample_time) samp_time
from dba_hist_active_sess_history
order by 1)) c
where a.sample_time=c.samp_time
and (a.session_id,a.SESSION_SERIAL#) not in (select session_id,sESSION_SERIAL# from dba_hist_active_sess_history where sample_time=c.lag_time)
group by a.sample_time
order by 1;

==> works well.

to test its effectiveness... replaced dba_hist with v$ to query the current info for every second sample.

select a.sample_time
,count(1)
from v$active_session_history a
,(select samp_time,lag(samp_time,1) over (order by samp_time) lag_time
from
(
select distinct(sample_time) samp_time
from v$active_session_history
order by 1)) c
where a.sample_time=c.samp_time
and (a.session_id,a.SESSION_SERIAL#) not in (select session_id,sESSION_SERIAL# from v$active_session_history where sample_time=c.lag_time)
group by a.sample_time
order by 1;


sample record from v$active_session_history...

21-DEC-18 11.31.39.436 AM                                                          136             188
21-DEC-18 11.31.40.436 AM                                                          136             188    << repeating all the time
21-DEC-18 11.31.41.436 AM                                                           12               3    << new 1
21-DEC-18 11.31.41.436 AM                                                           21               5    << new 2
21-DEC-18 11.31.41.436 AM                                                          128               1    << new 3
21-DEC-18 11.31.41.436 AM                                                          136             188    << repeating
21-DEC-18 11.31.42.446 AM                                                          136             188
21-DEC-18 11.31.43.446 AM                                                          136             188
21-DEC-18 11.31.44.446 AM                                                          136             188
21-DEC-18 11.31.45.446 AM                                                          136             188
21-DEC-18 11.31.46.446 AM                                                          136             188
21-DEC-18 11.31.47.446 AM                                                          136             188
21-DEC-18 11.31.48.446 AM                                                          136             188
21-DEC-18 11.31.49.446 AM                                                          136             188
21-DEC-18 11.31.50.446 AM                                                          136             188
21-DEC-18 11.31.51.446 AM                                                          136             188
21-DEC-18 11.31.52.446 AM                                                          136             188
21-DEC-18 11.31.53.456 AM                                                          136             188
21-DEC-18 11.31.54.456 AM                                                          136             188
21-DEC-18 11.31.55.456 AM                                                          136             188
21-DEC-18 11.31.56.456 AM                                                          136             188
21-DEC-18 11.31.57.456 AM                                                          136             188
21-DEC-18 11.31.58.456 AM                                                          136             188
21-DEC-18 11.31.59.456 AM                                                          136             188
21-DEC-18 11.32.00.456 AM                                                          136             188
21-DEC-18 11.32.01.466 AM                                                          136             188
21-DEC-18 11.32.02.476 AM                                                          136             188
21-DEC-18 11.32.03.476 AM                                                          136             188
21-DEC-18 11.32.04.486 AM                                                          136             188
21-DEC-18 11.32.05.486 AM                                                          136             188
21-DEC-18 11.32.06.486 AM                                                          136             188
21-DEC-18 11.32.07.486 AM                                                          136             188
21-DEC-18 11.32.08.486 AM                                                          136             188
21-DEC-18 11.32.09.486 AM                                                          136             188
21-DEC-18 11.32.10.486 AM                                                          136             188
21-DEC-18 11.32.11.496 AM                                                          136             188
21-DEC-18 11.32.41.556 AM                                                           12               3  << new 1
21-DEC-18 11.35.00.897 AM                                                           14              20    << new 1


so ideally we should have 21-DEC-18 11.31.41.436 AM (3) and 21-DEC-18 11.32.41.556 AM  & 21-DEC-18 11.35.00.897 AM (1) each. Other samples had repeating value, so should be skipped.

SAMPLE_TIME                                                                   COUNT(1)
--------------------------------------------------------------------------- ----------
21-DEC-18 10.47.14.345 AM                                                            2
21-DEC-18 10.47.17.365 AM                                                            2
..
21-DEC-18 11.30.27.236 AM                                                            1
21-DEC-18 11.30.31.256 AM                                                            1
21-DEC-18 11.30.39.266 AM                                                            1
21-DEC-18 11.30.41.276 AM                                                            1
21-DEC-18 11.30.42.276 AM                                                            1
21-DEC-18 11.31.21.396 AM                                                            1
21-DEC-18 11.31.41.436 AM                                                            3    << 3 as expected
21-DEC-18 11.32.41.556 AM                                                            1    << 1 as expected
21-DEC-18 11.35.00.897 AM                                                            1    << 1 as expected

So this works as expected.

Thanks for paying a visit.
All the best.


Tuesday, December 18, 2018

rman switch df with or without run prompt - which one is quicker & metrics associated

Lab: Which one is better and quicker - rman switch df in run or without run... when siwtching multiple datafiles.
oracle version: 11.2.0.1

Without Run version:
-----------------
RMAN> @rmn_swtch.cmd

RMAN> switch datafile 8 to copy;
datafile 8 switched to datafile copy "/oracle_data_2/cpydata_D-GGTEST1_I-1273850353_TS-TEST2_FNO-8_08tl5igt"

RMAN> switch datafile 9 to copy;
datafile 9 switched to datafile copy "/oracle_data_2/cpydata_D-GGTEST1_I-1273850353_TS-TEST3_FNO-9_09tl5ih1"

RMAN> switch datafile 10 to copy;
datafile 10 switched to datafile copy "/oracle_data_2/cpydata_D-GGTEST1_I-1273850353_TS-TEST4_FNO-10_0atl5ih2"


the rman job in run is swift compared to non run rman session.

No run - just switch in a command file:

********************************************************************************

OVERALL TOTALS FOR ALL NON-RECURSIVE STATEMENTS

call     count       cpu    elapsed       disk      query    current        rows
------- ------  -------- ---------- ---------- ---------- ----------  ----------
Parse      209      0.12       0.21          0          0          0           0
Execute    221      0.17       0.22          0          0          0         137
Fetch       75      0.11       0.13          0          0          0          75
------- ------  -------- ---------- ---------- ---------- ----------  ----------
total      505      0.41       0.57          0          0          0         212

Misses in library cache during parse: 14
Misses in library cache during execute: 4

Elapsed times include waiting on following events:
  Event waited on                             Times   Max. Wait  Total Waited
  ----------------------------------------   Waited  ----------  ------------
  SQL*Net message to client                     257        0.00          0.00
  SQL*Net message from client                   256       78.14        128.98
  control file sequential read                 1141        0.00          0.05
  asynch descriptor resize                       26        0.00          0.00
  SQL*Net break/reset to client                  12        0.00          0.00
  Disk file operations I/O                       33        0.00          0.00
  RMAN backup & recovery I/O                      6        0.00          0.00
  control file parallel write                    72        0.00          0.08
  control file single write                      39        0.00          0.03
  recovery area: computing dropped files          3        0.00          0.01
  recovery area: computing obsolete files         3        0.45          1.17
  recovery area: computing backed up files        3        0.06          0.10
  recovery area: computing applied logs           3        0.00          0.01


OVERALL TOTALS FOR ALL RECURSIVE STATEMENTS

call     count       cpu    elapsed       disk      query    current        rows
------- ------  -------- ---------- ---------- ---------- ----------  ----------
Parse      228      0.06       0.07          0          0          0           0
Execute    346      1.37       1.44          0          0          0         102
Fetch      403      0.20       0.20          0         26          0         309
------- ------  -------- ---------- ---------- ---------- ----------  ----------
total      977      1.64       1.71          0         26          0         411

Misses in library cache during parse: 32
Misses in library cache during execute: 11

Elapsed times include waiting on following events:
  Event waited on                             Times   Max. Wait  Total Waited
  ----------------------------------------   Waited  ----------  ------------
  SQL*Net message to client                       6        0.00          0.00
  SQL*Net message from client                     6        0.00          0.00
  control file sequential read                 1506        0.00          0.02
  asynch descriptor resize                       66        0.00          0.00
  Disk file operations I/O                       24        0.00          0.00
  db file sequential read                        30        0.00          0.00
  rdbms ipc reply                                14        0.00          0.00

  211  user  SQL statements in session.
  346  internal SQL statements in session.
  557  SQL statements in session.
********************************************************************************
Trace file: ggtest1_ora_2440.trc
Trace file compatibility: 11.1.0.7
Sort options: default

       1  session in tracefile.
     211  user  SQL statements in trace file.
     346  internal SQL statements in trace file.
     557  SQL statements in trace file.
      67  unique SQL statements in trace file.
   99729  lines in trace file.
     131  elapsed seconds in trace file.


******************************************************************************
In rman under run prompt...

command generator:
-------------------
select 'switch datafile '||''''||a.file_name||''''||' to datafilecopy '||''''||b.name||''''||';'
from dba_data_files a,v$datafile_copy b
where a.file_id=b.file#
and b.status='A'
and a.file_id in (8,9,10)
order by a.file_name;


--------------------

RMAN> run
2> {
3> switch datafile '/oracle_data_2/cpydata_D-GGTEST1_I-1273850353_TS-TEST2_FNO-8_08tl5igt' to datafilecopy '/oracle_data_2/ggtest1/test2_01.dbf';
4> switch datafile '/oracle_data_2/cpydata_D-GGTEST1_I-1273850353_TS-TEST3_FNO-9_09tl5ih1' to datafilecopy '/oracle_data_2/ggtest1/test3_01.dbf';
5> switch datafile '/oracle_data_2/cpydata_D-GGTEST1_I-1273850353_TS-TEST4_FNO-10_0atl5ih2' to datafilecopy '/oracle_data_2/ggtest1/test4_01.dbf';
6> }
using target database control file instead of recovery catalog
datafile 8 switched to datafile copy
input datafile copy RECID=7 STAMP=995281762 file name=/oracle_data_2/ggtest1/test2_01.dbf

datafile 9 switched to datafile copy
input datafile copy RECID=8 STAMP=995281764 file name=/oracle_data_2/ggtest1/test3_01.dbf

datafile 10 switched to datafile copy
input datafile copy RECID=9 STAMP=995281764 file name=/oracle_data_2/ggtest1/test4_01.dbf

RMAN> **end-of-file**


==============================================================================


OVERALL TOTALS FOR ALL NON-RECURSIVE STATEMENTS

call     count       cpu    elapsed       disk      query    current        rows
------- ------  -------- ---------- ---------- ---------- ----------  ----------
Parse      536      0.02       0.03          0          0          0           0
Execute    546      0.29       0.34          0          0          0         484
Fetch       54      0.09       0.11          0          0          0          54
------- ------  -------- ---------- ---------- ---------- ----------  ----------
total     1136      0.41       0.49          0          0          0         538

Misses in library cache during parse: 15
Misses in library cache during execute: 5

Elapsed times include waiting on following events:
  Event waited on                             Times   Max. Wait  Total Waited
  ----------------------------------------   Waited  ----------  ------------
  SQL*Net message to client                     564        0.00          0.00
  SQL*Net message from client                   563        0.22          0.41
  control file sequential read                  897        0.00          0.01
  asynch descriptor resize                       18        0.00          0.00
  SQL*Net break/reset to client                  12        0.00          0.00
  Disk file operations I/O                       24        0.00          0.00
  RMAN backup & recovery I/O                      9        0.00          0.00
  control file parallel write                    30        0.00          0.03


OVERALL TOTALS FOR ALL RECURSIVE STATEMENTS

call     count       cpu    elapsed       disk      query    current        rows
------- ------  -------- ---------- ---------- ---------- ----------  ----------
Parse       20      0.00       0.00          0          0          0           0
Execute     27      0.06       0.06          0          0          0           0
Fetch       33      0.02       0.02          0         16          0          12
------- ------  -------- ---------- ---------- ---------- ----------  ----------
total       80      0.10       0.09          0         16          0          12

Misses in library cache during parse: 2
Misses in library cache during execute: 1

Elapsed times include waiting on following events:
  Event waited on                             Times   Max. Wait  Total Waited
  ----------------------------------------   Waited  ----------  ------------
  control file sequential read                  197        0.00          0.00
  asynch descriptor resize                       24        0.00          0.00

  536  user  SQL statements in session.
   27  internal SQL statements in session.
  563  SQL statements in session.
********************************************************************************
Trace file: ggtest1_ora_2598.trc
Trace file compatibility: 11.1.0.7
Sort options: default

       1  session in tracefile.
     536  user  SQL statements in trace file.
      27  internal SQL statements in trace file.
     563  SQL statements in trace file.
      39  unique SQL statements in trace file.
   25741  lines in trace file.
       1  elapsed seconds in trace file.

=====================================================================

******************************************************************************


Flashback data archive steps

 Objective: Ways to track DML changes in a table Detailed objective: We should be able to track the changes in the table at any point in tim...