sql调优之--寻找我们最感兴趣的语句
2010-05-11 11:02
162 查看
Tuning an Application / Reducing Load
If your whole application is performing suboptimally, or if you are attempting to
reduce the overall CPU or I/O load on the database server, then identifying
resource-intensive SQL involves the following steps:
1. Determine which period in the day you would like to examine; typically this is the
application's peak processing time.
2. Gather operating system and Oracle statistics at the beginning and end of that
period. The minimum of Oracle statistics gathered should be file I/O
(V$FILESTAT), system statistics (V$SYSSTAT), and SQL statistics (V$SQLAREA,
V$SQL or V$SQLSTATS, V$SQLTEXT, V$SQL_PLAN, and V$SQL_PLAN_
STATISTICS).
3. Using the data collected in step two, identify the SQL statements using the most
resources. A good way to identify candidate SQL statements is to query
V$SQLSTATS. V$SQLSTATS contains resource usage information for all SQL
statements in the shared pool. The data in V$SQLSTATS should be ordered by
resource usage. The most common resources are:
■ Buffer gets (V$SQLSTATS.BUFFER_GETS, for high CPU using statements)
■ Disk reads (V$SQLSTATS.DISK_READS, for high I/O statements)
■ Sorts (V$SQLSTATS.SORTS, for many sorts)
One method to identify which SQL statements are creating the highest load is to
compare the resources used by a SQL statement to the total amount of that resource
used in the period. For BUFFER_GETS, divide each SQL statement's BUFFER_GETS by
the total number of buffer gets during the period. The total number of buffer gets in
the system is available in the V$SYSSTAT table, for the statistic session logical reads.
Similarly, it is possible to apportion the percentage of disk reads a statement performs
out of the total disk reads performed by the system by dividing V$SQL_STATS.DISK_
READS by the value for the V$SYSSTAT statistic physical reads. The SQL sections of
the Automatic Workload Repository report include this data, so you do not need to
perform the percentage calculations manually
After you have identified the candidate SQL statements, the next stage is to gather
information that is necessary to examine the statements and tune them.
调试一个应用/减少负载
如果整个应用表现的是最优化的状态,或者如果你在尝试减少数据库服务器的CPU或者IO负载,那么你可以用如下的方式来识别
消耗资源的sql语句:
1、确定在一天的哪个时间段来抽样数据,一般选择在应用最繁忙的时间段。
2、在那天的初始和结尾抓取操作系统的、数据库的信息。我们至少要包含这些信息,
系统的IO信息(v$filestat),系统信息(v$sysstat),sql语句的信息(v$sqlarea,v$sql或者v$sqlstats,v$sqltext,v$sqlstat,
v$sql_plan以及v$sql_plan_statistics)
3、使用第二部收集到的信息,定位最耗资源的sql语句。一个比较好的方法来识别待甄选的SQL语句的方法是查询
v$sqlstats. v$sqlstats 包含了在共享池中所有sql语句的资源使用信息。在V$SQLSTATS中的信息应该根据资源的使用
来进行排序,而最常见的资源包括:
Buffer gets(V$SQLSTATS.BUFFER_GETS,针对高CPU利用率的语句)
Disk reads(V$SQLSTATS.DISK_READS,针对高I/O的语句)
Sorts(V$SQLSTATS.SORTS,针对sort 操作多的语句)
识别产生最高负载的sql语句的方法是,让某个sql语句消耗的资源和所有的资源进行比较。
针对buffer_gets,让每个sql语句消耗的buffer_gets除以这段时间消耗的buffer_gets的总量。
系统中所有的buffer gets信息存在v$sysstat这个表中,针对的是静态的逻辑读。
相似的,我们可以用某个语句导致的disk读(v$sql_stats.disk_reads)除以这段时间的系统disk读(v$sysstat)。
AWR 报告的 SQL部分将包含这些信息,所以你不需要手工来计算。
当你获得了待选语句之后,你可以进一步抓取信息并调试这些语句。
Gathering Data on the SQL Identified
If you are most concerned with CPU, then examine the top SQL statements that
performed the most BUFFER_GETS during that interval. Otherwise, start with the SQL
statement that performed the most DISK_READS.
Information to Gather During Tuning
The tuning process begins by determining the structure of the underlying tables and
indexes. The information gathered includes the following:
1. Complete SQL text from V$SQLTEXT
2. Structure of the tables referenced in the SQL statement, usually by describing the
table in SQL*Plus
3. Definitions of any indexes (columns, column orderings), and whether the indexes
are unique or non-unique
4. Optimizer statistics for the segments (including the number of rows each table,
selectivity of the index columns), including the date when the segments were last
analyzed
5. Definitions of any views referred to in the SQL statement
6. Repeat steps two, three, and four for any tables referenced in the view definitions
found in step five
7. Optimizer plan for the SQL statement (either from EXPLAIN PLAN, V$SQL_PLAN,
or the TKPROF output)
8. Any previous optimizer plans for that SQL statement
进一步抓取信息
如果你最关心的是CPU,那么检查这段时间里最消耗BUFFER_GETS的语句。
或者,选择导致最多磁盘读操作的语句。
If your whole application is performing suboptimally, or if you are attempting to
reduce the overall CPU or I/O load on the database server, then identifying
resource-intensive SQL involves the following steps:
1. Determine which period in the day you would like to examine; typically this is the
application's peak processing time.
2. Gather operating system and Oracle statistics at the beginning and end of that
period. The minimum of Oracle statistics gathered should be file I/O
(V$FILESTAT), system statistics (V$SYSSTAT), and SQL statistics (V$SQLAREA,
V$SQL or V$SQLSTATS, V$SQLTEXT, V$SQL_PLAN, and V$SQL_PLAN_
STATISTICS).
3. Using the data collected in step two, identify the SQL statements using the most
resources. A good way to identify candidate SQL statements is to query
V$SQLSTATS. V$SQLSTATS contains resource usage information for all SQL
statements in the shared pool. The data in V$SQLSTATS should be ordered by
resource usage. The most common resources are:
■ Buffer gets (V$SQLSTATS.BUFFER_GETS, for high CPU using statements)
■ Disk reads (V$SQLSTATS.DISK_READS, for high I/O statements)
■ Sorts (V$SQLSTATS.SORTS, for many sorts)
One method to identify which SQL statements are creating the highest load is to
compare the resources used by a SQL statement to the total amount of that resource
used in the period. For BUFFER_GETS, divide each SQL statement's BUFFER_GETS by
the total number of buffer gets during the period. The total number of buffer gets in
the system is available in the V$SYSSTAT table, for the statistic session logical reads.
Similarly, it is possible to apportion the percentage of disk reads a statement performs
out of the total disk reads performed by the system by dividing V$SQL_STATS.DISK_
READS by the value for the V$SYSSTAT statistic physical reads. The SQL sections of
the Automatic Workload Repository report include this data, so you do not need to
perform the percentage calculations manually
After you have identified the candidate SQL statements, the next stage is to gather
information that is necessary to examine the statements and tune them.
调试一个应用/减少负载
如果整个应用表现的是最优化的状态,或者如果你在尝试减少数据库服务器的CPU或者IO负载,那么你可以用如下的方式来识别
消耗资源的sql语句:
1、确定在一天的哪个时间段来抽样数据,一般选择在应用最繁忙的时间段。
2、在那天的初始和结尾抓取操作系统的、数据库的信息。我们至少要包含这些信息,
系统的IO信息(v$filestat),系统信息(v$sysstat),sql语句的信息(v$sqlarea,v$sql或者v$sqlstats,v$sqltext,v$sqlstat,
v$sql_plan以及v$sql_plan_statistics)
3、使用第二部收集到的信息,定位最耗资源的sql语句。一个比较好的方法来识别待甄选的SQL语句的方法是查询
v$sqlstats. v$sqlstats 包含了在共享池中所有sql语句的资源使用信息。在V$SQLSTATS中的信息应该根据资源的使用
来进行排序,而最常见的资源包括:
Buffer gets(V$SQLSTATS.BUFFER_GETS,针对高CPU利用率的语句)
Disk reads(V$SQLSTATS.DISK_READS,针对高I/O的语句)
Sorts(V$SQLSTATS.SORTS,针对sort 操作多的语句)
识别产生最高负载的sql语句的方法是,让某个sql语句消耗的资源和所有的资源进行比较。
针对buffer_gets,让每个sql语句消耗的buffer_gets除以这段时间消耗的buffer_gets的总量。
系统中所有的buffer gets信息存在v$sysstat这个表中,针对的是静态的逻辑读。
相似的,我们可以用某个语句导致的disk读(v$sql_stats.disk_reads)除以这段时间的系统disk读(v$sysstat)。
AWR 报告的 SQL部分将包含这些信息,所以你不需要手工来计算。
当你获得了待选语句之后,你可以进一步抓取信息并调试这些语句。
Gathering Data on the SQL Identified
If you are most concerned with CPU, then examine the top SQL statements that
performed the most BUFFER_GETS during that interval. Otherwise, start with the SQL
statement that performed the most DISK_READS.
Information to Gather During Tuning
The tuning process begins by determining the structure of the underlying tables and
indexes. The information gathered includes the following:
1. Complete SQL text from V$SQLTEXT
2. Structure of the tables referenced in the SQL statement, usually by describing the
table in SQL*Plus
3. Definitions of any indexes (columns, column orderings), and whether the indexes
are unique or non-unique
4. Optimizer statistics for the segments (including the number of rows each table,
selectivity of the index columns), including the date when the segments were last
analyzed
5. Definitions of any views referred to in the SQL statement
6. Repeat steps two, three, and four for any tables referenced in the view definitions
found in step five
7. Optimizer plan for the SQL statement (either from EXPLAIN PLAN, V$SQL_PLAN,
or the TKPROF output)
8. Any previous optimizer plans for that SQL statement
进一步抓取信息
如果你最关心的是CPU,那么检查这段时间里最消耗BUFFER_GETS的语句。
或者,选择导致最多磁盘读操作的语句。
相关文章推荐
- 《高性能SQL调优精要与案例解析》——10.4_SQL语句改写部分文档
- Qt开发,链接了数据库后,调用QSqlQuery::setQuery执行SQL语句获取我们想要的数据
- MySQL百万级、千万级数据多表关联SQL语句调优
- SQL 语句性能调优
- MySQL千万级多表关联SQL语句调优
- Java中的面试题 [5] --- 数据库知识、MySQL、Oracle、sql调优、sql语句设计等
- 我们一起写SQL语句
- SQL语句调优实例锦集
- SQL语句调优三板斧
- 扩展LINQ to Entity:使用Lambda Expression批量删除数据------让微软帮我们生成T-SQL语句
- SQL语句调优
- MySQL 处理海量数据时的SQL语句调优
- oracle性能调优之--Oracle sql语句跟踪
- NDatabase 入门,简单使用 增删改查。让NDatabase带你脱离ADO.net,各种SQL 语句,各种DBMS,各种CRM,IOC之类的烦恼。我们也不需要仓库设计模式了,你妹的。不要表了,不要设计数据库字段了。就这样!
- Informix SQL 语句性能调优最佳实践
- SQL语句集锦:寻找连续号码的断号值
- SQL 语句性能调优
- SQL 语句中对于like 的调优
- SQL语句调优-基础知识准备
- SQL语句调优 - 索引上的数据检索方法