重庆思庄Oracle、Redhat认证学习论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 3216|回复: 0
打印 上一主题 下一主题

[认证考试] OCP课程35:管理Ⅰ之性能

[复制链接]
跳转到指定楼层
楼主
发表于 2016-2-15 09:01:05 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

课程目标:

  • 使用EM管理性能
  • 管理自动内存管理AMM
  • 使用内存顾问
  • 查看性能相关动态视图
  • 无效对象处理

1、性能监控

要使数据库保持平稳运行,数据库管理员(DBA)必须定期监测性能瓶颈。

DBA可以看到数以百计的性能指标,涵盖从网络性能和磁盘输入/输出(I / O)速度等。这些性能指标通常被称为数据库度量。


2、企业管理器性能页面

企业管理器的性能页面是性能监控和调优工具的入口。这个页面上的第一组图形显示了进程和活动会话。平均活动会话图显示了CPU使用率和导致大多数等待事件的资源。

在上图中可以看到,最近的并发性和其他等待的增加。在每一个尖峰,有一个I/O和CPU轻微的增加。你可以点击这些类别查看更多的细节。


3、下钻等待类别

当深入到一个特定的等待类,可以查看某个五分钟的详细信息,也可以看到与该等待事件相关的TOP SQL与TOP Working Sessions。可以据此分析系统变慢的原因。


4、性能页面:吞吐量

通过单击“性能”页面上的“吞吐量”和“I/O”选项卡来查看实例吞吐量和实例I/O。


5、性能监控:顶级会话

在其他监视链接区域点击顶级使用者,进入顶级使用者页面,点击“顶级会话”。

顶级使用者页面包括:

  • 顶级服务
  • 顶级模块
  • 顶级操作
  • 顶级客户机
  • 顶级会话

点击“顶级会话”可以看到会话的关键统计信息,包括:

  • CPU
  • PGA内存
  • 逻辑读
  • 物理读
  • 硬解析数量
  • 排序数量


6、性能监控:顶级服务

在多层系统中通过应用服务器连接到数据库,查看会话可能无法提供分析性能所需要的信息。以服务名称分组会话可以更准确地监视性能。

在上面这个例子中,有四个服务:SYS$USERS,SYS$BACKGROUND,SH,和SERV1。如果会话是通过以上服务进行连接,则会话的性能数据被捕获在该服务名下。

7、管理内存组件

Oracle 11g可以指定分配给实例的内存总量。内存将被动态地分配给系统全局区(SGA)和程序全局区(PGA)。这种方法被称为自动内存管理(AMM)。这简化了内存管理任务。

内存顾问可帮助您设置不同级别的初始化参数。该顾问可用性取决于指定的内存参数的级别。如果启用了AMM,则只有内存大小顾问可用。

自动共享内存管理(ASMM)将SGA作为一个整体管理。SGA由几个部分组成,这些部分的大小是动态调整。当AMM启用,则自动启用的ASMM。如果启用ASMM但不启用AMM,则可以使用SGA大小顾问。

可以通过设置每个组件的初始化参数来手动管理各个组件的大小。如果Oracle服务器通知你一个性能问题,与SGA或PGA组件的大小有关,就可以使用内存顾问来确定组件的大小。


8、启用自动内存管理(AMM)

如果没有启用自动内存管理(AMM),可以通过执行以下步骤启用:

(1)在主页上单击“服务器”选项卡。

(2)单击数据库配置区域中的内存顾问。

(3)单击“启用”。

(4)设置内存大小和最大内存大小,如果更改最大内存大小,必须重新启动数据库实例。

(5)点击确定。

也可以通过memory_target初始化参数设置内存大小。但不能大于最大内存大小或memory_max_target参数指定的值。

AMM启用后,可以使用内存大小顾问帮助调整内存大小和最大内存大小。

Oracle建议使用自动内存管理来简化内存管理任务。

Instance
SGA
PGA
Description
Initialization Parameters

Auto

n/a

n/a

The database tunes the size of the instance based on a single instance target size.

You set:

  • Total memory target size for the database instance (MEMORY_TARGET)
  • Optional maximum memory size for the database instance (MEMORY_MAX_TARGET)

n/a

Auto

Auto

The database automatically tunes the SGA based on an SGA target.

The database automatically tunes the PGA based on a PGA target.

You set:

  • SGA target size (SGA_TARGET)
  • Optional SGA maximum size (SGA_MAX_SIZE)
  • Instance PGA target size (PGA_AGGREGATE_TARGET)

n/a

Auto

Manual

The database automatically tunes the SGA based on an SGA target.

You control the PGA manually, setting the maximum work area size for each type of SQL operator.

You set:

  • SGA target size (SGA_TARGET)
  • Optional SGA maximum size (SGA_MAX_SIZE)
  • PGA work area parameters such as SORT_AREA_SIZE, HASH_AREA_SIZE, and BITMAP_MERGE_AREA_SIZE

n/a

Manual

Auto

You control the SGA manually by setting individual component sizes.

The database automatically tunes the PGA based on a PGA target.

You set:

  • Shared pool size (SHARED_POOL_SIZE)
  • Buffer cache size (DB_CACHE_SIZE)
  • Large pool size (LARGE_POOL_SIZE)
  • Java pool size (JAVA_POOL_SIZE)
  • Streams pool size (STREAMS_POOL_SIZE)
  • Instance PGA target size (PGA_AGGREGATE_TARGET)

n/a

Manual

Manual

You must manually configure SGA component sizes.

You control the PGA manually, setting the maximum work area size for each type of SQL operator.

You must manually configure SGA component sizes. You set:

  • Shared pool size (SHARED_POOL_SIZE)
  • Buffer cache size (DB_CACHE_SIZE)
  • Large pool size (LARGE_POOL_SIZE)
  • Java pool size (JAVA_POOL_SIZE)
  • Streams pool size (STREAMS_POOL_SIZE)
  • PGA work area parameters such as SORT_AREA_SIZE, HASH_AREA_SIZE, and BITMAP_MERGE_AREA_SIZE


9、启用自动共享内存管理(ASMM)

如果启用了AMM则自动启用自动共享内存管理。如果没有启用AMM或者ASMM,可以通过执行以下步骤启用自动共享内存管理:

(1)在主页上单击“服务器”选项卡。

(2)单击数据库配置区域中的内存顾问。

(3)向下滚动到SGA区。单击“启用”自动共享内存管理。

(4)指定SGA总大小。点击确定。

可以通过sga_target初始化参数设置SGA大小。但是不能大于最大SGA大小或sga_max_size参数指定的值。

当禁用AMM,可以访问PGA顾问。PGA顾问建议设置PGA内存值。单击选项卡访问PGA属性页。


10、自动共享内存顾问

当启用ASMM,不需要为特定的共享内存组件设置初始化参数。在ASMM启用后,可以使用SGA大小顾问帮助设置SGA大小为最佳值。

在启用ASMM之前,应该从SPFILE中将ASMM管理的各个内存参数移除,因为这将对ASMM产生限制。也可以单独调整某些组件的大小,如果指定的值低于当前值,那么这些值被视为最小内存大小。如果指定的值大于当前值,只要有空闲内存,就会增大到设定的值。这样做限制了内存的自动调整,仅用于特定情况下的内存调整。

可调整的初始化参数如下:

  • shared_pool_size
  • large_pool_size
  • java_pool_size
  • db_cache_size
  • streams_pool_size

必须使用ALTER SYSTEM命令进行调整。


11、动态性能统计

有效诊断性能问题需要使用统计信息。在不同粒度级别上,Oracle服务器会生成多种类型的统计数据。

在系统级别,会话级别和服务级别,会生成等待事件和积累统计数据。在上图中,上部显示累计统计数据,下部显示等待事件视图。

当分析某个范围内的性能问题时,通常会查看某个时间段内统计数据的变化情况。通过V$EVENT_NAME视图查看所有可能的等待事件名称。通过V$STATNAME查看所有统计数据名称。

例子:查看系统范围的统计数据

SQL> select name,class,value from v$sysstat where value<>0 and name like 'table scan%';

NAME                                                                  CLASS      VALUE

---------------------------------------------------------------- ---------- ----------

table scans (short tables)                                               64       1673

table scans (long tables)                                                64         17

table scans (direct read)                                                64         30

table scan rows gotten                                                   64     754203

table scan blocks gotten                                                 64      15251

系统统计信息按照调优和诊断目的进行分类。包括一般实例活动、重做日志缓冲区活动、锁定、数据库缓冲区缓存活动等。


12、故障排除和调优视图

上图列出了一些视图,可以帮助确定性能问题的原因或者分析数据库的当前状态。


13、无效的对象

无效的PL/SQL对象和无用的索引对性能有影响。无效的PL/SQL对象必须重新编译才可以使用,额外增加了编译时间。如果PL/SQL重新编译不成功,操作失败并返回错误。优化器忽略不可用索引。如果一个SQL语句的性能取决于一个不可以索引,则在索引重建前性能不会有提升。

无效的PL/SQL对象:PL/SQL对象当前的状态可以通过查询数据字典查看。

例子:查找无效的对象

SQL> select object_name,object_type from dba_objects where status='INVALID';

OBJECT_NAME                    OBJECT_TYPE

------------------------------ ---------------

MGMT$REORG_CHECKDBAPRIVS       PROCEDURE

默认情况下,每24小时检查一次用户的无效对象计数指标。如果用户的无效对象数量超过2个,则发出警报。

如果发现PL/SQL对象状态无效,你需要回答的第一个问题是“这个对象曾经有效吗?“,应用程序开发人员经常忽略不工作的代码。如果因为一个代码错误导致PL/SQL对象无效,则需要先修复代码错误。如果程序在过去的某个时候是有效的,最近变成无效,有2个选项来解决这个问题:

  • 什么也不做。大多数PL/SQL对象在被调用时会自动重新编译。对象编译时用户体验稍有延迟(在大多数情况下,这种延迟是不明显的)
  • 手动编译无效的对象。

无效的PL/SQL对象可以手动重新编译,使用企业管理器或通过SQL命令:

ALTER PROCEDURE HR.add_job_history COMPILE;

手动重新编译PL/SQL包需要两个步骤:

ALTER PACKAGE HR.maintainemp COMPILE;
ALTER PACKAGE HR.maintainemp COMPILE BODY;

不可用索引:可以通过查询数据字典视图dba_indexes查找无效索引:

select index_name,table_name from dba_indexes where status='UNUSABLE';

对于分区索引,查看dba_ind_partitions视图的status字段。

通过重建不可用索引使索引有效。可以通过使用企业管理器或通过SQL命令

  • ALTER INDEX HR.emp_empid_pk REBUILD;
  • ALTER INDEX HR.emp_empid_pk REBUILD ONLINE;
  • ALTER INDEX HR.email REBUILD TABLESPACE USERS;

如果忽略tablespace子句,则索引重建在相同的表空间。REBUILD ONLINE可以在重建索引的时候继续对索引进行更新。

企业管理器使用的重组行动修复不可用索引。

例子:创建存储过程进行测试

SQL> conn hr/hr

Connected.

SQL> create or replace procedure p_test

  2  is

  3   begin

  4     update emp set salary=salary*1.10 where employee_id=100;

  5   end;

  6  /

Procedure created.

SQL> select employee_id,salary from emp where employee_id=100;

EMPLOYEE_ID     SALARY

----------- ----------

        100      10000

SQL> exec p_test;

PL/SQL procedure successfully completed.

SQL> select employee_id,salary from emp where employee_id=100;

EMPLOYEE_ID     SALARY

----------- ----------

        100      11000

SQL> select object_name,status from obj where object_name='P_TEST';

OBJECT_NAME                    STATUS

------------------------------ -------

P_TEST                         VALID

SQL> alter table emp modify(salary number(10,2));

Table altered.

SQL> select object_name,status from obj where object_name='P_TEST';

OBJECT_NAME                    STATUS

------------------------------ -------

P_TEST                         INVALID

SQL> exec p_test;

PL/SQL procedure successfully completed.

SQL> select employee_id,salary from emp where employee_id=100;

EMPLOYEE_ID     SALARY

----------- ----------

        100      12100

SQL> select object_name,status from obj where object_name='P_TEST';

OBJECT_NAME                    STATUS

------------------------------ -------

P_TEST                         VALID

例子:创建索引并重建

SQL> create index idx_emp_last_name on emp(last_name);

Index created.

SQL> select index_name,status from ind where index_name='IDX_EMP_LAST_NAME';

INDEX_NAME                     STATUS

------------------------------ --------

IDX_EMP_LAST_NAME              VALID

SQL> alter table emp move tablespace example;

Table altered.

SQL> select index_name,status from ind where index_name='IDX_EMP_LAST_NAME';

INDEX_NAME                     STATUS

------------------------------ --------

IDX_EMP_LAST_NAME              UNUSABLE

SQL> alter index idx_emp_last_name rebuild online;

Index altered.

SQL> select index_name,status from ind where index_name='IDX_EMP_LAST_NAME';

INDEX_NAME                     STATUS

------------------------------ --------

IDX_EMP_LAST_NAME              VALID


14、相关习题:

(1)What can you achieve by implementing reverse key index?
A.  Reverse the bytes of each column indexed including the row ID
B.  Store a bitmap for each key value instead of a list of row IDs in the leaf node
C.  Prevent contention on the highest leaf block when using sequences to generate keys
D.  Remove repeated key values from the index to fit more index entries in a given amount of disk space

答案:C

(2)You set the following parameters in the parameter file and restarted the database:
   MEMORY_MAX_TARGET=0
   MEMORY_TARGET=500M
   PGA_AGGREGATE_TARGET=90M
   SGA_TARGET=270M
Which  two  statements  are  true  about these  parameters  after  the  database instance  is restarted? (Choose two.)
A.  The MEMORY_MAX_TARGET parameter is automatically set to 500 MB.
B.  The PGA_AGGREGATE_TARGET and SGA_TARGET parameters are automatically set to zero.
C.  The value of the MEMORY_MAX_TARGET parameter remains zero until it is changed manually.
D.  The lower bounds of PGA_AGGREGATE_TARGET and SGA_TARGET parameters are set to 90 MB and 270 MB, respectively.

答案:AD

(3)Automatic  Shared  Memory  Management  (ASMM)  has  been  enabled  for  your  database instance.  The  initialization  parameters  for  the  components  that  are  managed  by  ASMM  are not set. After observing the effects of ASMM, you executed the following command:
   SQL> ALTER SYSTEM SET DB_CACHE_SIZE = 100M;
Which statement is true in this scenario?
A.  The minimum memory size for the database buffer cache is set to 100 MB.
B.  The maximum memory size that can be obtained by the database buffer cache during ASMM is set to 100 MB.
C.  The minimum memory size allocated for a server process in the database buffer cache in dedicated mode is set to 100 MB.
D.  The  maximum  memory  size from  the  database  buffer  cache  that  can  be  released  for  dynamic  distribution during ASMM is set to 100 MB.

答案:A

(4)While  observing  the  index  statistics,  you  find  that  an  index  is  highly  fragmented,  thereby  resulting in poor database performance.
Which option would you use to reduce fragmentation without affecting the users who are currently using the index?
A.  Validate the index structure using the ANALYZE .... INDEX command
B.  Rebuild the index using the ALTER INDEX ..... REBUILD ONLINE command
C.  Change the block space utilization parameters using the ALTER INDEX command
D.  Deallocate the unused space in the index using the ALTER INDEX ... DEALLOCATE UNUSED command

答案:B

(5)Examine the following output:
   SQL> SELECT index_name,status
             FROM dba_indexes
             WHERE status='UNUSABLE';
   INDEX_NAME              STATUS
   -------------             ---------------
   EIND                          UNUSABLE
Which two statements about the above index are true? (Choose two.)
A.  It is ignored by the query optimizer.
B.  It is not used while the index is being rebuilt.
C.  The index cannot be rebuilt, and has to be re-created.
D.  The index is automatically rebuilt when used the next time.

答案:AB

(6)In  a  system,  large  online  transaction  processing  (OLTP)  jobs  run  during  the  daytime  that require  a  large  database  buffer  cache.  In  the  night,  the  system  supports  batch  jobs  that require  a  higher  value  to  be  set  for  the  large  pool.  You  must  simultaneously  configure  the memory components to accommodate the peak requirement.
What would you do to automate this configuration for the memory components with change in mode of working?
A.  Set the SGA_TARGET initialization parameter to zero.
B.  Set the PRE_PAGE_SGA initialization parameter to TRUE.
C.  Set the MEMORY_MAX_TARGET initialization parameter to zero.
D.  Set the SGA_TARGET initialization parameter to a nonzero value.

答案:D

(7)Which two statements are true regarding the SGA_TARGET initialization parameter? (Choose two.)
A.  It can be increased up to the value of the SGA_MAX_SIZE parameter.
B.  Increasing  the  value  of  the  SGA_TARGET  parameter  distributes  the  increased  memory  among  all  the  autotuned components.
C.  Reducing the value of the SGA_TARGET parameter deallocates memory from both autotuned and manually sized components.
D.  Increasing the value of SGA_TARGET up to the value of SGA_MAX_SIZE disables the automatic shared memory management feature

答案:AB

(8)Which two statements are true regarding B-tree index? (Choose two.)
A. The leaf blocks in the index are doubly linked.
B. The leaf node stores a bitmap for each key value.
C. The rows with NULL value in key columns also have entries in the index.
D. The  deletion  of  a  row  from  the  table  causes  a  logical  deletion  in  index  leaf  block  and  the  space  becomes available for the new leaf entry.

答案:AD

(9)Examine the following statement that is used to modify the primary key constraint on the SALES table:
   SQL> ALTER TABLE SALES MODIFY CONSTRAINT pk DISABLE VALIDATE;
Which three statements are true regarding the above command? (Choose three.)
A.  The constraint remains valid.
B.  The index on the constraint is dropped.
C.  It allows the loading of data into the table using SQL *Loader.
D.  New data conforms to the constraint, but existing data is not checked.
E. It allows the data manipulation on the table using INSERT/UPDATE/DELETE SQL statements.

答案:ABC


分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 支持支持 反对反对
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|手机版|小黑屋|重庆思庄Oracle、Redhat认证学习论坛 ( 渝ICP备12004239号-4 )

GMT+8, 2024-5-6 02:53 , Processed in 0.104134 second(s), 20 queries .

重庆思庄学习中心论坛-重庆思庄科技有限公司论坛

© 2001-2020

快速回复 返回顶部 返回列表