AWR能够帮助DBA识别占用资源最多的SQL语句.
SQL Tune Advisor执行步骤
- 捕获到占用资源较多的SQL
- Advisor对捕获到的、占用资源较多的SQL进行分析
- Advisor产生建议的SQL
- 执行实施SQL
SQL Tuning Advisor:Overview
Automatic SQL Tuning:Overview
- Automatic SQL Tuning automates the entire SQL tuning process and replaces manual SQL tuning.
- Optimizer modes:
- Normal modes:
- Tuning mode or Automatic Tuning Optimizer(ATO)
- SQL Tuning Advisor is used to access tuning mode.
- You should use tuning mode only for high-load SQL statements.
Application Tuning Challenges
Stale or Missing Object Statistics
- Object statistics are key inputs to the optimizer
- ATO verifies object statistics for each query object.
- ATO uses dynamic sampling and generates:
- -Auxiliary object statistics to compensate for missing or stale object statistics
- -Recommendations to gather object statistics where appropriate:
DBMS_STATS.GAHTER_TABLE_STATS( ownname=>'SH',tablename=>'CUSTOMERS',estimate_percent=>DBMS_STATS.AUTO_SAMPLE_SIZE );
SQL Statement Profiling
- Statement statistics are key inputs to the optimizer.
- ATO verifies statements statistics such as :
- Predicate selectivity
- Optimizer settings(FIRST ROWS versus ALL_ROWS)
- Automatic Tuning Optimizer uses
- Dynamic samling
- Partial execution of the statement
- Past execution history statistics of the statment
- ATO builds a profile if statistics were generated:
EXEC :profile_name := DBMS_SQLTUNE.accept_sql_profile(task_name => 'my_sql_tuning_task');
Plan Tuning Flow and SQL Profile Creation
Using the SQL Tuning Advisor
- Use the SQL Tuning Advisor to analyze SQL statements and obtain performance recommendations.
- Sources for SQL Tuning Advisor to analyze:
- -Top Activity:Analyzes the top SQL statements currently active.
- -SQL Tuning Sets:Analyzes a set of SQL statements you provide.
- -Historical SQL(AWR):Analyzes SQL statements from statements collected by AWR snapshots.