Practice 6 - Using AWR SQL Reports
Practice 6 - Using AWR SQL Reports
Practice 6
Practice Target
In this practice, you will produce an AWR SQL report to list performance statistics and execution plans
history of a specific statement.
The script runs multiple SQL*Plus sessions at the same time. Each session executes the script
run_query.sql
counter=1
while [ \$counter -le \$1 ]
do
exit | sqlplus -L -S soe/soe @ run_query.sql &
((counter++))
done
EOL
chmod +x run_query.sh
sqlplus soe/soe
6. Run the following code to create a new table (ORDERS2) and gather its statistics.
CREATE TABLE ORDERS2 NOLOGGING AS SELECT * FROM ORDERS WHERE ORDER_ID <=150000;
ANALYZE TABLE ORDERS2 COMPUTE STATISTICS;
9. Run the following script twice. The script kicks off 30 SQL*Plus sessions. Each session runs the
query script.
After the last script finishes execution, you need to press on [ENTER] key to get back to the
command prompt.
./run_query.sh 30
11. Run the following code to create an index on the table ORDERS2
conn soe/soe
CREATE INDEX I2 ON ORDERS2 (ORDER_ID) NOLOGGING;
ANALYZE INDEX I2 COMPUTE STATISTICS;
12. Exit from SQL*Plus then run the following script twice.
EXIT
./run_query.sh 30
13. Obtain the SQL_ID of the executed query and take a note of it. (It should be '0rzpfnnv95pv1')
In real life, you would obtain the SQL_ID from outputs of a performance tuning tool (so many
tools retrieve them).
sqlplus / as sysdba
SELECT SQL_ID FROM V$SQL
WHERE SQL_TEXT LIKE 'SELECT ORDER_ID, ORDER_TOTAL FROM ORDERS2%';
15. Generate an AWR SQL report on the executed query based on the most recent three AWR
snapshots. Give it the name awr_sql.html
@ ?/rdbms/admin/awrsqrpt.sql
17. In the hosting PC, open the file using your favorite browser.
In the generated report, observe the following:
o The query was executed using two execution plans.
o The data was retrieved using full table scan (FTS) in one execution plan and using index
range scan in the other.
o Each execution plan was executed 60 times.
o As expected, the index based execution plan is more efficient than the FTS one.
In real life scenario, if you observe multiple execution plans for a statement, you need to study
the performance difference between them. If there is a big difference between their
performance, then you should study the root cause.
Note: The information presented in the AWR was brought from the view DBA_HIST_SQLSTAT. Refer to
the concepts lecture to obtain a query that retrieves that same information about the query from that
view.
Clean up
Summary
• Using the AWR SQL reports, we can retrieve the history of a specific SQL statement
performance.