This is a brief description of how to collect the information to test the performance of programs written in PL\SQL
SELECT DBID FROM v$database;
SELECT inst_id FROM gv$instance;
SELECT SYS_CONTEXT ('USERENV', 'SID') FROM DUAL;
Run the ash report using one of those: - for time frame
SELECT * FROM TABLE(DBMS_WORKLOAD_REPOSITORY.ASH_REPORT_HTML(
L_DBID => <db_id>, -- this is number
L_INST_NUM => <inst_id>, -- this is number usualy 1
L_BTIME => sysdate - 60/1440, /* meaning start the report from 60 minutes ago */
L_ETIME => sysdate - 30/1440 /* Until 30 minutes ago */
));
You can Run ASH report for an exact date:
SELECT * FROM TABLE(DBMS_WORKLOAD_REPOSITORY.ASH_REPORT_HTML(
L_DBID => <db_id>, -- this is number
L_INST_NUM => <inst_id>, -- this is number usualy 1
L_BTIME => TO_DATE('22/2/2013 06:20','dd/mm/yyyy hh24:mi'),
L_ETIME => TO_DATE('22/2/2013 06:40','dd/mm/yyyy hh24:mi'),
L_SQL_ID =>'4susktwfs9jg2'));
SELECT * FROM table(DBMS_WORKLOAD_REPOSITORY.ASH_REPORT_HTML(
L_DBID => 123456,
L_INST_NUM => 1,
L_BTIME => TO_DATE('23/2/2019 10:00','dd/mm/yyyy hh24:mi'),
L_ETIME => TO_DATE('23/2/2019 16:00','dd/mm/yyyy hh24:mi'),
L_WAIT_CLASS =>'Commit' ));
SELECT * FROM TABLE(DBMS_WORKLOAD_REPOSITORY.ASH_REPORT_HTML(
L_DBID => 62116283,
L_INST_NUM => 1, -- this is number usualy 1
L_BTIME => TO_DATE('11/02/2019 15:06:20','dd/mm/yyyy hh24:mi:ss'),
L_ETIME => TO_DATE('11/02/2019 15:09:20','dd/mm/yyyy hh24:mi:ss'),
L_client_id=>'YourClientId'
));
Copy the result into a text editor. Save with HTML extention, and there you have your AWR report.
Remark: Based on stored object statistics and estimated costs
EXPLAIN PLAN FOR
SELECT * FROM stg_tst_interest_sem_um1_vu a;
SELECT * FROM TABLE(DBMS_XPLAN.DISPLAY);
SELECT /*+ GATHER_PLAN_STATISTICS */ *
FROM stg_tst_interest_sem_um1_vu a;
Remark: sometimes it does not work…
SELECT * FROM TABLE(DBMS_XPLAN.DISPLAY_CURSORFORMAT=>'ALLSTATS LAST'));
SELECT sql_id, sql_text
FROM v$sqlarea
WHERE sql_text LIKE '%GATHER_PLAN_STATISTICS%'
and sql_text NOT LIKE '%sqlarea%';
b. Get execution plan with actual run-time statistics (Replace the “&sql_id” with the actual SQL ID of the statement)
SELECT *
FROM TABLE(DBMS_XPLAN.DISPLAY_CURSOR(sql_id => '&sql_id',FORMAT=>'ALLSTATS LAST'));
SELECT /*+ MONITOR */ COUNT(*), AVG(salary)
FROM hr.employees
WHERE department_id = 50;
ALTER SESSION SET NLS_DATE_FORMAT='dd/mm/yyyy hh24:mi:ss';
SELECT sql_id, sql_exec_id, SQL_EXEC_START, SUBSTR(sql_text,1,80)
FROM V$SQL_MONITOR
WHERE sql_text LIKE '%MONITOR%'
ORDER BY SQL_EXEC_START DESC;
SELECT DBMS_SQLTUNE.report_sql_monitor(
sql_id=>'&sql_id',
sql_exec_id=>&sql_exec_id,
report_level=>'ALL') as text
FROM dual;
Using:
SELECT * FROM TABLE(DBMS_WORKLOAD_REPOSITORY.AWR_REPORT_HTML(
L_DBID => <DBID>,
L_INST_NUM => <INSTANCE_NUMBER>,
L_BID => <BEGIN_SNAP>,
L_EID => <END_SNAP>));
For example:
SELECT DBID FROM v$database;
SELECT
s.snap_id AS "snap_id",
to_char(s.end_interval_time,'dd/mm/yyyy HH24:mi') AS "snapshot time",
to_char(s.startup_time,'dd Mon "at" HH24:mi:ss') AS "Startup time"
FROM dba_hist_snapshot s
ORDER BY snap_id DESC;
You should choose snap_id for begin () and end parameters
SELECT * FROM TABLE(DBMS_WORKLOAD_REPOSITORY.AWR_REPORT_HTML(
L_DBID => 625123283,
L_INST_NUM => 1,
L_BID => 46980,
L_EID => 46982));
exec sys.dbms_workload_repository.create_snapshot;