Monday, March 6, 2017

privileges required to generate awr report

GRANT SELECT ON SYS.V_$DATABASE TO FCUBSUSR;
GRANT SELECT ON SYS.V_$INSTANCE TO FCUBSUSR;
GRANT EXECUTE ON SYS.DBMS_WORKLOAD_REPOSITORY TO FCUBSUSR;
GRANT SELECT ON SYS.DBA_HIST_DATABASE_INSTANCE TO FCUBSUSR;
GRANT SELECT ON SYS.DBA_HIST_SNAPSHOT TO FCUBSUSR;

SELECT * FROM
TABLE(sys.DBMS_WORKLOAD_REPOSITORY.awr_report_html(<dbid>,<instance_number>,<snapshot_id begin>,<snapshot_id eind>));
select * from table( dbms_xplan.display_awr('&sql_id', plan_hash_value => '&plan_hash_value', format =>'ALL ALLSTATS LAST -PROJECTION')); --format =>'ALL ALLSTATS LAST')) --'ADVANCED +PEEKED_BINDS +ALLSTATS LAST +MEMSTATS LAST') ); set linesize 999 set pagesize 999 --set serveroutput off REM Note REM ----- REM - Warning: basic plan statistics not available. These are only collected when: REM * hint 'gather_plan_statistics' is used for the statement or REM * parameter 'statistics_level' is set to 'ALL', at session or system level select * from table( dbms_xplan.display_awr('&sql_id', plan_hash_value => '&plan_hash_value', format => 'ADVANCED ALLSTATS LAST') ) --'ADVANCED +PEEKED_BINDS +ALLSTATS LAST +MEMSTATS LAST partition cost') ) / --'ALLSTATS LAST')) --
VAR dbid NUMBER

PROMPT Listing latest AWR snapshots ...
SELECT snap_id, end_interval_time 
FROM dba_hist_snapshot 
--WHERE begin_interval_time > TO_DATE('2011-06-07 07:00:00', 'YYYY-MM-DD HH24:MI:SS') 
WHERE end_interval_time > SYSDATE - 1
ORDER BY end_interval_time;

ACCEPT bid NUMBER PROMPT "Enter begin snapshot id: "
ACCEPT eid NUMBER PROMPT "Enter   end snapshot id: "

BEGIN
  SELECT dbid INTO :dbid FROM v$database;
END;
/

SET TERMOUT OFF PAGESIZE 0 HEADING OFF LINESIZE 1000 TRIMSPOOL ON TRIMOUT ON TAB OFF

SPOOL awr_local_inst_1.html
SELECT * FROM TABLE(DBMS_WORKLOAD_REPOSITORY.AWR_REPORT_HTML(:dbid, 1, &bid, &eid));

--------Generate AWR on-screen


declare
  v_btime     date := to_date('&v_btime','rrmmdd hh24mi');
  v_etime     date := to_date('&v_etime','rrmmdd hh24mi');
  v_dbid      V$database.dbid%TYPE;

begin
  for i in ( with AWR_snaps as(
           select dbid,instance_number,snap_id
             from dba_hist_snapshot
            where end_interval_time between v_btime
                                        and v_etime)
           select dbid,instance_number,min(snap_id) bsnap,max(snap_id)+1 esnap
             from AWR_snaps
            group by instance_number,dbid
            order by instance_number)
    loop
     dbms_output.put_line(chr(10)||'***** FOR INSTANCE:'||i.instance_number||' *****'||chr(10));
     FOR c_awrreport IN (SELECT output
                           FROM TABLE (dbms_workload_repository.awr_report_html
                                                ( i.dbid
                                                , i.instance_number
                                                , i.bsnap
                                                , i.esnap
                                                , 8)))
       LOOP
         dbms_output.put_line(c_awrreport.output);
       END LOOP;
   end loop;
   dbms_output.put_line('===END OF OUTPUT===');
end;
/


No comments:

Post a Comment