1. Trang chủ
  2. » Công Nghệ Thông Tin

OCA /OCP Oracle Database 11g A ll-in-One Exam Guide- P96 doc

10 92 0
Tài liệu đã được kiểm tra trùng lặp

Đang tải... (xem toàn văn)

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Tiêu đề Oca/Ocp Oracle Database 11g All-in-One Exam Guide
Trường học Oracle University
Chuyên ngành Database Management
Thể loại guide
Định dạng
Số trang 10
Dung lượng 707,06 KB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

Clicking the SQL Tuning Advisor task name or selecting the radio button next to the task and clicking VIEW RESULT, you see the results of the analysis in Figure 25-8.. Figure 25-7 Adviso

Trang 1

Clicking the SQL Tuning Advisor task name or selecting the radio button next to the task and clicking VIEW RESULT, you see the results of the analysis in Figure 25-8 Note that the results include recommendations for user SQL (e.g., RJB) and for system accounts (e.g., SYSMAN and DBSNMP) Each SQL statement has one or more types of recommendation, including statistics gathering, creating a SQL Profile, creating an index, or revising the SQL statement itself You can implement the SQL Profile recommendation by clicking IMPLEMENT ALL PROFILES

Figure 25-7 Advisor Central task results

Trang 2

Selecting the radio button for the fourth SQL statement in Figure 25-8, you can see

a detailed explanation of all recommendations for this SQL statement in Figure 25-9

In Figure 25-9, you are advised to implement one of the recommendations, such

as saving a SQL Profile for future executions or creating an index on one of the tables

in the SQL query

Figure 25-8 SQL Tuning Advisor recommendations summary

Trang 3

The SQL Tuning Advisor API:

the DBMS_SQLTUNE Package

If you need to have more control over your tuning tasks or want to run a specific set

of tuning tasks repeatedly, you can use the DBMS_SQLTUNE PL/SQL package to create, run, and monitor a SQL Tuning Advisor job

For a basic analysis of a SQL statement, you will use the following procedures within DBMS_SQLTUNE:

• CREATE_TUNING_TASK Create a tuning task for a SQL statement or a SQL

Tuning Set

• EXECUTE_TUNING_TASK Execute a tuning task created with CREATE_

TUNING_TASK.

• REPORT_TUNING_TASK Show the results and recommendations from the

SQL Tuning Advisor

In addition, you can use the following data dictionary views to query the name and status of tuning jobs:

• DBA_ADVISOR_LOG Task names, status, and execution statistics for all tasks

Figure 25-9 SQL Tuning Advisor detailed recommendations

Trang 4

• DBA_/USER_ADVISOR_TASKS More detailed information about advisor

tasks, such as advisor name, user-specified description, and execution type for

the current user

• V$ADVISOR_PROGRESS More detailed information about the completion

status and time remaining for an advisor task

Exercise 25-3: Run the SQL Tuning Advisor for a SQL Statement In this

exercise, you will use DBMS_SQLTUNE to generate recommendations for one of the

SQL statements in Figure 25-8

1 Connect to the database with SQL*Plus as user SYSTEM, and create the table

to be used in this exercise:

create table object_analysis as select * from all_objects;

2 These commands, executed at the SQL prompt, will create a variable to store the

name of the task, create a task to tune one statement, and then run the task:

variable vtask varchar2(100);

execute :vtask :=

dbms_sqltune.create_tuning_task(-sql_text=>'select distinct object_id from object_analysis');

execute dbms_sqltune.execute_tuning_task(:vtask);

3 Retrieve the recommendations from the tuning task, first setting up SQL*Plus

to display them:

set long 10000

set longchunksize 10000

select dbms_sqltune.report_tuning_task(:vtask) from dual;

The illustration shows Steps 2 and 3

4 Study the output of the tuning task, as retrieved in Step 3 Following the detail

of the task, there will be a recommendation to gather statistics on the table,

and an example of a procedure call to do this

5 Tidy up:

Trang 5

views, and partitioning There is a graphical interface through Enterprise Manager, and

a PL/SQL API

Using the SQL Access Advisor with Database Control

The four steps to create a set of recommendations are as follows:

1 Create a task

2 Define the workload

3 Generate the recommendations

4 Review and implement the recommendations

From the SQL Advisors window in Figure 25-2, click the SQL Access Advisor link You will see the page shown in Figure 25-10, where you can perform one of two tasks: verify that existing structures such as indexes and materialized views are being used,

or recommend new structures

Figure 25-10 SQL Access Advisor options

Trang 6

For this example, you want to find new access structures, so you select the second

radio button If you select the Inherit Options check box, you can choose a template

that may fit your environment, such as OLTP or data warehousing When you click

CONTINUE, you will see the first step of the wizard as in Figure 25-11

For the source of the tuning activity, you can select one of three sources: recent SQL

from the cache, an existing SQL Tuning Set (such as the SQL Tuning Set created in the

SQL Tuning Advisor example earlier in this chapter), or a generated workload based

on the type of queries that appear likely given the structure of the objects in one or

more schemas In this example, we want to analyze all current and recent SQL activity

Therefore click the corresponding radio button and then click NEXT

The next page, in Figure 25-12, lets you select which types of access structures that the

SQL Access Advisor should recommend: indexes, materialized views, and partitioning In

addition, you can direct the SQL Access Advisor to perform a limited analysis on just

the high-cost statements—or perform a relatively time-consuming analysis on all

relationships between the tables in the specified workload The Advanced Options

section lets you further refine the analysis based on disk space limitations as well as

specify alternate locations for recommended indexes and materialized views Select

the Indexes and Materialized Views check boxes and select the Comprehensive radio

button Finally, click NEXT

The next page, in Figure 25-13, specifies the scheduling options for the tuning task

As you can see, Enterprise Manager (EM) will automatically create the task for you

Figure 25-11 Specify SQL Access Advisor workload source

Trang 7

Figure 25-12 Specifying SQL Access Advisor recommendation options

Figure 25-13 Specifying SQL Access Advisor scheduling options

Trang 8

Other options on this page include how much logging the SQL Access Advisor generates,

how long the task will remain in the database, the total time allotted to this task, and

when to start the task

In Figure 25-13, accept the default options and click NEXT to proceed to Step 4 of

the wizard, as you can see in Figure 25-14 Step 4 summarizes the options you have

chosen and gives you a chance to revise the options before submitting the job

Note the SHOW SQL button in Figure 25-14 This will show the API calls being

generated by the wizard This is a useful source of code for scripted tuning jobs

that can be incorporated into a batch job, which includes other SQL commands

or processes that you cannot easily perform repeatedly within EM

Click the SUBMIT button shown in Figure 25-14 to start the analysis From the Advisor

Central page, you can monitor the progress of the job When the job completes, select

the job and click VIEW RESULT The page in Figure 25-15 shows a summary of the

improvements you can make if you implement the recommendations in the second

tab The SQL Statements tab shows you the statements analyzed and gives you the

option to implement the recommendations The Details tab recaps the options you

chose to run this analysis In this particular analysis, almost half of the recent SQL

statements may benefit dramatically if the recommendations are implemented

Using the SQL Access Advisor with DBMS_ADVISOR

Using the SQL Access Advisor via the DBMS_ADVISOR package can get quite

complex Using Enterprise Manager is an easier way to run most day-to-day analyses

There is, however, one procedure designed to make the job easy DBMS_ADVISOR

Figure 25-14 Reviewing SQL Access Advisor options

Trang 9

QUICK_TUNE is straightforward and takes as input a single SQL statement to tune As

a result, it performs much like the SQL Tuning Advisor but can perform a much more in-depth analysis, producing more recommendations than the SQL Tuning Advisor, such as materialized view recommendations The procedure requires (as a minimum) three arguments: the name of the advisor, the name of the task to be run, and the statement For example:

SQL> execute

3

4

5 'select distinct object_id from

6

7 /

PL/SQL procedure successfully completed.

SQL>

The results of the tuning effort reside in the data dictionary view USER_ADVISOR_ ACTIONS, but the output is not very readable Therefore, you can use the procedure CREATE_FILE to create the script you can use to implement the recommendations

Figure 25-15 SQL Access Advisor recommendation summary

Trang 10

generated by the QUICK_TUNE procedure First, create a directory object to point to

a file system directory to hold the script:

SQL> create directory tune_scripts as '/u06/tune_scripts';

Directory created.

SQL>

Next, use CREATE_FILE to create the script containing the implementation

recommendations:

SQL> begin

2 dbms_advisor.create_file

3 (dbms_advisor.get_task_script('task1'),

4 'TUNE_SCRIPTS',

5 'tune_fts.sql'

6 );

7 end;

8 /

PL/SQL procedure successfully completed.

SQL>

In this example, the file tune_fts.sql looks like this:

Rem SQL Access Advisor: Version 11.1.0.6.0 – Production

Rem

Rem Username: JON

Rem Task: task1

Rem Execution date:

Rem

CREATE MATERIALIZED VIEW LOG ON

"JON"."OBJECT_ANALYSIS"

WITH ROWID, SEQUENCE("OBJECT_ID")

INCLUDING NEW VALUES;

CREATE MATERIALIZED VIEW "JON"."MV$$_0BDC0000"

REFRESH FAST WITH ROWID

ENABLE QUERY REWRITE

AS SELECT JON.OBJECT_ANALYSIS.OBJECT_ID C1, COUNT(*) M1

FROM JON.OBJECT_ANALYSIS

GROUP BY JON.OBJECT_ANALYSIS.OBJECT_ID;

begin

dbms_stats.gather_table_stats

('"JON"','"MV$$_0BDC0000"',NULL,dbms_stats.auto_sample_size);

end;

/

The recommendations include creating a materialized view log, creating a

materialized view that can be used for query rewrite, and collecting statistics on

the materialized view

Ngày đăng: 06/07/2014, 13:20