University of Electronic Science and Technology of China Database and Software Engineering Experiment 5

Applicable to network engineering and Internet of Things majors

final exam

Table of contents

1. Experimental purpose

2. Experimental content

3. Experimental software

4. Experimental procedures and data recording

1. Permission management

2. Database backup

3. Generate AWR report

5. Experimental conclusions and questions

6. Summary and experience

7. Suggestions for improving the experimental process, methods and means


1. Experimental purpose

1. Master the granting and recycling of system permissions and object permissions;

2. Master the method of using data pump to back up and restore the database;

3. Be familiar with using Oracle AWR reports to analyze database performance.

2. Experimental content

Use DBA users to manage system permissions and object permissions of Oracle database, and use Data Pump

Tools for backup and recovery of database data. Generate Oracle AWR reports and observe various

parameters to optimize the database.

3. Experimental software

Oracle database

4. Experimental procedures and data recording

1. Permission management

Use the Oracle user to log in to the CentOS system desktop, and use the sys account to enter sqlplus.

1) Create a password-authenticated database user usera_exer with the password usera, the default table space is USERS, the default temporary table space is TEMP, the quota of the USERS table is 10MB, and the initial state is locked.

Figure 1 Creation of usera_exer

 

2) Create a password-authenticated database user userb_exer with the password userb, the default table space is USERS, the default temporary table space is TEMP, the quota of the USERS table is 10MB, and the initial state is the default state.

Figure 2 Creation of userb_exer

 

3) Grant the CREATE SESSION system permissions, SCOTT.EMP SELECT and UPDATE object permissions to the usera_exer user, and allow this user to grant the obtained permissions to other users.

Figure 3 usera_exer related permission authorization

 

4) Unlock the account of user usera_exer.

Figure 4 Unlocking the account of user usera_exer

 

5) Log in to the database (conn usera_exer/usera) with the usera_exer account and query the data in SCOTT.EMP.

 

 

Figure 5 Data in SCOTT.EMP

6) Grant the SELECT permission and UPDATE permission of SCOTT.EMP to user userb_exer, but prohibit user userb_exer from granting the obtained permissions to other users.

Figure 6 Screenshot of command and results

 

7) Use the sys account to log in to the database (conn /as sysdba) and prohibit user usera_exer from granting the CREATE SESSION system permission to other users.

图7 ​Prohibited limit

 

8) User usera_exer is prohibited from granting the SELECT and UPDATE object permissions of SCOTT.EMP to other users.

Figure 8 Disable the permissions of user usera_exer

 

9) Create roles rolea (password is rolea) and roleb (password is roleb), grant CREATE TABLE permissions, SCOTT.EMP INSERT and DELETE permissions to rolea; grant CONNECT and RESOURCE roles to roleb.

Figure 9 Create role

 

10) Grant roles rolea and roleb to user usera_exer.

 

Figure 10 Role granted to user

2. Database backup

1) Grant the permissions CREATE SESSION, CREATE TABLE, EXP_FULL_DATABASE, IMP_FULL_DATABASE to user userb_exer.

Figure 11 Permission Grant

 

2) Use the Oracle user to create a directory imp_dir under /home/Oracle_11g.

[Oracle@localhost ~]$ cd /home/oracle_11g/

[Oracle@localhost Oracle_11g]$ mkdir imp_dir

3) Use the sys account to enter sqlplus and define the just created imp_dir directory.

[Oracle@localhost Oracle_11g]$ sqlplus /nolog

SQL> conn /as sysdba

SQL> CREATE DIRECTORY imp_test AS '/home/Oracle_11g/imp_dir';

View the directory of the Oracle database,take a screenshot and record the query results.

SQL> select * from dba_directories;

Figure 12 View the directory of the database

 

Grant the read and write permissions of the imp_dir directory to the userb_exer user,

SQL> grant read,write on directory imp_test to userb_exer;

4) Exit sqlplus, under the oracle user, use the userb_exer user to use expdp to back up all tables and all data of the scott user. The backup file name is in the form of "Experimenter's Name Pinyin_Date".

[Oracle@localhost ~]$ expdp userb_exer/userb DIRECTORY=imp_test  SCHEMAS=scott DUMPFILE=zhangsan.scott_0831.dmp logfile= zhangsan_scott.0831.log

Figure 13 Execution result record

 

3. Generate AWR report

Use the sys account to enter sqlplus and run the script awrrpt.sql to generate an AWR report for the entire database.

SQL> @$ORACLE_HOME/rdbms/admin/awrrpt.sql

Require:

1) The file format of the output report is html

2) The number of reported monitoring days is 1 day

3) The starting snapshot number and ending snapshot number for the report contain up to 5 latest snapshots

After the AWR report is generated, exit sqlplus, use a browser to open the AWR report file generated in the current directory, view and take screenshots to record the report data that reflects the current database performance.

 

Figure 14 AWR report

Since the AWR report is too long, not all results are listed. Only some key indicators are attached above.

5. Experimental conclusions and questions

1. Create a database account named after yourself and grant operation permissions to the table. You can query, update, delete and other operations on the table data. After the operation is completed, revoke the operation permissions to the table and try again. Repeat the previous operation for the table data. Screenshot recordsall operation commands and their results.

Figure 15 Create a database with your own name and grant permissions

Then query:

 

 

Figure 16 Query results

Query after revoking permissions.

Picture17 Recycling permissions

 

 

Figure 18 Screenshot of query after permission recovery

2. Analyze the report data reflecting the current database performance in the Oracle AWR report (file awrrpt_1_51326_51330.html) to determine whether there is a performance bottleneck in the current database and the options that need to be optimized for the current database.

The AWM report teacher will send

 

1ELAPSEDDB TIME

DB TIME=CPU TIME+WAIT TIME

DB TIME>ELAPSED indicates that the database is relatively busy. For example, DB TIME<ELAPSED indicates that the database is relatively idle.

If the database is busy.

CPU的负载程度可以使用下面公式:

CPU负载=DB TIME/(CPU数*ELAPSED)*100% 计算

2Load Profile (REDO SIZELOGICAL READSHARD PARSESROLLBACK)

 

 

Redo size:每秒/每事务产生的redo大小(单位字节),可标志数据库任务的繁重程序。其中Per Second表示每秒中产生的redo的字节数,Per Transaction表示每个事务产生的redo的字节数,可以通过后者可以看到事务的大小,协助判断是否commit次数太多。例如per second很大,而per transaction很小,说明commit次数太多。通常在很繁忙的系统中日志生成量可能达到上百k,甚至几百k。

Logical reads:每秒/每事务逻辑读的块数(我们可以这样认为,block在内存中,我们每一次读一块内存,就相当于一次逻辑读),单位为块。

Executes:每秒/每事务SQL执行次数,包括用户执行的sql语句与系统执行的sql语句,表示一个系统SQL的繁忙程度。

Logical reads/Executes不会超过50,一般只有10左右。

Hard parses:其中硬解析的次数,如果硬解析次数太高,说明SQL重用率不高。例如超过100,基本都是由于不使用绑定变量所导致的,导致CPU使用率的问题,极有使得性能急剧下降。

Rollbacks:表示数据库中事务的回退率,如果不是因为业务本身的原因,通常应该小于10%为好,回退是一个很消耗资源的操作。

 3、内存命中率相关指标

 

 

首先看整个实例的命中率,普通应用系统应该在90%以上。

Buffer Nowait% :表示在数据缓冲区中获取buffer时,未进行等待的比率,越高越好。

buffer hit% :表示进程从内存中找到数据块的比率,监视这个值是否发生重大变化比这个值本身更重要。对于一般系统,命中率通常在95%以上,如果此值低于80%,应该给数据库分配更多的内存,考虑加大db_cache_size。

Redo NoWai%t表示在LOG缓冲区获得BUFFER的未等待比例。如果太低(可参考90%阀值),考虑增加LOG BUFFER。

library hit%表示Oracle从Library Cache中检索到一个解析过的SQL或PL/SQL语句的比率,当应用程序调用SQL或存储过程时,Oracle检查Library Cache确定是否存在解析过的版本,如果存在,Oracle立即执行语句;如果不存在,Oracle解析此语句,并在Library Cache中为它分配共享SQL区。低的library hit ratio会导致过多的解析,增加CPU消耗,降低性能。Sql语句在库缓冲中能否找到相应的解析计划,如果library hit ratio低于90%,可能需要调大shared pool区,或检查是否有硬编码现象。

Latch Hit%:Latch是一种保护内存结构的锁,可以认为是SERVER进程获取访问内存数据结构的许可,表示内部结构维护锁命中率。要确保Latch Hit>99%,否则意味着Shared Pool latch争用,可能由于未共享的SQL,或者Library Cache太小,可使用绑定变更或调大Shared Pool解决。

Parse CPU to Parse Elapsd:表示解析实际运行时间/(解析实际运行时间+解析中等待资源时间),越高越好。在实际繁忙的系统中,该值可能因为等待资源而不会太高。

Non-Parse CPU :SQL实际运行时间/(SQL实际运行时间+SQL解析时间),太低表示解析消耗时间过多。说明解析时间所占比率过高,需要考虑提高sql语句重用性。

Execute to Parse:是语句执行与分析的比例,表示sql语句解析后被重复执行的命中率,计算公式=100*(1-Parses/Executions),如果该值偏小,说明分析(硬分析和软分析)的比例较大,快速分析较少,根据实际情况,可以考虑调整session_cached_cursors参数,有些报告中这个值是负的,看上去很奇怪,事实上这表示一个问题,sql如果被age out的话就可能出现这种情况 ,也就是sql老化,执行alter system flush shared_pool如果要SQL重用率高,则这个比例会很高。该值越高表示一次解析后被重复执行的次数越多。

Soft Parse%:

Soft Parse%:软解析的百分比(softs/softs+hards),近似当作SQL在共享区的命中率,SQL语句软解析占整个分析的命中率,如果低于95,需检查是否有硬编码现象,如果低于80,说明SQL语句基本没有重用性=soft/(soft+hard)。太低则需要调整应用使用绑定变量。

In-memory Sort:在内存中排序的比率,即有多少排序在内存中进行的,如果过低说明有大量的排序在临时表空间中进行,性能肯定不好,考虑调大PGA参数,sort_area_size。

 4、共享内存池总体情况

 

Memory Usage %:表示共享池内存使用率,对于一个已经运行一段时间的数据库来说,共享池内存使用率,应该稳定在75%-90%间,如果太小,说明Shared Pool有浪费,而如果高于90,说明共享池中有争用,内存不足。

SQL with executions>1:执行次数大于1的SQL比率,如果此值太小的话要结合Parse,看看是不是硬编码现象,说明需要在应用中更多使用绑定变量,避免过多SQL解析。

Memory for SQL w/exec>1:执行次数大于1的SQL消耗内存的占比。

5、前5/10个等待时间最长的事件

  

通常排序前几位的事件有如下几个:

db file scattered read等待事件是当SESSION等待multi-block I/O时发生的,通常是由于full table scans或 index fast full scans。如果在一般系统中,不应该有过多的全扫描操作,而应使用选择性好的索引操作。

db file sequential read等待意味着发生顺序I/O读等待(通常是单块读取到连续的内存区域中),如果这个等待非常严重,应该使用上一段的方法确定执行读操作的热点SEGMENT,然后通过对大表进行分区以减少I/O量,或者优化执行计划(通过使用存储大纲或执行数据分析)以避免单块读操作引起的sequential read等待。通过在批量应用中,DB file sequential read是很影响性能的事件,总是应当设法避免。

Log File Parallel Write事件是在等待LGWR进程将REDO记录从LOG 缓冲区写到联机日志文件时发生的。虽然写操作可能是并发的,但LGWR需要等待最后的I/O写到磁盘上才能认为并行写的完成,因此等待时间依赖于OS完成所有请求的时间。如果这个等待比较严重,可以通过将LOG文件移到更快的磁盘上或者条带化磁盘(减少争用)而降低这个等待。

Buffer Busy Waits事件是在一个SESSION需要访问BUFFER CACHE中的一个数据库块而又不能访问时发生的。缓冲区“busy”的两个原因是:1)另一个SESSION正在将数据块读进BUFFER。2)另一个SESSION正在以排它模式占用着这块被请求的BUFFER。

Log File Sync事件,当用户SESSION执行事务操作(COMMIT或ROLLBACK等)后,会通知 LGWR进程将所需要的所有REDO信息从LOG BUFFER写到LOG文件,在用户SESSION等待LGWR返回安全写入磁盘的通知时发生此等待。

Enqueue Waits是串行访问本地资源的本锁,表明正在等待一个被其它SESSION(一个或多个)以排它模式锁住的资源。减少这种等待的方法依赖于生产等待的锁类型。导致Enqueue等待的主要锁类型有三种:TX(事务锁), TM D(ML锁)和ST(空间管理锁)。

enq:TX-index contention是索引分割事件。当事务修改索引中的数据时,而相关索引块没有足够的空间的时候,就会发生索引块的分割,在分割的过程中前台进程需要等待分割完毕才能继续操作。如果这个时候其他会话也要修改这个索引块的数据,那么将会出现索引块的竞争。一般索引块的分割持有资源和释放非常短,并不会对数据库造成严重的影响。但是对表操作并发量很大的情况下可能导致严重的竞争。

buffer exterminate等待事件通常发生SGA自动管理内存组件的时候。是当buffer cache中的部分空间正进行动态回缩时,有会话试图访问buffer cache中被选择空间释放的granule中的data block时,就会发生buffer exterminate等待。当buffer被释放(比如从buffer cache hash chain,LRU chain上移除)后,等待的会话就能够重载该block到剩余的一个db cache granule中去,然后其他会话就可以通过hash查找找到新的该block的buffer address。

六、总结及心得体会

实验中遇到的问题以及解决办法:

1.在一开始进入Oracle数据库进行操作的时候,进入sqlplus之后也要先启动数据库,才能正常进行命令的输入;

2. expdp备份scott用户的所有表和所有数据时候,一开始会出现错误,如下:

图19 错误截图

 

解决方案:

图20 解决方案

 

3.在最后生成AWR报告时候,快照起始和结束要连续。

七、对本实验过程及方法、手段的改进建议

1. 在expdp 备份 scott用户的所有表和所有数据的时候,可能会出现报错,实验指导书可以指明一下。

2.对快照的ID进行一些说明,防止学生在进行到输入快照的那一步出错,不知如何解决。

Guess you like

Origin blog.csdn.net/weixin_53284122/article/details/129219972