Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
23 views

Practice 6 - Using AWR SQL Reports

1) The document describes using Automatic Workload Repository (AWR) SQL reports to analyze the performance of a SQL statement that was executed with different execution plans. 2) The practice involves running a query against a table with and without an index, capturing AWR snapshots, and generating an AWR SQL report to compare the performance of the full table scan versus index scan plans. 3) The report shows that the index scan plan was more efficient than the full table scan, highlighting the usefulness of AWR in analyzing SQL performance over time.

Uploaded by

Abdo Mohamed
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views

Practice 6 - Using AWR SQL Reports

1) The document describes using Automatic Workload Repository (AWR) SQL reports to analyze the performance of a SQL statement that was executed with different execution plans. 2) The practice involves running a query against a table with and without an index, capturing AWR snapshots, and generating an AWR SQL report to compare the performance of the full table scan versus index scan plans. 3) The report shows that the index scan plan was more efficient than the full table scan, highlighting the usefulness of AWR in analyzing SQL performance over time.

Uploaded by

Abdo Mohamed
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Practice 6 - Using AWR SQL Reports P a g e |1

Practice 6

Using AWR SQL Reports

Practice Target
In this practice, you will produce an AWR SQL report to list performance statistics and execution plans
history of a specific statement.

Oracle Database Performance Tuning, a course by Ahmed Baraka


Practice 6 - Using AWR SQL Reports P a g e |2

Preparing for the Practice


In this section of the practice, you will perform actions to prepare your environment for this practice.

1. Make sure srv1 is started. If it is not, start it up.

2. Start Putty, login to srv1 as oracle

3. Create the following shell script file, named as run_query.sh

The script runs multiple SQL*Plus sessions at the same time. Each session executes the script
run_query.sql

cat > run_query.sh <<EOL


#!/bin/bash

counter=1
while [ \$counter -le \$1 ]
do
exit | sqlplus -L -S soe/soe @ run_query.sql &
((counter++))
done
EOL

chmod +x run_query.sh

4. Create the following SQL*Plus script file, named as run_query.sql

The script runs a single query.


cat > run_query.sql <<EOL
SELECT ORDER_ID, ORDER_TOTAL FROM ORDERS2 WHERE ORDER_ID <=15000;
EOL

Oracle Database Performance Tuning, a course by Ahmed Baraka


Practice 6 - Using AWR SQL Reports P a g e |3

Producing SQL AWR Report


In this section of the practice, you will produce a SQL AWR report for a specific statement. The
statement was executed using multiple execution plans.

5. Invoke SQL*Plus and login to the database as soe

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;

7. Create an AWR snapshot.


conn / as sysdba
exec DBMS_WORKLOAD_REPOSITORY.CREATE_SNAPSHOT(FLUSH_LEVEL=>'ALL')

8. Exit from SQL*Plus.


EXIT

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

10. Create an AWR snapshot.


sqlplus / as sysdba
exec DBMS_WORKLOAD_REPOSITORY.CREATE_SNAPSHOT(FLUSH_LEVEL=>'ALL')

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

Oracle Database Performance Tuning, a course by Ahmed Baraka


Practice 6 - Using AWR SQL Reports P a g e |4

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%';

14. Create an AWR snapshot.


exec DBMS_WORKLOAD_REPOSITORY.CREATE_SNAPSHOT(FLUSH_LEVEL=>'ALL')

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

16. Move the generated file to the staging folder.


host mv awr_sql.html /media/sf_extdisk

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

18. Drop the created table.


conn soe/soe
DROP TABLE ORDERS2 PURGE;

19. Delete the created script files.


host rm run_query.*

Oracle Database Performance Tuning, a course by Ahmed Baraka


Practice 6 - Using AWR SQL Reports P a g e |5

Summary
• Using the AWR SQL reports, we can retrieve the history of a specific SQL statement
performance.

Oracle Database Performance Tuning, a course by Ahmed Baraka

You might also like