PL/SQL Packages and Types Reference 10g Release 1 (10.1) Part Number B10802-01 |
|
|
View PDF |
DBMS_ADVISOR
is part of the Server Manageability suite of Advisors, a set of expert systems that identifies and helps resolve performance problems relating to the various database server components.
See Also:
|
This chapter contains the following topics:
Security on this package can be controlled by granting EXECUTE
on this package to selected users or roles. You might want to write a cover package on top of this one that restricts the alert names used. EXECUTE
privilege on this cover package can then be granted rather than on this package. In addition, there is an ADVISOR
privilege, which is required by DBMS_ADVISOR
procedures.
Table 12-1 lists DBMS_ADVISOR
procedures that are used in all Advisors.
Table 12-2 lists DBMS_ADVISOR
procedures that are used in the SQLAccess Advisor.
The Oracle Database includes a number of advisors for different subsystems in the database to automatically determine how the operation of the corresponding subcomponents could be further optimized. The SQL Tuning and SQLAccess Advisor, for example, provide recommendations for running SQL statements faster. Memory advisors help size the various memory components without resorting to trial-and-error techniques. The Segment Advisor handles all space-related issues, such as recommending wasted-space reclamation, predicting the sizes of new tables and indexes, and analyzing growth trends, and the Undo Advisor lets you size the undo tablespace. You should see the specific documentation for each Advisor for details regarding how parameters are used.
This section includes:
The generic Advisor parameters are the following:
DAYS_TO_EXPIRE
END_SNAPSHOT
END_TIME
INSTANCE
JOURNALING
MODE
START_SNAPSHOT
START_TIME
TARGET_OBJECTS
TIME_LIMIT
See your Advisor-specific documentation for further information.
Table 12-3 lists SQLAccess Advisor task parameters.
Table 12-4 lists SQLAccess Advisor object parameters.
Table 12-5 lists the input task parameters that can be set in the Segment Advisor using the SET_TASK_PARAMETER
procedure.
This procedure establishes a link between the current SQLAccess Advisor task and a SQL Workload object. The link allows an advisor task to access interesting data for doing an analysis. The link also provides a stable view of the data. Once a connection between a SQLAccess Advisor task and a SQL Workload object is made, the workload is protected from removal or modification.
DBMS_ADVISOR.ADD_SQLWKLD_REF ( task_name IN VARCHAR2, workload_name IN VARCHAR2);
DECLARE task_id NUMBER; task_name VARCHAR2(30); workload_name VARCHAR2(30); BEGIN task_name := 'My Task'; workload_name := 'My Workload'; DBMS_ADVISOR.CREATE_TASK(DBMS_ADVISOR.SQLACCESS_ADVISOR, task_id, task_name); DBMS_ADVISOR.CREATE_SQLWKLD(workload_name, 'My Workload'); DBMS_ADVISOR.ADD_SQLWKLD_REF(task_name, workload_name); END; /
This procedure adds a single statement to the specified workload.
DBMS_ADVISOR.ADD_SQLWKLD_STATEMENT ( workload_name IN VARCHAR2, module IN VARCHAR2, action IN VARCHAR2, cpu_time IN NUMBER := 0, elapsed_time IN NUMBER := 0, disk_reads IN NUMBER := 0, buffer_gets IN NUMBER := 0, rows_processed IN NUMBER := 0, optimizer_cost IN NUMBER := 0, executions IN NUMBER := 1, priority IN NUMBER := 2, last_execution_date IN DATE := 'SYSDATE', stat_period IN NUMBER := 0, username IN VARCHAR2, sql_text IN CLOB);
A workload cannot be modified or deleted if it is currently referenced by an active task. A task is considered active if it is not in its initial state. See "RESET_TASK Procedure" for directions on setting a task to its initial state.
DECLARE workload_name VARCHAR2(30); BEGIN workload_name := 'My Workload'; DBMS_ADVISOR.CREATE_SQLWKLD(workload_name, 'My Workload'); DBMS_ADVISOR.ADD_SQLWKLD_STATEMENT(workload_name, 'MONTHLY', 'ROLLUP', 100,400,5041,103,640445,680000,2, 1,SYSDATE,1,'SH','SELECT avg(amount_sold) FROM sh.sales'); END; /
This procedure causes a currently executing operation to terminate. This call does a soft interrupt. It will not break into a low-level database access call like a hard interrupt such as Ctrl-C. The SQLAccess Advisor periodically checks for soft interrupts and acts appropriately. As a result, this operation may take a few seconds to respond to a call.
DBMS_ADVISOR.CANCEL_TASK ( task_name IN VARCHAR2);
Parameter | Description |
---|---|
|
A valid Advisor task name that uniquely identifies an existing task. |
A cancel command effective restores the task to its condition prior to the start of the cancelled operation. Therefore, a cancelled task or data object cannot be resumed.
Because all Advisor task procedures are synchronous, to cancel an operation, you must use a separate database session.
DECLARE task_id NUMBER; task_name VARCHAR2(30); workload_name VARCHAR2(30); BEGIN task_name := 'My Task'; workload_name := 'My Workload'; DBMS_ADVISOR.CREATE_TASK(DBMS_ADVISOR.SQLACCESS_ADVISOR, task_id, task_name); DBMS_ADVISOR.CANCEL_TASK('My Task'); END; /
This procedure creates an external file from a PL/SQL CLOB variable, which is used for creating scripts and reports. CREATE_FILE
accepts a CLOB input parameter and writes the character string contents to the specified file.
DBMS_ADVISOR.CREATE_FILE ( buffer IN CLOB, location IN VARCHAR2, filename IN VARCHAR2);
All formatting must be embedded within the CLOB.
The Oracle server restricts file access within Oracle Stored Procedures. This means that file locations and names must adhere to the known file permissions in the server.
CREATE DIRECTORY MY_DIR as '/homedir/user4/gssmith'; GRANT READ,WRITE ON DIRECTORY MY_DIR TO PUBLIC; DECLARE task_id NUMBER; task_name VARCHAR2(30); workload_name VARCHAR2(30); BEGIN task_name := 'My Task'; workload_name := 'My Workload'; DBMS_ADVISOR.CREATE_TASK(DBMS_ADVISOR.SQLACCESS_ADVISOR, task_id, task_name); DBMS_ADVISOR.CREATE_SQLWKLD(workload_name, 'My Workload'); DBMS_ADVISOR.ADD_SQLWKLD_REF(task_name, workload_name); DBMS_ADVISOR.ADD_SQLWKLD_STATEMENT(workload_name, 'MONTHLY', 'ROLLUP', 100,400,5041,103,640445,680000,2, 1,SYSDATE,1,'SH','SELECT avg(amount_sold) FROM sh.sales'); DBMS_ADVISOR.EXECUTE_TASK(task_name); DBMS_ADVISOR.CREATE_FILE(DBMS_ADVISOR.GET_TASK_SCRIPT(task_name), 'MY_DIR','script.sql'); END; /
This procedure creates a new task object.
DBMS_ADVISOR.CREATE_TASK ( task_name IN VARCHAR2, object_type IN VARCHAR2, attr1 IN VARCHAR2 := NULL, attr2 IN VARCHAR2 := NULL, attr3 IN VARCHAR2 := NULL, attr4 IN CLOB := NULL, attr5 IN VARCHAR2 := NULL, object_id OUT NUMBER);
The attribute parameters have different values depending upon the object type. See Oracle Database Administrator's Guide for details regarding these parameters and object types.
Returns the new object identifier.
Task objects are typically used as input data for a particular advisor. Segment advice can be generated at the object, segment, or tablespace level. If for the object level, advice is generated on all partitions of the object (if the object is partitioned). The advice is not cascaded to any dependent objects. If for the segment level, advice can be obtained on a single segment, such as the partition or subpartition of a table, index, or lob column. If for a tablespace level, target advice for every segment in the tablespace will be generated.
See Oracle Database Administrator's Guide for further information regarding the Segment Advisor.
DECLARE task_id NUMBER; task_name VARCHAR2(30); obj_id NUMBER; BEGIN task_name := 'My Task'; DBMS_ADVISOR.CREATE_TASK(DBMS_ADVISOR.SQLACCESS_ADVISOR, task_id, task_name); DBMS_ADVISOR.CREATE_OBJECT (task_name,'SQL',NULL,NULL,NULL, 'SELECT * FROM SH.SALES',obj_id); END; /
This procedure creates a new private SQL Workload object for the user. A SQL Workload object manages a SQL workload on behalf of the SQLAccess Advisor. A SQL Workload object must exist prior to performing any other SQL Workload operations, such as importing or updating SQL statements.
DBMS_ADVISOR.CREATE_SQLWKLD ( workload_name IN VARCHAR2, description IN VARCHAR2 := NULL, template IN VARCHAR2 := NULL, is_template IN VARCHAR2 := 'FALSE');
The SQLAccess Advisor returns a unique workload object identifier number that must be used for subsequent activities within the new SQL Workload object.
By default, workload objects are created using built-in default settings. To create a workload using the parameter settings of an existing workload or workload template, the user may specify an existing workload name.
Once a SQL Workload object is present, it can then be referenced by one or more SQLAccess Advisor tasks using the ADD_SQLWKLD_REF
procedure.
DECLARE workload_name VARCHAR2(30); BEGIN workload_name := 'My Workload'; DBMS_ADVISOR.CREATE_SQLWKLD(workload_name, 'My Workload'); END; /
This procedure creates a new Advisor task in the repository.
DBMS_ADVISOR.CREATE_TASK ( advisor_name IN VARCHAR2 NOT NULL, task_name IN VARCHAR2, task_desc IN VARCHAR2 := NULL, task_or_template IN VARCHAR2 := NULL, is_template IN VARCHAR2 := 'FALSE'); DBMS_ADVISOR.CREATE_TASK ( advisor_name IN VARCHAR2 NOT NULL, task_id OUT NUMBER, task_name IN OUT VARCHAR2, task_desc IN VARCHAR2 := NULL, task_or_template IN VARCHAR2 := NULL, is_template IN VARCHAR2 := 'FALSE');
Returns a unique task ID number and a unique task name if one is not specified.
A task must be associated with an advisor, and once the task has been created, it is permanently associated with the original advisor. By default, tasks are created using built-in default settings. To create a task using the parameter settings of an existing task or task template, the user may specify an existing task name.
For the SQLAccess Advisor, use the identifier DBMS_ADVISOR.SQLACCESS_ADVISOR
as the advisor_name
.
The SQLAccess Advisor provides three built-in task templates, using the following constants:
DBMS_ADVISOR.SQLACCESS_OLTP
Parameters are preset to favor an OLTP application environment.
DBMS_ADVISOR.SQLACCESS_WAREHOUSE
Parameters are preset to favor a data warehouse application environment.
DBMS_ADVISOR.SQLACCESS_GENERAL
Parameters are preset to favor a hybrid application environment where both OLTP and data warehouse operations may occur. For the SQLAccess Advisor, this is the default template.
DECLARE task_id NUMBER; task_name VARCHAR2(30); BEGIN task_name := 'My Task'; DBMS_ADVISOR.CREATE_TASK(DBMS_ADVISOR.SQLACCESS_ADVISOR, task_id, task_name); END; /
This procedure deletes an existing SQL Workload object from the repository.
DBMS_ADVISOR.DELETE_SQLWKLD ( workload_name IN VARCHAR2);
A workload cannot be modified or deleted if it is currently referenced by an active task. A task is considered active if it is not in its initial state. See the "RESET_TASK Procedure" to set a task to its initial state.
DECLARE workload_name VARCHAR2(30); BEGIN workload_name := 'My Workload'; DBMS_ADVISOR.CREATE_SQLWKLD(workload_name, 'My Workload'); DBMS_ADVISOR.DELETE_SQLWKLD(workload_name); END; /
This procedure removes a link between the current SQLAccess task and a SQL Workload data object.
DBMS_ADVISOR.DELETE_SQLWKLD_REF ( task_name IN VARCHAR2, workload_name IN NUMBER);
DECLARE task_id NUMBER; task_name VARCHAR2(30); workload_name VARCHAR2(30); BEGIN task_name := 'My Task'; workload_name := 'My Workload'; DBMS_ADVISOR.CREATE_TASK(DBMS_ADVISOR.SQLACCESS_ADVISOR, task_id, task_name); DBMS_ADVISOR.CREATE_SQLWKLD(workload_name, 'My Workload'); DBMS_ADVISOR.ADD_SQLWKLD_REF(task_name, workload_name); DBMS_ADVISOR.ADD_SQLWKLD_STATEMENT(workload_name, 'MONTHLY', 'ROLLUP', 100,400,5041,103,640445,680000,2, 1,SYSDATE,1,'SH','SELECT avg(amount_sold) FROM sh.sales'); DBMS_ADVISOR.DELETE_SQLWKLD_REF(task_name, workload_name); END; /
This procedure deletes one or more statements from a workload.
DBMS_ADVISOR.DELETE_SQLWKLD_STATEMENT ( workload_name IN VARCHAR2, sql_id IN VARCHAR2); DBMS_ADVISOR.DELETE_SQLWKLD_STATEMENT ( workload_name IN VARCHAR2, search IN VARCHAR2, deleted OUT NUMBER);
A workload cannot be modified or deleted if it is currently referenced by an active task. A task is considered active if it is not in its initial state. See the "RESET_TASK Procedure" to set a task to its initial state.
DECLARE workload_name VARCHAR2(30); deleted NUMBER; id NUMBER; BEGIN workload_name := 'My Workload'; DBMS_ADVISOR.CREATE_SQLWKLD(workload_name, 'My Workload'); DBMS_ADVISOR.ADD_SQLWKLD_STATEMENT(workload_name, 'MONTHLY', 'ROLLUP', 100,400,5041,103,640445,680000,2, 1,SYSDATE,1,'SH','SELECT avg(amount_sold) FROM sh.sales'); DBMS_ADVISOR.ADD_SQLWKLD_STATEMENT(workload_name, 'YEARLY', 'ROLLUP', 100,400,5041,103,640445,680000,2, 1,SYSDATE,1,'SH','SELECT avg(amount_sold) FROM sh.sales'); DBMS_ADVISOR.DELETE_SQLWKLD_STATEMENT(workload_name,'module = ''MONTHLY''',deleted); SELECT min(sql_id) INTO id FROM USER_ADVISOR_SQLW_STMTS WHERE workload_name = 'My Workload'; DBMS_ADVISOR.DELETE_SQLWKLD_STATEMENT(workload_name, id); END; /
This procedure deletes an existing task from the repository.
DBMS_ADVISOR.DELETE_TASK ( task_name IN VARCHAR2);
DECLARE task_id NUMBER; task_name VARCHAR2(30); BEGIN task_name := 'My Task'; DBMS_ADVISOR.CREATE_TASK(DBMS_ADVISOR.SQLACCESS_ADVISOR, task_id, task_name); DBMS_ADVISOR.DELETE_TASK(task_name); END; /
This procedure performs the Advisor analysis or evaluation for the specified task.
DBMS_ADVISOR.EXECUTE_TASK ( task_name IN VARCHAR2);
Parameter | Description |
---|---|
|
The task name that uniquely identifies an existing task. |
Task execution is a synchronous operation. Control will not be returned to the caller until the operation has completed, or a user-interrupt was detected.
Upon return, you can check the DBA_ADVISOR_LOG
table for the execution status.
DECLARE task_id NUMBER; task_name VARCHAR2(30); workload_name VARCHAR2(30); BEGIN task_name := 'My Task'; workload_name := 'My Workload'; DBMS_ADVISOR.CREATE_TASK(DBMS_ADVISOR.SQLACCESS_ADVISOR, task_id, task_name); DBMS_ADVISOR.CREATE_SQLWKLD(workload_name, 'My Workload'); DBMS_ADVISOR.ADD_SQLWKLD_REF(task_name, workload_name); DBMS_ADVISOR.ADD_SQLWKLD_STATEMENT(workload_name, 'MONTHLY', 'ROLLUP', 100,400,5041,103,640445,680000,2, 1,SYSDATE,1,'SH','SELECT avg(amount_sold) FROM sh.sales'); DBMS_ADVISOR.EXECUTE_TASK(task_name); END; /
This procedure retrieves a specified attribute of a new object as recommended by Advisor analysis.
DBMS_ADVISOR.GET_REC_ATTRIBUTES ( workload_name IN VARCHAR2, rec_id IN NUMBER, action_id IN NUMBER, attribute_name IN VARCHAR2, value OUT VARCHAR2);
The requested attribute value is returned in the VALUE
argument.
This will name and assign ownership to new objects such as indexes and materialized views during the analysis operation. However, it will not necessarily choose appropriate names, so you can manually set the owner, name and tablespace values for new objects.
DECLARE task_id NUMBER; task_name VARCHAR2(30); workload_name VARCHAR2(30); attribute VARCHAR2(100); BEGIN task_name := 'My Task'; workload_name := 'My Workload'; DBMS_ADVISOR.CREATE_TASK(DBMS_ADVISOR.SQLACCESS_ADVISOR, task_id, task_name); DBMS_ADVISOR.CREATE_SQLWKLD(workload_name, 'My Workload'); DBMS_ADVISOR.ADD_SQLWKLD_REF(task_name, workload_name); DBMS_ADVISOR.ADD_SQLWKLD_STATEMENT(workload_name, 'MONTHLY', 'ROLLUP', 100,400,5041,103,640445,680000,2, 1,SYSDATE,1,'SH','SELECT avg(amount_sold) FROM sh.sales WHERE promo_id = 10'); DBMS_ADVISOR.EXECUTE_TASK(task_name); DBMS_ADVISOR.GET_REC_ATTRIBUTES(task_name, 1, 1, 'NAME', attribute); END; /
This procedure creates and returns an XML report for the specified task.
DBMS_ADVISOR.GET_TASK_REPORT ( task_name IN VARCHAR2, type IN VARCHAR2 := 'TEXT', level IN VARCHAR2 := 'TYPICAL', section IN VARCHAR2 := 'ALL', owner_name IN VARCHAR2 := NULL) RETURN CLOB;
Returns the buffer receiving the script.
This procedure creates a SQL*Plus-compatible SQL script and sends the output to file. The script will contain all of the accepted recommendations from the specified task.
DBMS_ADVISOR.GET_TASK_SCRIPT ( task_name IN VARCHAR2 type IN VARCHAR2 := 'IMPLEMENTATION', rec_id IN NUMBER := NULL, action_id IN NUMBER := NULL) RETURN CLOB;
Returns the script as a CLOB buffer.
Though the script is ready to execute, Oracle recommends that the user review the script for acceptable locations for new materialized views and indexes.
For a recommendation to appear in a generated script, it must be marked as accepted.
DECLARE task_id NUMBER; task_name VARCHAR2(30); workload_name VARCHAR2(30); buf CLOB; BEGIN task_name := 'My Task'; workload_name := 'My Workload'; DBMS_ADVISOR.CREATE_TASK(DBMS_ADVISOR.SQLACCESS_ADVISOR, task_id, task_name); DBMS_ADVISOR.CREATE_SQLWKLD(workload_name, 'My Workload'); DBMS_ADVISOR.ADD_SQLWKLD_REF(task_name, workload_name); DBMS_ADVISOR.ADD_SQLWKLD_STATEMENT(workload_name, 'MONTHLY', 'ROLLUP', 100,400,5041,103,640445,680000,2, 1,SYSDATE,1,'SH','SELECT avg(amount_sold) FROM sh.sales'); DBMS_ADVISOR.EXECUTE_TASK(task_name); buf := DBMS_ADVISOR.GET_TASK_SCRIPT(task_name); END; /
This procedure constructs and loads a SQL workload based on schema evidence. The workload is also referred to as a hypothetical workload.
DBMS_ADVISOR.IMPORT_SQLWKLD_SCHEMA ( workload_name IN VARCHAR2, import_mode IN VARCHAR2, priority NUMBER := 2, saved_rows OUT NUMBER, failed_rows OUT NUMBER);
This call returns the number of rows processed and the number of rows saved and failed as output parameters.
To successfully import a hypothetical workload, the target schemas must contain dimension or primary/foreign key information.
If the VALID_TABLE_LIST
parameter is not set, the search space may become very large and require a significant amount of time to complete. Oracle recommends that you limit your search space to specific set of tables.
If a task contains valid recommendations from a prior run, adding or modifying task will mark the task as invalid, preventing the viewing and reporting of potentially valuable recommendation data.
DECLARE workload_name VARCHAR2(30); saved NUMBER; failed NUMBER; BEGIN workload_name := 'My Workload'; DBMS_ADVISOR.CREATE_SQLWKLD(workload_name, 'My Workload'); DBMS_ADVISOR.SET_SQLWKLD_PARAMETER(workload_name,'VALID_TABLE_LIST','SH.%'); DBMS_ADVISOR.IMPORT_SQLWKLD_SCHEMA(workload_name, 'REPLACE', 1, saved, failed); END; /
This procedure creates a SQL workload from the current contents of the server's SQL cache.
DBMS_ADVISOR.IMPORT_SQLWKLD_SQLCACHE ( workload_name IN VARCHAR2, import_mode IN VARCHAR2, priority IN NUMBER := 2, saved_rows OUT NUMBER, failed_rows OUT NUMBER);
This call returns the number of rows processed and the number of rows saved and failed as output parameters.
A workload cannot be modified or deleted if it is currently referenced by an active task. A task is considered active if it is not in its initial state. See "RESET_TASK Procedure" to set a task to its initial state.
DECLARE workload_name VARCHAR2(30); saved NUMBER; failed NUMBER; BEGIN workload_name := 'My Workload'; DBMS_ADVISOR.CREATE_SQLWKLD(workload_name, 'My Workload'); DBMS_ADVISOR.SET_SQLWKLD_PARAMETER(workload_name,'VALID_TABLE_LIST','SH.%'); DBMS_ADVISOR.IMPORT_SQLWKLD_SQLCACHE(workload_name, 'REPLACE', 1, saved, failed); END; /
This procedure loads a SQL workload from an existing SQL Tuning Set. A SQL Tuning Set is typically created from the server workload repository using various time and data filters.
DBMS_ADVISOR.IMPORT_SQLWKLD_STS ( workload_name IN VARCHAR2, sqlset_name IN VARCHAR2, import_mode IN VARCHAR2, priority IN NUMBER := 2, saved_rows OUT NUMBER, failed_rows OUT NUMBER);
This call returns the number of rows processed and the number of rows saved and failed as output parameters.
A workload cannot be modified or deleted if it is currently referenced by an active task. A task is considered active if it is not in its initial state. See "RESET_TASK Procedure" to set a task to its initial state.
DECLARE workload_name VARCHAR2(30); saved NUMBER; failed NUMBER; BEGIN workload_name := 'My Workload'; DBMS_ADVISOR.CREATE_SQLWKLD(workload_name, 'My Workload'); DBMS_ADVISOR.SET_SQLWKLD_PARAMETER(workload_name,'VALID_TABLE_LIST','SH.%'); DBMS_ADVISOR.IMPORT_SQLWKLD_STS(workload_name, 'MY_SQLSET', 'REPLACE', 1, saved, failed); END; /
This procedure collects a SQL workload from a Summary Advisor workload. This procedure is intended to assist 9i Summary Advisor users in the migration to SQLAccess Advisor.
DBMS_ADVISOR.IMPORT_SQLWKLD_SUMADV ( workload_name IN VARCHAR2, import_mode IN VARCHAR2, priority IN NUMBER := 2, sumadv_id IN NUMBER, saved_rows OUT NUMBER, failed_rows OUT NUMBER);
This call returns the number of rows processed and the number of rows saved and failed as output parameters.
A workload cannot be modified or deleted if it is currently referenced by an active task. A task is considered active if it is not in its initial state. See "RESET_TASK Procedure" to set a task to its initial state.
DECLARE workload_name VARCHAR2(30); saved NUMBER; failed NUMBER; sumadv_id NUMBER; BEGIN workload_name := 'My Workload'; sumadv_id := 394; DBMS_ADVISOR.CREATE_SQLWKLD(workload_name, 'My Workload'); DBMS_ADVISOR.SET_SQLWKLD_PARAMETER(workload_name,'VALID_TABLE_LIST','SH.%'); DBMS_ADVISOR.IMPORT_SQLWKLD_SUMADV(workload_name, 'REPLACE', 1, sumadv_id, saved, failed); END; /
This procedure collects a SQL workload from a specified user table.
DBMS_ADVISOR.IMPORT_SQLWKLD_USER ( workload_name IN VARCHAR2, import_mode IN VARCHAR2, owner IN VARCHAR2, table IN VARCHAR2, saved_rows OUT NUMBER, failed_rows OUT NUMBER);
This call returns the number of rows processed and the number of rows saved and failed as output parameters.
A workload cannot be modified or deleted if it is currently referenced by an active task. A task is considered active if it is not in its initial state. See "RESET_TASK Procedure" to set a task to its initial state.
DECLARE workload_name VARCHAR2(30); saved NUMBER; failed NUMBER; BEGIN workload_name := 'My Workload'; DBMS_ADVISOR.CREATE_SQLWKLD(workload_name, 'My Workload'); DBMS_ADVISOR.SET_SQLWKLD_PARAMETER(workload_name,'VALID_TABLE_LIST','SH.%'); DBMS_ADVISOR.IMPORT_SQLWKLD_USER(workload_name, 'REPLACE', 'SH', 'USER_WORKLOAD', saved, failed); END; /
This procedure stops a currently executing task. The task will end its operations as it would at a normal exit. The user will be able to access any recommendations that exist to this point.
DBMS_ADVISOR.INTERRUPT_TASK ( task_name IN VARCHAR2);
Parameter | Description |
---|---|
|
A single Advisor task name that will be interrupted. |
DECLARE task_id NUMBER; task_name VARCHAR2(30); BEGIN task_name := 'My Task'; DBMS_ADVISOR.CREATE_TASK(DBMS_ADVISOR.SQLACCESS_ADVISOR, task_id, task_name); DBMS_ADVISOR.INTERRUPT_TASK('My Task'); END; /
This procedure marks a recommendation for import or implementation.
DBMS_ADVISOR.MARK_RECOMMENDATION ( task_name IN VARCHAR2 id IN NUMBER, action IN VARCHAR2);
For a recommendation to be implemented, it must be marked as accepted. By default, all recommendations are considered accepted and will appear in any generated scripts.
DECLARE task_id NUMBER; task_name VARCHAR2(30); workload_name VARCHAR2(30); attribute VARCHAR2(100); rec_id NUMBER; BEGIN task_name := 'My Task'; workload_name := 'My Workload'; DBMS_ADVISOR.CREATE_TASK(DBMS_ADVISOR.SQLACCESS_ADVISOR, task_id, task_name); DBMS_ADVISOR.CREATE_SQLWKLD(workload_name, 'My Workload'); DBMS_ADVISOR.ADD_SQLWKLD_REF(task_name, workload_name); DBMS_ADVISOR.ADD_SQLWKLD_STATEMENT(workload_name, 'MONTHLY', 'ROLLUP', 100,400,5041,103,640445,680000,2, 1,SYSDATE,1,'SH','SELECT avg(amount_sold) FROM sh.sales WHERE promo_id = 10'); DBMS_ADVISOR.EXECUTE_TASK(task_name); rec_id := 1; DBMS_ADVISOR.MARK_RECOMMENDATION(task_name, rec_id, 'REJECT'); END; /
This procedure performs an analysis and generates recommendations for a single SQL statement.
This provides a shortcut method of all necessary operations to analyze the specified SQL statement. The operation creates a task using the specified task name. The task will be created using a specified Advisor task template. Finally, the task will be executed and the results will be saved in the repository.
DBMS_ADVISOR.QUICK_TUNE ( advisor_name IN VARCHAR2, task_name IN VARCHAR2, attr1 IN CLOB, attr2 IN VARCHAR2 := NULL, attr3 IN NUMBER := NULL, task_or_template IN VARCHAR2 := NULL);
If indicated by the user, the final recommendations can be implemented by the procedure.
The task will be created using either a specified SQLAccess task template or the built-in default template of SQLACCESS_GENERAL
. The workload will only contain the specified statement, and all task parameters will be defaulted.
attr1
must be the single SQL statement to tune.
DECLARE task_name VARCHAR2(30); BEGIN task_name := 'My Task'; DBMS_ADVISOR.QUICK_TUNE(DBMS_ADVISOR.SQLACCESS_ADVISOR, task_name, 'SELECT avg(amount_sold) FROM sh.sales WHERE promo_id=10'); END; /
This procedure resets a workload to its initial starting point. This has the effect of removing all journal messages, log messages, and recalculating necessary volatility and usage statistics.
DBMS_ADVISOR.RESET_SQLWKLD ( workload_name IN VARCHAR2);
Parameter | Description |
---|---|
|
The SQL Workload object name that uniquely identifies an existing workload. |
RESET_SQLWKLD
should be executed after any workload adjustments such as adding or removing SQL statements.
DECLARE workload_name VARCHAR2(30); BEGIN workload_name := 'My Workload'; DBMS_ADVISOR.CREATE_SQLWKLD(workload_name, 'My Workload'); DBMS_ADVISOR.ADD_SQLWKLD_STATEMENT(workload_name, 'MONTHLY', 'ROLLUP', 100,400,5041,103,640445,680000,2, 1,SYSDATE,1,'SH','SELECT avg(amount_sold) FROM sh.sales WHERE promo_id = 10'); DBMS_ADVISOR.RESET_SQLWKLD(workload_name); END; /
This procedure resets a task to its initial state. All intermediate and recommendation data will be removed from the task. The task status will be set to INITIAL
.
DBMS_ADVISOR.RESET_TASK ( task_name IN VARCHAR2);
Parameter | Description |
---|---|
|
The task name that uniquely identifies an existing task. |
DECLARE task_id NUMBER; task_name VARCHAR2(30); workload_name VARCHAR2(30); BEGIN task_name := 'My Task'; workload_name := 'My Workload'; DBMS_ADVISOR.CREATE_TASK(DBMS_ADVISOR.SQLACCESS_ADVISOR, task_id, task_name); DBMS_ADVISOR.CREATE_SQLWKLD(workload_name, 'My Workload'); DBMS_ADVISOR.ADD_SQLWKLD_REF(task_name, workload_name); DBMS_ADVISOR.ADD_SQLWKLD_STATEMENT(workload_name, 'MONTHLY', 'ROLLUP', 100,400,5041,103,640445,680000,2, 1,SYSDATE,1,'SH','SELECT avg(amount_sold) FROM sh.sales WHERE promo_id = 10'); DBMS_ADVISOR.EXECUTE_TASK(task_name); DBMS_ADVISOR.RESET_TASK(task_name); END; /
This procedure modifies the default value for a user parameter within a SQL Workload object or SQL Workload object template. A user parameter is a simple variable that stores various attributes that affect workload collection, tuning decisions and reporting. When a default value is changed for a parameter, workload objects will inherit the new value when they are created.
DBMS_ADVISOR.SET_DEFAULT_SQLWKLD_PARAMETER ( parameter IN VARCHAR2, value IN VARCHAR2); DBMS_ADVISOR.SET_DEFAULT_SQLWKLD_PARAMETER ( parameter IN VARCHAR2, value IN NUMBER);
A parameter will only affect operations that modify the workload collection. Therefore, parameters should be set prior to importing or adding new SQL statements to a workload. If a parameter is set after data has been placed in a workload object, it will have no effect on the existing data.
BEGIN DBMS_ADVISOR.SET_DEFAULT_SQLWKLD_PARAMETER('VALID_TABLE_LIST','SH.%'); END; /
This procedure modifies the default value for a user parameter within a task or a template. A user parameter is a simple variable that stores various attributes that affect various Advisor operations. When a default value is changed for a parameter, tasks will inherit the new value when they are created.
DBMS_ADVISOR.SET_DEFAULT_TASK_PARAMETER ( advisor_name IN VARCHAR2 parameter IN VARCHAR2, value IN VARCHAR2); DBMS_ADVISOR.SET_DEFAULT_TASK_PARAMETER ( advisor_name IN VARCHAR2 parameter IN VARCHAR2, value IN NUMBER);
BEGIN DBMS_ADVISOR.SET_DEFAULT_TASK_PARAMETER(DBMS_ADVISOR.SQLACCESS_ADVISOR, 'VALID_TABLE_LIST', 'SH.%'); END; /
This procedure modifies a user parameter within a SQL Workload object or SQL Workload object template. A user parameter is a simple variable that stores various attributes that affect workload collection, tuning decisions and reporting.
DBMS_ADVISOR.SET_SQLWKLD_PARAMETER ( workload_name IN VARCHAR2, parameter IN VARCHAR2, value IN VARCHAR2); DBMS_ADVISOR.SET_SQLWKLD_PARAMETER ( workload_name IN VARCHAR2, parameter IN VARCHAR2, value IN NUMBER);
A parameter will only affect operations that modify the workload collection. Therefore, parameters should be set prior to importing or adding new SQL statements to a workload. If a parameter is set after data has been placed in a workload object, it will have no effect on the existing data.
DECLARE workload_name VARCHAR2(30); BEGIN workload_name := 'My Workload'; DBMS_ADVISOR.CREATE_SQLWKLD(workload_name, 'My Workload'); DBMS_ADVISOR.SET_SQLWKLD_PARAMETER(workload_name, 'VALID_TABLE_LIST','SH.%'); END; /
This procedure modifies a user parameter within an Advisor task or a template. A user parameter is a simple variable that stores various attributes that affect workload collection, tuning decisions and reporting.
DBMS_ADVISOR.SET_TASK_PARAMETER ( task_name IN VARCHAR2 parameter IN VARCHAR2, value IN VARCHAR2); DBMS_ADVISOR.SET_TASK_PARAMETER ( task_name IN VARCHAR2 parameter IN VARCHAR2, value IN NUMBER);
A task cannot be modified unless it is in its initial state. See "RESET_TASK Procedure" to set a task to its initial state. See your Advisor-specific documentation for further information on using this procedure.
DECLARE task_id NUMBER; task_name VARCHAR2(30); BEGIN task_name := 'My Task'; DBMS_ADVISOR.CREATE_TASK(DBMS_ADVISOR.SQLACCESS_ADVISOR, task_id, task_name); DBMS_ADVISOR.SET_TASK_PARAMETER(task_name, 'VALID_TABLELIST', 'SH.%,SCOTT.EMP'); END; /
This procedure shows how to decompose a materialized view into two or more materialized views and to restate the materialized view in a way that is more advantageous for fast refresh and query rewrite. It also shows how to fix materialized view logs and to enable query rewrite.
DBMS_ADVISOR.TUNE_MVIEW ( task_name IN OUT VARCHAR2, mv_create_stmt IN [CLOB | VARCHAR2]);
See Also:
Oracle Data Warehousing Guide for more information about using the |
Executing TUNE_MVIEW
generates two sets of output results: one is for CREATE
implementation and the other is for undoing the CREATE
MATERIALIZED
VIEW
implementation. The output results are accessible through USER_TUNE_MVIEW
and DBA_TUNE_MVIEW
views. You can also use DBMS_ADVISOR.GET_TASK_SCRIPT
and DBMS_ADVISOR.CREATE_FILE
to output the TUNE_MVIEW
results into a script file for later execution.
These views are to get the result after executing the TUNE_MVIEW
procedure.
name VARCHAR2(30); DBMS_ADVISOR.TUNE_MVIEW.(name, 'SELECT AVG(C1) FROM my_fact_table WHERE c10 = 7');
The following is an example to show how to use TUNE_MVIEW
to optimize a CREATE
MATERIALIZED
VIEW
statement:
NAME VARCHAR2(30) := 'my_tune_mview_task'; EXECUTE DBMS_ADVISOR.TUNE_MVIEW (name, 'CREATE MATERIALIZED VIEW MY_MV REFRESH FAST AS SELECT C2, AVG(C1) FROM MY_FACT_TABLE WHERE C10 = 7 GROUP BY C2');
You can view the CREATE
output results by querying USER_TUNE_MVIEW
or DBA_TUNE_MVIEW
as the following example:
SELECT * FROM USER_TUNE_MVIEW WHERE TASK_NAME='my_tune_mview_task' AND SCRIPT_TYPE='CREATE';
Alternatively, you can save the output results in an external script file as in the following example:
CREATE DIRECTORY TUNE_RESULTS AS ''/myscript_dir'' ; GRANT READ, WRITE ON DIRECTORY TUNE_RESULTS TO PUBLIC; EXECUTE DBMS_ADVISOR.CREATE_FILE(DBMS_ADVISOR.GET_TASK_SCRIPT('my_tune_mview_ task'), - '/homes/tune','my_tune_mview_create.sql');
The preceding statement will save the CREATE
output results in /myscript_dir/my_tune_mview_create.sql
.
This procedure updates an existing task object. Task objects are typically used as input data for a particular advisor. Segment advice can be generated at the object, segment, or tablespace level.
DBMS_ADVISOR.UPDATE_OBJECT ( task_name IN VARCHAR2 object_id IN NUMBER, attr1 IN VARCHAR2 := NULL, attr2 IN VARCHAR2 := NULL, attr3 IN VARCHAR2 := NULL, attr4 IN CLOB := NULL, attr5 IN VARCHAR2 := NULL);
The attribute parameters have different values depending upon the object type. See Oracle Database Administrator's Guide for details regarding these parameters and object types.
If for the object level, advice is generated on all partitions of the object (if the object is partitioned). The advice is not cascaded to any dependent objects. If for the segment level, advice can be obtained on a single segment, such as the partition or subpartition of a table, index, or lob column. If for a tablespace level, target advice for every segment in the tablespace will be generated.
See Oracle Database Administrator's Guide for further information regarding the Segment Advisor.
DECLARE task_id NUMBER; task_name VARCHAR2(30); obj_id NUMBER; BEGIN task_name := 'My Task'; DBMS_ADVISOR.CREATE_TASK(DBMS_ADVISOR.SQLACCESS_ADVISOR, task_id, task_name); DBMS_ADVISOR.CREATE_OBJECT (task_name,'SQL',NULL,NULL,NULL, 'SELECT * FROM SH.SALES',obj_id); DBMS_ADVISOR.UPDATE_OBJECT (task_name, obj_id,NULL,NULL,NULL, 'SELECT count(*) FROM SH.SALES'); END; /
This procedure updates the owner, name, and tablespace for a recommendation.
DBMS_ADVISOR.UPDATE_REC_ATTRIBUTES ( task_name IN VARCHAR2 rec_id IN NUMBER, action_id IN NUMBER, attribute_name IN VARCHAR2, value IN VARCHAR2);
Recommendation attributes cannot be modified unless the task has successfully executed.
DECLARE task_id NUMBER; task_name VARCHAR2(30); workload_name VARCHAR2(30); attribute VARCHAR2(100); BEGIN task_name := 'My Task'; workload_name := 'My Workload'; DBMS_ADVISOR.CREATE_TASK(DBMS_ADVISOR.SQLACCESS_ADVISOR, task_id, task_name); DBMS_ADVISOR.CREATE_SQLWKLD(workload_name, 'My Workload'); DBMS_ADVISOR.ADD_SQLWKLD_REF(task_name, workload_name); DBMS_ADVISOR.ADD_SQLWKLD_STATEMENT(workload_name, 'MONTHLY', 'ROLLUP', 100,400,5041,103,640445,680000,2, 1,SYSDATE,1,'SH','SELECT avg(amount_sold) FROM sh.sales WHERE promo_id = 10'); DBMS_ADVISOR.EXECUTE_TASK(task_name); attribute := 'SH'; DBMS_ADVISOR.UPDATE_REC_ATTRIBUTES(task_name, 1, 3, 'OWNER', attribute); END; /
This procedure changes various attributes of a SQL Workload object or template.
DBMS_ADVISOR.UPDATE_SQLWKLD_ATTRIBUTES ( workload_name IN VARCHAR2, new_name IN VARCHAR2 := NULL, description IN VARCHAR2 := NULL, read_only IN VARCHAR2 := NULL, is_template IN VARCHAR2 := NULL, source IN VARCHAR2 := NULL);
DECLARE workload_name VARCHAR2(30); BEGIN workload_name := 'My Workload'; DBMS_ADVISOR.CREATE_SQLWKLD(workload_name, 'My Workload'); DBMS_ADVISOR.ADD_SQLWKLD_STATEMENT(workload_name, 'MONTHLY', 'ROLLUP', 100,400,5041,103,640445,680000,2, 1,SYSDATE,1,'SH','SELECT AVG(amount_sold) FROM sh.sales WHERE promo_id = 10'); DBMS_ADVISOR.UPDATE_SQLWKLD_ATTRIBUTES(workload_name,'New workload name'); END; /
This procedure updates an existing SQL statement in a specified SQL workload.
DBMS_ADVISOR.UPDATE_SQLWKLD_STATEMENT ( workload_name IN VARCHAR2, updated OUT NUMBER, action IN VARCHAR2, priority IN NUMBER, username IN VARCHAR2, search IN VARCHAR2); DBMS_ADVISOR.UPDATE_SQLWKLD_STATEMENT ( workload_name IN VARCHAR2, sql_id IN NUMBER, module IN VARCHAR2, action IN VARCHAR2, priority IN NUMBER, username IN VARCHAR2);
A workload cannot be modified or deleted if it is currently referenced by an active task. A task is considered active if it is not in its initial state. See "RESET_TASK Procedure" to set a task to its initial state.
DECLARE workload_name VARCHAR2(30); updated NUMBER; BEGIN workload_name := 'My Workload'; DBMS_ADVISOR.CREATE_SQLWKLD(workload_name, 'My Workload'); DBMS_ADVISOR.ADD_SQLWKLD_STATEMENT(workload_name, 'MONTHLY', 'ROLLUP', 100,400,5041,103,640445,680000,2, 1,SYSDATE,1,'SH','SELECT AVG(amount_sold) FROM sh.sales WHERE promo_id = 10'); DBMS_ADVISOR.UPDATE_SQLWKLD_STATEMENT(workload_name, 'module = ''MONTHLY''', updated, 'YEARLY', NULL, NULL,NULL); END; /
This procedure changes various attributes of a task or a task template.
DBMS_ADVISOR.UPDATE_TASK_ATTRIBUTES ( task_name IN VARCHAR2 new_name IN VARCHAR2 := NULL, description IN VARCHAR2 := NULL, read_only IN VARCHAR2 := NULL, is_template IN VARCHAR2 := NULL, source IN VARCHAR2 := NULL);
DECLARE task_id NUMBER; task_name VARCHAR2(30); BEGIN task_name := 'My Task'; DBMS_ADVISOR.CREATE_TASK(DBMS_ADVISOR.SQLACCESS_ADVISOR, task_id, task_name); DBMS_ADVISOR.UPDATE_TASK_ATTRIBUTES(task_name,'New Task Name'); DBMS_ADVISOR.UPDATE_TASK_ATTRIBUTES('New Task Name',NULL,'New description'); END; /