Oracle性能调整最重要的就是对最影响性能的SQL的调整。在一个应用中,能够影响到数据库的只有SQL,也只能是SQL。我们不能一味依靠增强硬件,修改系统、数据库参数来提高数据库的性能。更多的应该关注那些最影响性能的SQL语句。ASH报告、AWR报告、ADDM报告都能够找出最影响性能的SQL的工具。在分析ASH报告、AWR报告的时候,最重要的就是关注SQL Statistics,SQL Statistics中最应该关注的是SQL ordered by Gets和SQL ordered by Reads两个指标。大量的Gets(逻辑读)会占用大量的CPU时间。大量的Reads(物理读)会引起IO的瓶颈出现。一般情况下,大量的Gets会伴随着大量的Reads出现。当然,我们可以通过增大SGA的大小来减少Reads的量。通过这两个指标找到了最影响性能的SQL,这是首要的,也是必要的。下一步就可以通过创建索引,调整SQL来提高SQL单独执行时的性能。减少SQL执行时出现的高Gets,Reads。当然整体的性能影响还和excutions有关,如果这条SQL执行的次数过多,累加起来量还是很大的。那么就可以考虑通过在应用上缓存等手段来减少SQL执行的次数。另外还有一个需要注意的问题就是在开发过程中SQL一定要使用绑定变量,来减少硬解析(大量的硬解析也会消耗大量的CPU时间,占用大量的Latch)。在开发过程中有个原则就是:小事务。操作完成及时的提交。
In a nutshell - the tuning advisor
o suggests sql profiles
o gathering more or stale statistics
o indexes that might be VERY useful
o query rewrites
the access advisor
o suggests indexes that might be useful (a possibly different set than the tuning advisor above)
o materialized views
o materialized view logs
o partitions (in 11g on up only)
参考文章:
《More about AWR》:http://blog.itpub.net/23135684/viewspace-1127938/
--end--
For some time, Oracle’s solution in this area has been its built-in tool, Statspack.Oracle Database 10g offers a significant improvement: the Automatic Workload Repository (AWR). The AWR installs along with the database and captures not only statistics, but the derived metrics as well.
AWR retention settings and data gathering frequency
The AWR History is by default maintained for 7 days and the data is gathered in the AWR repository tables every hour by default.
The current snapshot retention settings and data gathering frequency can be determined by the query shown below. Note in this case the default settings of 7 days and 1 hour is displayed.
SQL> select to_char(snap_interval,’DD’),to_char(retention,’DD’) FROM dba_hist_wr_control;
TO_CHAR(SNAP_INTER TO_CHAR(RETENTION,
—————— ——————
+00000 01:00:00.0 +00007 00:00:00.0;
To change the settings –say, for snapshot intervals of 20 minutes and a retention period of two days –you would issue the following. The parameters are specified in minutes.
begin
dbms_workload_repository.modify_snapshot_settings (
interval => 20,
retention => 2*24*60
);
end;
AWR TABLES
Metadata (WRM$)
Historical data (WRH$)
AWR tables related to advisor functions (WRI$)
Oracle 11g New Features About Workload Capture and Workload Replay tables (WRR$)
Workload Repository Reports
Oracle provide two main scripts to produce workload repository reports (awrrpt.sql and awrrpti.sql). They are similar in format to the statspack reports and give the option of HTML or plain text formats. The two reports give essential the same output but the awrrpti.sql allows you to select a single instance. The reports can be generated as follows:
@$ORACLE_HOME/rdbms/admin/awrrpt.sql
@$ORACLE_HOME/rdbms/admin/awrrpti.sql
There are other scripts too, here is the full list:
REPORT NAME SQL Script
Automatic Workload Repository Report awrrpt.sql
Automatic Database Diagnostics Monitor Report addmrpt.sql
ASH Report ashrpt.sql
AWR Diff Periods Report awrddrpt.sql
AWR Single SQL Statement Report awrsqrpt.sql
AWR Global Report awrgrpt.sql
AWR Global Diff Report awrgdrpt.sql
Exporting and Importing AWR snapshot data
AWR data is stored in the WRH$ and DBA_HIST tables in the SYSAUX tablespace. There could be performance implications if these tables were to grow too large in size or if the retention was increased beyond the default of 7 days.
A good solution is to have a central repository and move statistical AWR data periodically to this central repository database using the Oracle supplied awrextr.sql and awrload.sql scripts which can be found in the $ORACLE_HOME/rdbms/admin directory.
– in source db
SQL> @?/rdbms/admin/awrextr.sql
– in target db
SQL>@?/rdbms/admin/awrload.sql
or
using oracle internal package
dbms_swrf_internal.AWR_EXTRACT
DBMS_SWRF_INTERNAL.AWR_LOAD
DBMS_SWRF_INTERNAL.MOVE_TO_AWR
DBMS_SWRF_INTERNAL.CLEAR_AWR_DBID
Clean AWR
exec dbms_swrf_internal.unregister_database();
dbms_workload_repository.DROP_SNAPSHOT_RANGE;
Disable Oracle AWR
If you would like to disable AWR from executing on an Oracle database, here are several ways to turn it off. If you are not using the AWR data, why pay the penalty for having it continually running and collecting unused data. These steps are listed in what I think are the easiest options first.
1,Set STATISTICS_LEVEL parameter to BASIC.
2,Run the CATNOAWR.sql script to drop the AWR Repository tables. The script calls procedure dbms_swrf_internal.remove_wr_control, which deletes a row relating to your database from the wrm$_wr_control table, and then drops all the AWR tables.
3,Execute DBMS_WORKLOAD_REPOSITORY.MODIFY_SNAPSHOT_SETTINGS(interval=>0).By setting the value of the interval as 0, we set the new interval between each snapshot collection as 110 years:
4,Download dbms_awr.plb from Metalink, compile this package and execute the PL/SQL package DBMS_AWR.DISABLE_AWR() [see Metalink note 436386.1].
5,This does not work for an existing database, but does for future databases: Create your own database creation scripts (do not utilize DBCA) and do not execute the CATAWRTB.sql script.
6,_awr_restrict_mode initialization parameter which is set to TRUE and turns off all AWR features in the repository database
Recreate the AWR
Oracle Support suggesting us to recreate the AWR using the below steps since our SYSAUX tablespace is keep growing:
alter system set sga_target=0 scope=spfile;
alter system set statistics_level = basic scope=both;
alter system set cluster_database=false;
shutdown immediate
startup restrict
– in 10g begin —
@?/rdbms/admin/catnoawr.sql
alter system flush shared_pool;
@?/rdbms/admin/catsvrm.sql –in the script had calls catawrtb.sql
– in 10g end —
– in 11g begin—
SQL> @?/rdbms/admin/catnoawr.sql
SQL> alter system flush shared_pool;
SQL> @?/rdbms/admin/catawr.sql
SQL> @?/rdbms/admin/utlrp.sql
sql> @?/rdbms/admin/execsvrm.sql
– in 11g end—
Then re-enable the AWR statistics gathering as required, by setting STATISTICS_LEVEL back to its original value, and restart the instance normally
Tip:
When SYSAUX tablespace is keep growing,you can check the V$SYSAUX_OCCUPANTS View to find out who/what is occupying space in SYSAUX.