【跟我学oracle18c】第四十五天:2 Day DBA:10.3 使用Advisors优化数据库性能

10.3 Using Advisors to Optimize Database Performance

Oracle数据库包括一组建议器,帮助您管理和优化数据库。本节包含关于这些顾问的背景信息和使用说明。以下是研讨会的主题:

See Also:

Oracle Database 2 Day + Performance Tuning Guide

10.3.1 About Advisors

Advisors是数据库管理的强大工具。它们提供了关于如何解决关键管理挑战的具体建议,涉及范围广泛,包括空间、性能和撤消管理。一般来说, Advisors提供的建议比警报更全面。这是因为警报生成的成本较低,对性能的影响最小,而建议程序消耗更多资源并执行更详细的分析。这一点,再加上一些 Advisors的假设功能,为调优提供了无法从任何其他苏获得的重要信息

提供了建议程序来帮助您改进数据库性能。这些Advisors包括自动数据库诊断监视器(ADDM)、SQL顾问和内存顾问。例如,SGA Advisor图形化地显示了更改系统全局区域(SGA)大小对性能的影响。

您可以在面临以下情况时运行performance advisor:

  • 您希望解决特定领域的问题,例如,确定给定SQL语句为何消耗50%的CPU时间,以及如何减少其资源消耗。您可以使用SQL调优顾问。

  • 您正在计划向系统中添加内存。您可以使用Memory Advisor来确定增加SGA或PGA(程序全局区域)对数据库性能的影响。

您还可以从Performance Hub页面或通过ADDM的建议调用一些建议程序。

Table 10-2 描述性能顾问。

Table 10-2 Performance Advisors

AdvisorDescription

Automatic Database Diagnostics Monitor (ADDM)

ADDM使Oracle数据库能够诊断自己的性能,并确定如何解决任何已识别的问题。参见“性能自诊断:自动数据库诊断监视器”和“使用ADDM诊断性能问题”。

SQL Tuning Advisor

SQL调优顾问分析一个或多个SQL语句,并提出改进性能的建议。此advisor工具在维护期间自动运行,但也可以手动运行。参见“关于自动SQL调优顾问”和“运行SQL调优顾问”。
有关数据库的维护窗口(时间段)的更多信息,请参见Oracle数据库参考。

Memory Advisors

  • Memory Advisor

  • SGA Advisor

  • Buffer Cache Advisor

  • PGA Advisor

内存管理器提供了总内存目标设置、SGA和PGA目标设置或SGA组件大小设置的图形化分析。您可以使用这些分析来优化数据库性能并进行假设规划。根据当前的内存管理模式,可以使用不同的内存建议器。

  • If Automatic Memory Management is enabled, the Memory Advisor is available. This advisor provides advice for the total memory target for the instance.

  • If Automatic Shared Memory Management is enabled, then the SGA Advisor and PGA Advisor are available.

  • If Manual Shared Memory Management and Automatic PGA Memory are enabled, then the Buffer Cache Advisor and PGA Advisor are available.

See "Optimizing Memory Usage with the Memory Advisors" for more information about memory advisors, and see "Managing Memory" for more information about memory management modes.

Undo Advisor

Undo Advisor可以帮助正确地调整撤销表空间的大小。对于任何Oracle闪回需求,Undo Advisor还可以用来设置撤销保留周期的低阈值。参见“使用Undo Advisor计算最小撤销表空间大小”。

Optimizer Statistics Advisor

优化统计信息顾问是内置的诊断软件,分析统计信息的质量和统计相关的任务。advisor任务在维护窗口中自动运行,但是您也可以根据需要运行它。然后您可以查看advisor报告。如果advisor提供了建议,那么在某些情况下,您可以运行系统生成的脚本来实现这些建议。
有关使用优化器统计信息顾问的信息,请参阅Oracle数据库SQL调优指南

See Also:

Oracle Database 2 Day + Performance Tuning Guide

10.3.2 About the SQL Tuning Advisor关于SQL调优顾问

SQL调优顾问检查给定的SQL语句或一组SQL语句,并提供提高效率的建议。它可以提供各种类型的建议,例如创建SQL概要文件(一组信息,使查询优化器能够为SQL语句创建最佳执行计划)、重构SQL语句和刷新优化器统计信息。SQL调优顾问还允许您从过去选择一个替代执行计划(存储在AWR中),并将其与SQL语句一起使用,还可以推荐并行度配置文件. EM Express使您只需单击几下鼠标就可以接受并实现其中许多建议。

您可以使用SQL调优顾问来调优单个SQL语句或多个SQL语句。通常,您运行SQL调优顾问,以响应建议使用它的ADDM性能发现。您还可以在资源最密集的SQL语句和SQL工作负载上定期运行它。

在调优多个SQL语句时,SQL调优顾问不识别SQL语句之间的相互依赖关系。它通过识别单个SQL语句的问题来解决SQL性能问题,例如性能不佳的优化器计划或某些SQL结构的错误使用。

您可以根据以下来源运行SQL调优顾问:

  • Activity——在性能集线器的Activity选项卡上显示的上一个小时内执行的最消耗资源的SQL语句,这些语句可能导致最近的性能问题。

  • 历史SQL -在Select Time Period字段中选择历史设置之一时,出现在Performance Hub的Activity选项卡上的最后一天、星期或月份的SQL语句。使用此选项对SQL语句进行主动调优。

  • 来自ADDM的历史SQL——来自ADDM任务的资源密集型SQL语句,在分析Performance Hub的ADDM选项卡上的任务时发现。

  • SQL调优顾问中的SQL语句—资源密集型SQL语句,在SQL调优顾问中作为调优任务出现。

  • SQL调优集(STS)——您提供的一组SQL语句。STS可以从AWR快照捕获的SQL语句或SQL工作负载创建。

Note:

不能使用EM Express创建STS。有关创建STS的信息,请参阅Oracle数据库SQL调优指南。

See Also:

10.3.3 About the Automatic SQL Tuning Advisor关于自动SQL调优顾问

SQL调优顾问在系统维护窗口(时间段)作为维护任务自动运行。在每次自动运行期间,advisor都会在系统中选择高负载SQL查询,并生成关于如何优化这些查询的建议。

可以将自动SQL调优顾问配置为自动实现SQL概要文件建议。SQL概要文件包含特定于SQL语句的额外SQL统计信息,使查询优化器能够在运行时生成更好的执行计划。如果启用自动实现,那么advisor只为那些性能改进至少有三倍的SQL语句创建SQL概要文件. 其他类型的建议,如创建新索引、刷新优化器统计信息或重构SQL,只能手工实现。自动SQL调优顾问不考虑DML语句进行调优。

您可以查看自动SQL调优结果的摘要,以及关于SQL调优顾问已处理的所有SQL语句的建议的详细报告。然后可以实现选定的建议。您还可以查看自动实现的建议。

如果需要,可以禁用自动SQL调优顾问。

See Also:

10.3.4 配置自动SQL调优顾问

下面是一些您可能希望为自动SQL调优顾问执行的配置任务:

  • 启用SQL配置文件建议的自动实现。
    自动实现在默认情况下是禁用的。

  • 更改SQL调优顾问一次运行期间实现的SQL概要文件的最大数量
    当启用SQL配置文件建议的自动实现时,默认情况下,在运行SQL调优顾问期间将实现20个SQL配置文件。

  • 更改总体上可以实现的SQL概要文件的最大数量。
    在启用SQL配置文件建议的自动实现时,默认情况下,SQL调优顾问可以实现总共10000个SQL配置文件。

配置自动SQL调优顾问:

  1. 作为具有EM_EXPRESS_ALL角色的用户登录到EM Express。
    有关EM_EXPRESS_ALL角色的更多信息,请参见“为非管理用户授予对EM Express的访问权限”。
  2. 在EM Express中,从Performance菜单中选择SQL调优顾问。
    将出现SQL调优顾问页面,并显示Automatic选项卡。
    出现在Automatic选项卡上的SQL调优任务是SYS_AUTO_SQL_TUNING_TASK。这个调优任务是由自动SQL调优顾问每天创建的。该任务包括自动SQL调优顾问为其生成调优建议的任何高负载SQL查询。

    Description of auto_sqlt_advisor.gif follows
    Description of the illustration auto_sqlt_advisor.gif

  3. 单击Configuration按钮。
    出现SQL调优设置对话框。

    Description of sql_tuning_settings_dibox.gif follows
    Description of the illustration sql_tuning_settings_dibox.gif

  4. (可选)要禁用自动SQL调优顾问,请删除自动SQL调优选项的复选标记。
    注意:
    如果禁用自动SQL调优选项,则SQL调优设置对话框中的其他选项都不起作用。
  5. (可选)在“每条语句的时间限制(秒)”字段中,输入SQL调优顾问用于调优任何一条SQL语句(以秒为单位)的最大时间。
  6. (可选)在SQL Profiles自动实现字段中,输入一个复选标记来启用SQL Profiles的自动实现,或者删除复选标记来禁用SQL Profiles的自动实现。

    如果禁用SQL Profiles选项的自动实现,则每次执行实现的最大SQL概要文件和(总体)实现的最大SQL概要文件选项的设置将无效。

  7. (可选)在每个执行字段实现的最大SQL概要文件中,输入在SQL调优顾问的一次日常运行中可以实现的SQL概要文件总数。默认值是20。
  8. (可选)在Maximum SQL Profiles implementation (Overall)字段中,输入可以全面实现的SQL概要文件的总数。默认值是10000。
  9. Click OK.

    A confirmation page appears.

See Also:

"About the Automatic SQL Tuning Advisor" for more information about SQL profiles

10.3.5 查看自动SQL调优结果

您可以使用EM Express跟踪自动SQL调优顾问的活动。
查看自动SQL调优结果:

  1. 在EM Express中,从Performance菜单中选择SQL调优顾问。
    将出现SQL调优顾问页面,并显示Automatic选项卡。

    出现在Automatic选项卡上的SQL调优任务是SYS_AUTO_SQL_TUNING_TASK。这个调优任务是由自动SQL调优顾问每天创建的。该任务包括自动SQL调优顾问为其生成调优建议的任何高负载SQL查询。

    Description of auto_sqlt_advisor.gif follows
    Description of the illustration auto_sqlt_advisor.gif

    如果您将Automatic SQL Tuning Advisor配置为自动实现SQL概要文件建议,那么在SQL Tuning Advisor页面的Automatic选项卡上的SQL profile Potential DB Time Benefit图表将包含一个实现的bar。单击implementation bar可以查看所有自动实现的SQL概要文件。

  2. 在顶级SQL语句表中,选择一行,其中包含希望查看调优建议的SQL语句,然后单击view Details。
    在本例中,选择SQL ID为ffy1dpzphwuud的SELECT语句,单击View Details。

    将显示SQL页面的调优结果,其中显示所选SQL语句的调优建议摘要。

    Description of sqlta_auto_start.gif follows
    Description of the illustration sqlta_auto_start.gif

  3. Select Recommendation部分建议只实现页面上的一个建议。
    要实现建议,请在表中选择它并单击implementation。系统会提示您提供执行建议所需的信息。

    为了帮助您决定要实现哪些(如果有的话)建议,您可能需要查看关于每个建议的更多细节。
    要查看关于建议的更多细节,请在表中选择它,然后单击view details。在本例中,选择了SQL概要文件推荐。
    这时会出现推荐详细信息页面。

  4. 该页面的顶部部分描述了性能推荐,该部分以推荐的类型命名。本节的一些可能名称是“过时或丢失的统计信息”、“重构SQL”和“SQL Profile”。本节提供建议的概述。

    Description of sqlta_auto_1_stmt_recomd.gif follows
    Description of the illustration sqlta_auto_1_stmt_recomd.gif

    页面底部的Compare Explain Plans部分包含一些选项卡,这些选项卡允许您查看所选语句的一个或多个执行计划。可以出现的四个选项卡是原始计划、成本调整后的原始计划、使用SQL Profile的计划和可选计划选项卡。图形和表格按钮使您能够以图形或表格格式显示执行计划。在本例中,执行计划以表格格式显示。

    对于不包含可能更好的执行计划的建议,只显示原始计划选项卡,并且原始计划的操作显示在选项卡上。

    当您点击成本调整后的原计划选项卡时,执行计划步骤与原计划步骤相同,但是成本调整后的原计划步骤的成本不同(如操作成本栏所示)。

    如果使用SQL Profile选项卡单击Plan,步骤与原始计划步骤不同,并且步骤的成本不同(如Operation Cost列所示)。
    当无法找到原始计划的执行历史记录时,将出现备用计划按钮。在这种情况下,如果您知道SQL调优顾问建议的替代计划优于原始计划,那么您可以为替代计划创建SQL计划基线,以便Oracle优化器将来为语句选择替代计划。

    单击建议详细信息页面顶部的implementation按钮来实现建议。

See Also:

10.3.6 运行SQL调优顾问

使用SQL调优顾问对SQL语句进行调优。通常,您运行这个advisor工具是为了响应一个ADDM性能发现,该发现建议使用它。您还可以手动启动SQL调优顾问。原因之一是对自动SQL调优顾问没有考虑调优的语句进行调优。

如“关于SQL调优顾问”中所述,SQL调优顾问可以从多个源选择要调优的SQL语句。下面的场景假设您希望调优活动最多的SQL语句:

要运行SQL调优顾问:

  1. 在EM Express中,从性能菜单中选择Performance Hub。
    出现Performance Hub页面。
  2. 在“选择时间段”字段中,选择所需的时间段。
    在本例中,history - All已在Select Time Period字段中被选中。
  3. 选择活动。
    出现Activity选项卡。
  4. 在Activity选项卡底部的表中,选择包含要调优的SQL语句的行,然后单击tune SQL按钮。
    在本例中,选择表第六行中的SQL语句。

    Description of row6_sqlta.gif follows
    Description of the illustration row6_sqlta.gif

  5. 将出现Schedule SQL调优顾问向导,并显示任务信息页面。

    Description of row6_sqlta_sched1.gif follows
    Description of the illustration row6_sqlta_sched1.gif

    在任务信息页面上,您可以接受系统生成的调优任务名称,或者为将为所选SQL语句创建的调优任务输入您选择的名称。您还可以选择输入调优任务的描述。

    Click the right arrow button.

  6. 将出现Scope页面。指定SQL调优顾问用于分析语句的总时间(默认值是无限制的)和分析范围(全面的或有限的)。

    Description of row4_sqlta_sched2.gif follows
    Description of the illustration row4_sqlta_sched2.gif

    Click the right arrow button.

  7. 出现Schedule页面。在这个页面上,您可以安排SQL调优顾问立即或稍后分析该语句。如果选择让SQL Tuning Advisor稍后分析语句,请指定希望SQL Tuning Advisor分析语句的时间。

    Description of row4_sqlta_sched3.gif follows
    Description of the illustration row4_sqlta_sched3.gif

    Click OK to begin the tuning task creation by SQL Tuning Advisor for the selected SQL statement.

  8. 当SQL调优顾问完成对SQL语句的分析后,完成的(复选标记)图标将出现在SQL调优顾问页面的Status列中。
    选择包含SQL Tuning Advisor已完成分析的SQL语句的行,然后单击View Result查看SQL Tuning Advisor对该SQL语句的建议。在本例中,选择第一行。

    Description of row6_sqlta_manual_tab.gif follows
    Description of the illustration row6_sqlta_manual_tab.gif

    将出现SQL的调优结果:SQLID页面,其中显示所选SQL语句的调优建议摘要。

  9. 页面底部的Select Recommendation部分显示了调优SQL语句的建议。
    如果页面上有多个建议,则只应该实现其中一个。
    要实现建议,请在表中选择它并单击implementation。系统会提示您提供执行建议所需的信息。
    为了帮助您决定要实现哪些(如果有的话)建议,您可能需要查看关于每个建议的更多细节。

    Note:

    一些SQL语句可能有一个SQL概要文件建议,这意味着SQL调优顾问建议为该语句创建一个SQL概要文件。当为一条语句推荐一个SQL概要文件时,Select Recommendation部分在Type列中包含一个SQL概要文件值的推荐,以及一个带有SPA按钮的Validate。要验证为语句实现SQL概要文件的影响,请选择SQL概要文件推荐并单击validate with SPA。

    要查看关于建议的更多细节,请在表中选择它,然后单击view details。
    在本例中,通过搜索系统的实时和历史性能数据推荐,找到了该语句的一些替代执行计划。

    Description of row6_sqlta_tun_results.gif follows
    Description of the illustration row6_sqlta_tun_results.gif

    The Recommendation Details page appears.

  10. 该页面的顶部部分描述了性能推荐,该部分以推荐的类型命名。本节的一些可能名称是“替代计划”、“过时或丢失的统计信息”、“重构SQL”和“SQL配置文件”。本节提供建议的概述。

    Description of row6_sqlta_tun_recs.gif follows
    Description of the illustration row6_sqlta_tun_recs.gif

    页面底部的Compare Explain Plans部分包含一个或多个选项卡,这些选项卡使您能够查看所选语句的一个或多个执行计划。可以出现的四个选项卡是原始计划、成本调整后的原始计划、使用SQL Profile的计划和可选计划选项卡。表格和图形按钮使您能够以表格或图形格式显示执行计划。在本例中,执行计划以表格格式显示。

    对于不包含潜在更好的执行计划的建议,只显示原始计划选项卡,并且原始计划的操作显示在原始计划子页面上。
    在成本调整后的原计划子页面上,执行计划步骤与原计划步骤相同,但成本调整后的原计划各步骤的成本不同(见运营成本栏)。

    在使用SQL Profile子页面的计划中,步骤与原始计划步骤不同,并且步骤具有不同的成本(如Operation Cost列所示)。

    当无法找到原始计划的执行历史记录时,备用计划子页可用。在这种情况下,如果你知道SQL调优建议的替代方案顾问比原计划,您可以单击创建SQL计划基线按钮来创建一个SQL替代计划,这样的计划基线甲骨文优化器将选择的替代计划未来的声明。
    要实现推荐,请单击浏览器中的Back按钮,并在优化结果页面上实现推荐。

See Also:

10.3.7 关于在备用数据库上调优SQL语句

在Oracle Active Data Guard环境中,可以在主数据库上执行读/写查询,而在备用数据库上执行只读SQL查询。您可以在EM Express中使用SQL调优顾问来调优备用数据库上昂贵的只读SQL查询。

当使用SQL tuning Advisor调优Oracle Active Data Guard工作负载时,整个SQL调优过程在备用数据库本地执行,同时维护备用数据库的只读特性。这是通过使用从备用服务器到主服务器的数据库链接来将任何数据库状态更改(如SQL profile实现)写到主服务器来完成的。在主服务器上实现的建议由Oracle Data Guard redo apply应用到备用服务器。

Note:

You must have a license for the Oracle Active Data Guard option to be able to tune SQL statements on a standby database.

See Also:

10.3.7.1 在备用数据库上调优SQL语句

您可以在EM Express中使用SQL调优顾问来调优Oracle Active Data Guard环境中备用数据库的SQL语句。

Note:

要调优备用数据库上的SQL语句,必须拥有Oracle Active Data Guard选项的许可。
本主题假设您熟悉“运行SQL调优顾问”主题中的SQL调优顾问说明。

To run the SQL Tuning Advisor to tune SQL statements for a standby database in an Oracle Active Data Guard environment:

  1. In EM Express, from the Performance menu, choose Performance Hub.

    The Performance Hub page appears. The Select Time Period field is unavailable. You can tune only those SQL statements that execute in real-time on the standby.

  2. Select Activity.

    The Activity tab appears.

  3. In the table at the bottom of the Activity tab, select the row that includes the SQL statement that you want to tune, and then click the Tune SQL button.

    The Task Information page of SQL Tuning Advisor appears.

  4. On the Task Information page, supply values for these fields:
    • Name: Accept the tuning task name generated by the system, or enter a name of your choosing for the tuning task that will be created for the selected SQL statement.

    • Description: You also have the option of entering a description for the tuning task.

    • Source DB Link: Click the search button, and the Select DB Link dialog box appears, which lists the database links that exist on this standby database and point to the primary database. Select the database link to use to write the SQL tuning task to the SQL tuning tables on the primary database. Then click OK.

  5. On the Task Information page, click the right arrow button.
  6. The Scope page of SQL Tuning Advisor appears. Specify the total time that SQL Tuning Advisor should spend analyzing the statement (the default value is Unlimited), and the scope of the analysis (Comprehensive or Limited).

    Click OK to begin the tuning task creation by SQL Tuning Advisor for the selected SQL statement.

    EM Express redirects to the SQL Tuning Advisor page that shows a list of SQL tuning tasks.

  7. When the SQL Tuning Advisor finishes analyzing the SQL statement, the Completed (check mark) icon appears in the Status column on the SQL Tuning Advisor page.

    Select the row that includes the SQL statement that SQL Tuning Advisor has finished analyzing, and then click View Result to see the recommendations the SQL Tuning Advisor has for this SQL statement.

    The Tuning Result for SQL: SQLID page appears, which shows a summary of the tuning recommendations for the selected SQL statement.

  8. The Select Recommendation section at the bottom of the page shows the recommendations for tuning the SQL statement.

    If there are multiple recommendations on the page, only one of them should be implemented.

    To implement a recommendation, select it in the table and click Implement. You will be prompted to provide the necessary information to implement the recommendation. Note that the recommendation is implemented on the primary database using the database link that you specified in the Source DB Link field on the Task Information page.

    To help you decide which (if any) of the recommendations to implement, you may want to view more details about each of the recommendations.

    Note:

    Some SQL statements may have a SQL Profile recommendation, which means that SQL Tuning Advisor recommends creating a SQL profile for the statement. When a SQL profile is recommended for a statement, the Select Recommendation section includes a recommendation with a value of SQL Profile in the Type column, as well as a Validate with SPA button. The Validate with SPA button is unavailable in a standby database because the standby is a read-only database.

    To view more details about a recommendation, select it in the table, then click View Details. You can then review the recommendation on the Recommendation Details page.

  9. After you implement a recommendation and SQL Tuning Advisor writes it to the primary database using the database link on the standby, the recommendation will then be propagated to the standby database by the Oracle Data Guard redo apply mechanism.From this point on, when the SQL statement that was tuned is executed on the standby, it will be executed using the new recommendations that were implemented using SQL Tuning Advisor.

    See Also:

10.3.8 Optimizing Memory Usage with the Memory Advisors

This section includes information about memory advisors.

See Also:

10.3.8.1 关于内存顾问

足够的物理内存对Oracle数据库的性能有很大的影响。Oracle数据库具有自动内存管理功能,可以自动调整各种SGA和PGA组件之间的内存分布,以获得最佳性能。这些调整是在分配给数据库的内存总量范围内进行的。

ADDM定期评估数据库的性能,以确定性能问题。如果ADDM发现当前可用内存数量不足并对性能造成不利影响,那么它可以建议您增加内存分配。您可以使用内存顾问选择新的内存分配。

Additionally, you can use the Memory Advisors to perform what-if analysis on the following:

  • The database performance benefits of adding physical memory to your database

  • The database performance impact of reducing the physical memory available to your database

With the Memory Advisors, you can obtain memory sizing advice as follows:

10.4 Monitoring and Tuning the Database: Oracle by Example Series

Oracle By Example (OBE) has a series on the Oracle Database 2 Day DBA guide. This OBE steps you through the tasks in this section, and includes annotated screenshots.

To view the Monitoring and Tuning the Database OBE,enter the following URL in your web browser:

https://apexapps.oracle.com/pls/apex/f?p=44785:24:::NO:24:P24_CONTENT_ID:16833

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值