01 March 2020

AWR, Snapshot and Baseline for Report

ใน Database จะใช้ AWR (Automatic Workload repository) สำหรับรวบรวมการประมวลผลต่างๆและเก็บสถิติประสิทธิภาพการใช้งาน  แล้วจึงนำมาแสดงสถานะและประสิทธิภาพของ Database ในรูปแบบของ report เพื่อนำไปการตรวจปัญหาต่างๆและ tuning Database ด้วยตนเอง

AWR เก็บรวบรวมข้อมูลดังนี้
- Object Statistics (สถิติการ access และ usage ของ Database segments)
- Time Model Statistics (V$SYS_TIME_MODEL และ V$SESS_TIME_MODEL)
- Some of the System and Session Statistics (V$SYSSTAT และ V$SESSTAT)
- ASH (Active Session History) Statistics
- High load generating SQL Statements

Components ต่างๆของ AWR
- Automatic Database Diagnostic Monitor
- Undo Advisor
- SQL Tuning Advisor
- Segment Advisor

Snapshots
- การ snapshot ในแต่ละอัน คือ เริ่ม snapshot (BEGIN_INTERVAL_TIME) และทำการเก็บค่าต่างๆ และจบการ snapshot (END_INTERVAL_TIME)
                     SNAPSHOT1             SNAPSHOT2                 SNAPSHOT3
เริ่มSnapshot SNAPSHOT_INTERVAL จบSnapshot --> เริ่มSnapshot SNAPSHOT_INTERVAL จบSnapshot --> เริ่มSnapshot SNAPSHOT_INTERVAL จบSnapshot

- ถ้าช่วงระยะห่างของ start ถึง end time ของการ snapshot มีค่าน้อยจะเก็บรายละเอียดได้มากกว่ามีค่ามาก เพราะค่าน้อยจะเกิดการ snapshot บ่อยกว่า จึงมีข้อมูลเก็บไว้หลากหลายกว่า ทำให้วิเคราะห์ได้ละเอียดกว่า แต่การ snapshot จำนวนมาก ก็จะต้องการพื้นที่และกระทบกับการทำงานของระบบมากกว่า
 การพิจารณาว่าจะกำหนดช่วงให้ห่างกันเท่าไร ให้ดูจากถ้าช่วงไหนมีปัญหาบ่อย ก็ให้กำหนดช่วงสั้นๆ เพื่อให้หาสาเหตุได้ง่ายขึ้น แต่พอแก้ไขปัญหาแล้วระบบทำงานปกติ ก็ให้กำหนดช่วงยาวๆแทน
   เช่น
    ตัวอย่าง
จำนวน session ในแต่ละช่วงเวลา
2020/01/01 00:00 = 1
2020/01/01 01:00 = 10
2020/01/01 02:00 = 20
...
....
.....
2020/01/01 22:00 = 220
2020/01/01 23:00 = 230
2020/01/02 00:00 = 240
 
กรณี snap ทุกๆ 1 ชม
SNAP_ID BEGIN_INTERVAL_TIME END_INTERVAL_TIME  
---------- ------------------- -------------------
24  2020/01/01 23:00:00 2020/01/02 00:00:00
23  2020/01/01 22:00:00 2020/01/01 23:00:00
22  2020/01/01 21:00:00 2020/01/01 22:00:00
....                                       
......                                     
........ 
5   2020/01/01 02:00:00 2020/01/01 05:00:00
4   2020/01/01 02:00:00 2020/01/01 04:00:00
3   2020/01/01 02:00:00 2020/01/01 03:00:00
2   2020/01/01 01:00:00 2020/01/01 02:00:00
1   2020/01/01 00:00:00 2020/01/01 01:00:00
กรณี snap ทุกๆ 6 ชม
SNAP_ID BEGIN_INTERVAL_TIME END_INTERVAL_TIME  
---------- ------------------- -------------------
4   2020/01/01 18:00:00 2020/01/02 00:00:00
3   2020/01/01 12:00:00 2020/01/01 18:00:00
2   2020/01/01 06:00:00 2020/01/01 12:00:00
1   2020/01/01 00:00:00 2020/01/01 06:00:00
ตัวอย่าง 1 ต้องการหาการเปลี่ยนแปลงจำนวน sessions ในช่วงเวลา 2020/01/01 01:00:00 - 2020/01/01 05:00:00 กรณี snap ทุกๆ 1 ชม SNAP_ID 1 มีจำนวน session Begin ถึง End = 1 ถึง 10 SNAP_ID 2 มีจำนวน session Begin ถึง End = 10 ถึง 20 SNAP_ID 3 มีจำนวน session Begin ถึง End = 20 ถึง 30 SNAP_ID 4 มีจำนวน session Begin ถึง End = 30 ถึง 40 SNAP_ID 5 มีจำนวน session Begin ถึง End = 40 ถึง 50 กรณี snap ทุกๆ 6 ชม SNAP_ID 1 มีจำนวน session Begin ถึง End = 1 ถึง 60 SNAP_ID 2 มีจำนวน session Begin ถึง End = 60 ถึง 120 จะเห็นว่า snap ทุกๆ 1 ชม แสดง report (จะใช้ค่า End) = 10 ถึง 50 ได้ค่าที่ตรงกับความเป็นจริงมากกว่า snap ทุกๆ 6 ชม แสดง report (จะใช้ค่า End) = 60 ถึง 120 ตัวอย่าง 2 ต้องการหาการเปลี่ยนแปลงจำนวน sessions ในช่วงเวลา 2020/01/01 02:00:00 - 2020/01/01 03:00:00 กรณี snap ทุกๆ 1 ชม SNAP_ID 2 มีจำนวน session Begin ถึง End = 10 ถึง 20 SNAP_ID 3 มีจำนวน session Begin ถึง End = 20 ถึง 30 กรณี snap ทุกๆ 6 ชม มี SNAP_ID = 1 SNAP_ID 1 มีจำนวน session Begin ถึง End = 1 ถึง 60 SNAP_ID 2 มีจำนวน session Begin ถึง End = 60 ถึง 120 จะเห็นว่า snap ทุกๆ 1 ชม แสดง report (จะใช้ค่า End) = 20 ถึง 30 ได้ค่าที่ตรงกับความเป็นจริงมากกว่า snap ทุกๆ 6 ชม แสดง report (จะใช้ค่า End) = 60 ถึง 120

- การเกิดใหม่ของ Snapshot หรือ SNAP_ID ตัวใหม่ ใน DBA_HIST_SNAPSHOT เมื่อ snapshot เริ่มต้นทำงาน คือ เกิด BEGIN_INTERVAL_TIME โดยจะยังไม่มีข้อมูลใน DBA_HIST_SNAPSHOT จนกว่าจะจบการทำงาน คือ เกิด END_INTERVAL_TIME หรือเรียกว่า จบการ snapshot
- ค่า default คือ ทำการ snapshot ทุกๆ 1 ชม (INTERVAL)  และเก็บรักษา snapshot เอาไว้ 8 วัน (RETENTION)
- สำหรับการออก report
  การกำหนดช่วงของ snapshot จะแสดง report นับจาก snap ID เริ่มต้น ถึง snap ID สิ้นสุด โดยใช้ END_INTERVAL_TIME แสดงว่าถ้าต้องการกำหนด snapshot ในช่วงเวลาใดๆต้องดูจากระยะ END_INTERVAL_TIME
  เช่น
 DBA_HIST_SNAPSHOT
    SNAP_ID       DBID INSTANCE_NUMBER BEGIN_INTERVAL_TIME END_INTERVAL_TIME  
 ---------- ---------- --------------- ------------------- -------------------
        86 1256122414               1 2020/09/10 14:00:54 2020/09/10 15:00:28
        85 1256122414               1 2020/09/10 13:00:25 2020/09/10 14:00:54
        84 1256122414               1 2020/09/10 12:00:51 2020/09/10 13:00:25
        83 1256122414               1 2020/09/10 10:35:05 2020/09/10 12:00:51
        82 1256122414               1 2020/09/09 18:00:04 2020/09/10 10:35:05
        81 1256122414               1 2020/09/09 17:00:32 2020/09/09 18:00:04
        80 1256122414               1 2020/09/09 16:27:05 2020/09/09 17:00:32
  ต้องการ report ช่วงเวลา 2020/09/09 17:00 ถึง 2020/09/10 15:00 จะต้องเลือก start snapshot = 80 และ end snapshot = 86
  โดย report จะแสดง Begin Snap = 17:00:32 และ End Snap = 15:00:28

RETENTION หรือ RETENTION_INTERVAL (ระยะการเก็บรักษา)
- คือ ช่วงเวลาหน่วยนาทีในการเก็บรักษา history เอาไว้
- ระบุค่าต่างๆ
ค่าเป็นตัวเลข ค่าที่ระบุต้องอยู่ในช่วง MIN_RETENTION (1 วัน) ถึง MAX_RETENTION (100 ปี)
ค่า 0 คือ Snapshot จะเก็บรักษาไว้ตลอดไป ค่าที่ระบบกำหนดส่วนมากจะใช้เป็นการตั้งค่าการเก็บข้อมูล
ค่า NULL คือ Snapshot ค่าเดิมจะถูกรักษาไว้

INTERVAL หรือ  SNAPSHOT_INTERVAL (ระยะ snapshot)
- คือ ช่วงระยะห่างของเวลาเริ่มต้นและสิ้นสุดของแต่ล่ะ Snapshot หน่วยนาที หรือเรียกว่า ในแต่ละ snapshot จะเริ่มเก็บจนหยุดเก็บใช้เวลาเท่าไร
- ระบุค่าต่างๆ
ค่าเป็นตัวเลข ค่าที่ระบุต้องอยู่ในช่วง MIN_INTERVAL (10 นาที) ถึง MAX_INTERVAL (1 ปี)
ค่า 0 คือ ทำการ Snapshot แบบ auto โดยการทำงาน Snapshot ในแบบ manual จะถูกปิดใช้งานการรวบรวมสถิติทั้งหมด ค่าที่ระบบกำหนดส่วนมากจะใช้เป็นการตั้งค่าการเก็บข้อมูล
ค่า NULL คือ Snapshot ค่าปัจจุบันจะถูกรักษาไว้

TOPNSQL
- ระบุค่าเป็นตัวเลข 
- คือ จำนวนสูงสุดของ SQL ที่จะ flush ข้อมูลของแต่ละ  criteria (Elapsed Time, CPU Time, Parse Calls, Shareable Memory, และ Version Count)
- จะไม่กระทบกับ statistics และ flush level แต่จะแทนที่ค่า system default ของ AWR SQL collection
- การตั้งค่าจะมีดังนี้
ค่าเป็นตัวเลข กำหนดได้ต่ำสุด 30 และสูงสุด 50000
NULL จะคงการตั้งค่าปัจจุบันไว้
- ระบุค่าเป็น varchar(2)
- การตั้งค่าจะมีดังนี้
MAXIMUM ทำการ capture SQL ใน cursor cache แบบสมบูรณ์
ค่าเป็นตัวเลข กำหนดได้ต่ำสุด 30 และสูงสุด 50000
DEFAULT กำหนดค่าแบบ default คือ top 30 สำหรับ statistics level แบบ TYPICAL และ top 100 สำหรับ statistics level แบบ ALL
NULL จะคงการตั้งค่าปัจจุบันไว้nt will keep the current setting.

- Criteria 14 อัน ใน AWR report และ Oracle AWR จะ capture ใน top-n-SQL ของแต่ละ criteria จาก http://www.dba-oracle.com/t_awr_automatic_snapshot_settings_modify.htm
1.Elapsed Time (ms)
2.CPU Time (ms)
3.Executions
4.Buffer Gets
5.Disk Reads
6.Parse Calls
7.Rows
8.User I/O Wait Time (ms)
9.Cluster Wait Time (ms)
10.Application Wait Time (ms)
11.Concurrency Wait Time (ms)
12.Invalidations
13.Version Count
14.Sharable Mem(KB)

แสดงเวลาของการ snapshot
- BEGIN_INTERVAL_TIME คือ เวลาที่เริ่ม snapshot
- END_INTERVAL_TIME คือ เวลาที่จบ snapshot
- BEGIN_INTERVAL_TIME ถึง END_INTERVAL_TIME ระยะเวลาจะห่างกันตามค่า SNAPSHOT_INTERVAL

คำสั่ง modify snapshot settings
dbms_workload_repository.modify_snapshot_settings(
   retention   in  number    default null,
   interval    in  number    default null,
   topnsql     in  number    default null,
   dbid        in  number    default null);

คำสั่ง taken snapshot
exec dbms_workload_repository.create_snapshot;

คำสั่ง removed snapshot
begin
  dbms_workload_repository.drop_snapshot_range (
    low_snap_id  => 22,
    high_snap_id => 32);
end;


แสดงค่าจำนวน วัน ชม นาที วินาที ของ SNAPSHOT_INTERVAL และ RETENTION_INTERVAL

ตัวอย่าง ทำการ snapshot ทุกๆ 1 ชม และเก็บรักษา snapshot เอาไว้ 8 วัน

รูปแบบของ SNAP_INTERVAL และ RETENTION คือ +วัน ชม:นาที:วินาที
SQL> select dbid,snap_interval,retention,topnsql from dba_hist_wr_control;
      DBID SNAP_INTERVAL         RETENTION            TOPNSQL 
---------- --------------------- -------------------- ----------
1550490185 +00 01:00:00.000000   +08 00:00:00.000000  DEFAULT 
หรือ
SNAPSHOT_INTERVAL_SEC และ RETENTION_INTERVAL_SEC หน่วยคือ seconds
set linesize 1000
SQL> select
(' Total='||trunc(wrcon.snapshot_interval_sec/60/60/24) || 'Day '
||to_char(trunc(MOD(wrcon.snapshot_interval_sec/60/60,24)),'fm9900')||':'||to_char(trunc(MOD(wrcon.snapshot_interval_sec,3600)/60),'fm00')||':'||to_char(MOD(MOD(wrcon.snapshot_interval_sec,3600),60),'fm00')
)snapshot_interval
,(' Total='||trunc(wrcon.retention_interval_sec/60/60/24) || 'Day '
||to_char(trunc(MOD(wrcon.retention_interval_sec/60/60,24)),'fm9900')||':'||to_char(trunc(MOD(wrcon.retention_interval_sec,3600)/60),'fm00')||':'||to_char(MOD(MOD(wrcon.retention_interval_sec,3600),60),'fm00')
)retention_interval
from
(select (extract(day from snap_interval) *24*60+extract(hour from snap_interval) *60+extract(minute from snap_interval))*60 snapshot_interval_sec
,(extract(day from retention) *24*60+extract(hour from retention) *60+extract(minute from retention))*60 retention_interval_sec
from dba_hist_wr_control)wrcon;
SNAPSHOT_INTERVAL         RETENTION_INTERVAL                                           
------------------------- ----------------------
Total=0Day 01:00:00       Total=8Day 00:00:00

แสดงค่าจำนวน นาที ของ SNAPSHOT_INTERVAL และ RETENTION_INTERVAL (เป็นค่าที่ set ใน parameter)
SQL> select extract(day from snap_interval) *24*60+extract(hour from snap_interval) *60+extract(minute from snap_interval) snapshot_interval,
extract(day from retention) *24*60+extract(hour from retention) *60+extract(minute from retention) retention_interval
from dba_hist_wr_control;
SNAPSHOT_INTERVAL RETENTION_INTERVAL
----------------- ------------------
               60              11520

แสดง detail snapshot ทั้งหมดที่มีอยู่
SQL> select sn.snap_id,sn.dbid,sn.instance_number
--,sn.startup_time
,to_char(sn.begin_interval_time,'yyyy/mm/dd hh24:mi:ss')begin_interval_time
,to_char(sn.end_interval_time,'yyyy/mm/dd hh24:mi:ss')end_interval_time
from dba_hist_snapshot sn
where to_char(sn.begin_interval_time,'yyyy/mm/dd hh24:mi:ss') >= '2018/07/05 00:00:00' and to_char(sn.end_interval_time,'yyyy/mm/dd hh24:mi:ss') <= '2018/07/05 06:00:00'
order by sn.begin_interval_time desc,sn.end_interval_time desc
;
   SNAP_ID       DBID INSTANCE_NUMBER STARTUP_TIME                BEGIN_INTERVAL_TIME END_INTERVAL_TIME
---------- ---------- --------------- --------------------------- ------------------- -------------------
      6551 1550490185               1 6/7/2018 5:25:17.000 PM     2018/07/05 04:00:08 2018/07/05 05:00:39
      6550 1550490185               1 6/7/2018 5:25:17.000 PM     2018/07/05 03:00:44 2018/07/05 04:00:08
      6549 1550490185               1 6/7/2018 5:25:17.000 PM     2018/07/05 02:00:07 2018/07/05 03:00:44
      6548 1550490185               1 6/7/2018 5:25:17.000 PM     2018/07/05 01:00:45 2018/07/05 02:00:07
      6547 1550490185               1 6/7/2018 5:25:17.000 PM     2018/07/05 00:00:38 2018/07/05 01:00:45


แสดง summary snapshot ทั้งหมดที่มีอยู่
SQL> select min(sn.snap_id)min_snap_id,max(sn.snap_id)max_snap_id
,min(to_char(sn.begin_interval_time,'yyyy/mm/dd hh24:mi:ss'))min_begin_interval_time
--,max(to_char(sn.begin_interval_time,'yyyy/mm/dd hh24:mi:ss'))max_begin_interval_time
--,min(to_char(sn.end_interval_time,'yyyy/mm/dd hh24:mi:ss'))min_end_interval_time
,max(to_char(sn.end_interval_time,'yyyy/mm/dd hh24:mi:ss'))max_end_interval_time
,count(sn.snap_id)count_snap
from dba_hist_snapshot sn
where to_char(sn.begin_interval_time,'yyyy/mm/dd hh24:mi:ss') >= '2018/07/05 00:30:00' and to_char(sn.end_interval_time,'yyyy/mm/dd hh24:mi:ss') <= '2018/07/05 03:30:00'
;
MIN_SNAP_ID MAX_SNAP_ID MIN_BEGIN_INTERVAL_TIME MAX_END_INTERVAL_TIME COUNT_SNAP
----------- ----------- ----------------------- --------------------- ----------
      42606       42610 2018/07/05 00:30:20     2018/07/05 03:00:27           10

Snapshots settings

Set STATISTICS_LEVEL เป็นการกำหนดจำนวนของ SQL statements ที่จะทำการ captured ดูเพิ่มเติมจาก Document "ORACLE_TUNING_Statistics Level.txt"
SQL> alter system set statistics_level=typical;
หรือ
SQL> alter system set statistics_level=all;

Modify snapshot settings
ตัวอย่าง snapshot ทุกๆ 10 นาที และเก็บ history เป็นเวลา 3 ปี
SQL> execute dbms_workload_repository.modify_snapshot_settings (interval => 10,retention => 1576800);
หรือ กำหนดค่าเหมือนค่า default คือ snapshot ทุกๆชม. และเก็บ history เป็นเวลา 7 วัน
SQL> execute dbms_workload_repository.modify_snapshot_settings (interval => 60,retention => 10080);

Baselines
- เป็นการสร้าง snapshot ในช่วงเวลาใดๆก็ได้ที่ต้องการใช้เป็นตัวนำไปเปรียบเทียบกับตัวอื่นๆ
   เช่น ช่วงเวลา 08.00 น. ระบบจะทำงานช้ามาก จึงนำช่วงนี้มาสร้างเป็น baseline ชื่อ SYSTEM_CRITICAL เพื่อนำไปเทียบกับ snapshot อื่นๆที่ทำงานช้า ว่ามี metrics แตกต่างจาก SYSTEM_CRITICAL อย่างไร
         ช่วงเวลา 12.00 น. ระบบจะทำงานเป็นปกติ จึงนำช่วงนี้มาสร้างเป็น baseline ชื่อ SYSTEM_NORMAL เพื่อนำไปเทียบกับ snapshot อื่นๆที่ทำงานช้า ว่ามี metrics แตกต่างจาก SYSTEM_NORMAL อย่างไร

แสดง Baseline
set linesize 1000
SQL> select bl.dbid,bl.baseline_id,bl.baseline_name,bl.baseline_type
,bl.start_snap_id,bl.end_snap_id
,bl.start_snap_time,bl.end_snap_time
,bl.moving_window_size
from dba_hist_baseline bl;
      DBID BASELINE_ID BASELINE_NAME                 BASELINE_TYPE START_SNAP_ID END_SNAP_ID START_SNAP_TIME                    END_SNAP_TIME                    MOVING_WINDOW_SIZE
---------- ----------- ----------------------------- ------------- ------------- ----------- ---------------------------------- -------------------------------- ------------------
1550490185           1 SYSTEM_NORMAL                 STATIC                 6000        6010 6/12/2018 6:00:21.094 AM           6/12/2018 4:00:49.560 PM                         
1550490185           2 SYSTEM_CRITICAL               STATIC                 5993        5999 6/11/2018 11:00:59.064 PM          6/12/2018 5:00:20.522 AM                         
1550490185           0 SYSTEM_MOVING_WINDOW          MOVING_WINDOW          6006        6197 6/12/2018 12:00:52.653 PM          6/20/2018 11:00:10.618 AM                         8


Create baseline
SQL> begin
  dbms_workload_repository.create_baseline (
    start_snap_id => 210,
    end_snap_id   => 220,
    baseline_name => 'mybaseline_batch_workingday');
end;
/

Delete baseline
SQL> begin
  dbms_workload_repository.drop_baseline (
    baseline_name => 'mybaseline_batch_workingday',
    cascade       => FALSE); -- Deletes associated snapshots if TRUE.
end;
/

การสร้าง AWR Report ด้วย AWR Scripts

AWR Report
--> sqlplus / as sysdba @$ORACLE_HOME/rdbms/admin/awrrpt.sql
SQL*Plus: Release 12.2.0.1.0 Production on Tue Jan 22 12:06:52 2019
Copyright (c) 1982, 2016, Oracle.  All rights reserved.

Connected to:
Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production

Specify the Report Type
~~~~~~~~~~~~~~~~~~~~~~~
AWR reports can be generated in the following formats. Please enter the
name of the format at the prompt.  Default value is 'html'.

'html' HTML format (default)
'text' Text format
'active-html' Includes Performance Hub active report

Enter value for report_type: html
old   1: select 'Type Specified: ',lower(nvl('&&report_type','html')) report_type from dual
new   1: select 'Type Specified: ',lower(nvl('html','html')) report_type from dual

Type Specified:  กำหนดประเภทรายงาน --> html

old   1: select '&&report_type' report_type_def from dual
new   1: select 'html' report_type_def from dual

old   1: select '&&view_loc' view_loc_def from dual
new   1: select 'AWR_PDB' view_loc_def from dual

Current Instance
~~~~~~~~~~~~~~~~
DB Id        DB Name       Inst Num      Instance     Container Name
-------------- -------------- -------------- -------------- --------------
 1186862925 DBTEST1      1 dbtest1      dbtest1

Instances in this Workload Repository schema
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  DB Id      Inst Num DB Name      Instance   Host
------------ ---------- ---------    ----------   ------
* 1186862925  1 DBTEST1      dbtest1   oradb12c.loc

Using 1186862925 for database Id
Using        1 for instance number

Specify the number of days of snapshots to choose from
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Entering the number of days (n) will result in the most recent
(n) days of snapshots being listed.  Pressing without
specifying a number lists all completed snapshots.

Enter value for num_days: กำหนดจำนวนวัน --> 5

Listing the last 5 days of Completed Snapshots
Instance     DB Name   Snap Id Snap Started Snap Level
------------ ------------ ---------- ------------------ ----------
dbtest1      DBTEST1 429  21 Jan 2019 21:04   1
430  21 Jan 2019 21:15   1
431  21 Jan 2019 21:30   1
432  21 Jan 2019 21:45   1
....
......
...........
452  22 Jan 2019 02:45   1
453  22 Jan 2019 03:00   1
454  22 Jan 2019 03:15   1
455  22 Jan 2019 03:30   1
....
......
...........
489  22 Jan 2019 12:00   1
490  22 Jan 2019 12:15   1
491  22 Jan 2019 12:30   1

Specify the Begin and End Snapshot Ids
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Enter value for begin_snap: กำหนดSnapIDเริ่มต้น --> 429
Begin Snapshot Id specified: 429

Enter value for end_snap: กำหนดSnapIDสิ้นสุด --> 489
End   Snapshot Id specified: 489

Specify the Report Name
~~~~~~~~~~~~~~~~~~~~~~~
The default report file name is awrrpt_1_429_489.html. To use this name,
press to continue, otherwise enter an alternative.

Enter value for report_name: กำหนดReportName --> awr_20190121to20190122

Using the report name awr_20190121to20190122
.......
...........
...............

End of Report

Report written to awr_20190121to20190122

จะได้ AWR Report file
--> ls -lrt
total 884
-rw-r--r--. 1 oracle oinstall 902197 Jan 22 12:08 awr_20190121to20190122.lst

Transfer awr_20190121to20190122.lst ไปที่ Local PC และแก้ไข file จาก .lst เป็น .html
และ open ด้วย Browser Tool จะสามารถดู AWR ได้

Compare Two AWR Reports

--> sqlplus / as sysdba @$ORACLE_HOME/rdbms/admin/awrddrpt.sql
SQL*Plus: Release 12.2.0.1.0 Production on Tue Jan 22 12:40:29 2019
Copyright (c) 1982, 2016, Oracle.  All rights reserved.

Connected to:
Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production

Specify the Report Type
~~~~~~~~~~~~~~~~~~~~~~~
Would you like an HTML report, or a plain text report?
Enter 'html' for an HTML report, or 'text' for plain text
Defaults to 'html'
Enter value for report_type: html
old   1: select 'Type Specified: ',lower(nvl('&&report_type','html')) report_type from dual
new   1: select 'Type Specified: ',lower(nvl('html','html')) report_type from dual

Type Specified: กำหนดประเภทรายงาน --> html

old   1: select '&&report_type' report_type_def from dual
new   1: select 'html' report_type_def from dual

old   1: select '&&view_loc' view_loc_def from dual
new   1: select 'AWR_PDB' view_loc_def from dual

Current Instance
~~~~~~~~~~~~~~~~
old   1: select (case when '&view_loc' = 'AWR_PDB'
new   1: select (case when 'AWR_PDB' = 'AWR_PDB'

old   1: select &default_dbid   dbid
new   1: select 1186862925     dbid
old   2:      , &default_dbid   dbid2
new   2:      , 1186862925     dbid2

   DB Id       DB Id DB Name      Inst Num Inst Num Instance
----------- ----------- ------------ -------- -------- ------------
 1186862925  1186862925 DBTEST1      1      1 dbtest1

Instances in this Workload Repository schema
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  DB Id      Inst Num DB Name      Instance   Host
------------ ---------- ---------    ----------   ------
* 1186862925  1 DBTEST1      dbtest1   oradb12c.loc

Database Id and Instance Number for the First Pair of Snapshots
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Using 1186862925 for Database Id for the first pair of snapshots
Using        1 for Instance Number for the first pair of snapshots

Specify the number of days of snapshots to choose from
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Entering the number of days (n) will result in the most recent
(n) days of snapshots being listed.  Pressing without
specifying a number lists all completed snapshots.

Enter value for num_days: กำหนดจำนวนวันของFirst --> 2

Listing the last 2 days of Completed Snapshots
Instance     DB Name   Snap Id Snap Started Snap Level
------------ ------------ ---------- ------------------ ----------
dbtest1      DBTEST1 429  21 Jan 2019 21:04   1
          430  21 Jan 2019 21:15   1
431  21 Jan 2019 21:30   1
432  21 Jan 2019 21:45   1
....
......
...........
452  22 Jan 2019 02:45   1
453  22 Jan 2019 03:00   1
454  22 Jan 2019 03:15   1
455  22 Jan 2019 03:30   1
....
......
...........
489  22 Jan 2019 12:00   1
490  22 Jan 2019 12:15   1
491  22 Jan 2019 12:30   1

Specify the First Pair of Begin and End Snapshot Ids
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Enter value for begin_snap: กำหนดSnapIDเริ่มต้นของFirst --> 429
First Begin Snapshot Id specified: 429

Enter value for end_snap: กำหนดSnapIDสิ้นสุดของFirst --> 440
First End   Snapshot Id specified: 440

Instances in this Workload Repository schema
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  DB Id      Inst Num DB Name      Instance   Host
------------ ---------- ---------    ----------   ------
* 1186862925  1 DBTEST1      dbtest1   oradb12c.loc

Database Id and Instance Number for the Second Pair of Snapshots
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Using 1186862925 for Database Id for the second pair of snapshots
Using        1 for Instance Number for the second pair of snapshots

Specify the number of days of snapshots to choose from
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Entering the number of days (n) will result in the most recent
(n) days of snapshots being listed.  Pressing without
specifying a number lists all completed snapshots.

Enter value for num_days2: กำหนดจำนวนวันของSecond --> 2

Listing the last 2 days of Completed Snapshots
                                429  21 Jan 2019 21:04   1
430  21 Jan 2019 21:15   1
431  21 Jan 2019 21:30   1
432  21 Jan 2019 21:45   1
....
......
...........
452  22 Jan 2019 02:45   1
453  22 Jan 2019 03:00   1
454  22 Jan 2019 03:15   1
455  22 Jan 2019 03:30   1
....
......
...........
489  22 Jan 2019 12:00   1
490  22 Jan 2019 12:15   1
491  22 Jan 2019 12:30   1

Specify the Second Pair of Begin and End Snapshot Ids
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Enter value for begin_snap2: กำหนดSnapIDเริ่มต้นของSecond -->  441
Second Begin Snapshot Id specified: 441

Enter value for end_snap2: กำหนดSnapIDสิ้นสุดของSecond --> 491
Second End   Snapshot Id specified: 491

Specify the Report Name
~~~~~~~~~~~~~~~~~~~~~~~
The default report file name is awrdiff_1_429_1_441.html  To use this name,
press to continue, otherwise enter an alternative.

Enter value for report_name: กำหนดReportName --> awr_20190121compare20190122

Using the report name awr_20190121compare20190122
.......
.............
.................


Report written to awr_20190121compare20190122

จะได้ AWR Report file
--> ls -lrt
total 1192
-rw-r--r--. 1 oracle oinstall 1217225 Jan 22 12:42 awr_20190121compare20190122.lst

Transfer awr_20190121compare20190122.lst to Local PC และแก้ไข file จาก .lst เป็น .html
และ open ด้วย Browser Tool จะสามารถดู AWR ได้

การสร้าง AWR Report ด้วย SQL Developer

เปิดใช้งานเครื่องมือสำหรับ DBA
Menu View > DBA

จะเห็นหน้าจอ DBA และไปที่ Menu Performance > AWR
จะเห็นรูปแบบรายงานดังนี้
AWR Report Viewer สำหรับออกรายงาน AWR อันเดียว
Difference Report Viewer สำหรับออกรายงาน AWR สองอัน แล้วนำมาเปรียบเทียบกัน
SQL Report Viewer สำหรับออกรายงาน SQL อันเดียว

การกำหนดช่วงของ snapshot จะแสดง report นับจาก snap ID เริ่มต้น ถึง snap ID สิ้นสุด โดยใช้ END_INTERVAL_TIME