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

 找回密码
 注册

QQ登录

只需一步,快速开始

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

[认证考试] OCP课程43:管理II之恢复配置

[复制链接]
跳转到指定楼层
楼主
发表于 2016-3-1 17:54:40 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

课程目标:

  • 调用和配置RMAN
  • 配置数据库归档模式
  • 配置多个归档日志文件地址
  • 配置快速恢复区(FRA)
  • 指定保留策略

1、备份和恢复目的

备份和恢复的目的是还原有问题的数据库。恢复由于硬件固执、介质故障、用户错误及程序错误导致数据库问题。还可以将数据恢复到过去的某一个时间点。还可以移动数据。


2、典型的备份恢复任务

使用最少的时间从数据丢失的数据库恢复,需要:

  • Configuration:需要配置备份和恢复策略,包括备份方法,备份目的地,备份保留时间等等
  • Scheduling:设置在非工作时间自动运行
  • Testing:定期进行备份和恢复测试
  • Monitoring:监控备份操作运行情况对数据库的影响
  • Restoration:使用备份的数据文件覆盖有问题的数据文件
  • Recovery:使用归档和联机重做日志,对数据块应用重做条目到前滚到最后一次提交的事务

3、备份和恢复解决方案

RMAN特性:

  • Block media recovery:恢复指定的数据块
  • Unused block compression:没有使用的块不会被备份和恢复
  • Binary compression:使用常用的压缩算法进行压缩节约磁盘空间
  • Backup encryption:保护数据

备份类型:

  • Full backup:全备,备份数据文件中包含数据的所有数据块
  • Incremental backup:增备,只备份上次备份后修改过的数据块。支持2种级别的增量备份(0和1),1级增量备份分类cumulative和differential两种,cumulative(累积)备份上一次0级备份后修改过的数据块,differential(差异)备份上一次增量备份(0和1)后修改过的数据块

4、备份解决方案

RMAN备份数据文件,控制文件,重做日志归档文件和服务器参数文件。可以备份成备份集或者镜像拷贝。可以备份到磁盘,可以借助类似Oracle Secure Backup的media management layer(MML)备份到磁带。

OSB是一款包括文件系统和数据库的Oracle环境集中磁带管理软件。既可以备份和恢复本地的数据还可以是网络上面的数据。


5、术语回顾

Correct Answers: 1P, 2C, 3F, 4O, 5W


6、术语回顾

Correct Answers: 1B, 2A


7、Oracle-Suggested Backup

Oracle-Suggested Backup使用增量备份。先做一个全库的0级备份,然后每天做一个增量备份。至少可以回到24小时之前的状态。


8、使用RMAN

启动rman可以使用以下选项:

target:指定连接到目标数据块,"/"表示连接到本地数据库,使用操作系统认证

catalog:指定连接到恢复目录

nocatalog:不使用恢复目录,默认选项

cmdfile:指定命令文件

log:指定日志文件

例子:rman连接到本地数据块,使用操作系统认证,指定命令文件和日志文件

$ rman target / cmdfile=~/fullbu.rman log=~/fullbu.log


9、RMAN命令类型

RMAN命令有2种基本类型:

  • stand-alone:在rman提示符后面输入
  • job commands:run命令块中的一组命令,其中有一条命令执行失败,则rman停止处理,前面执行成功的命令不撤销,例如allocate channel命令只能在run块中运行,为当前执行的job分配通道。

10、Job Commands:例子

job commands必须都位于run块中,使用大括号括起来,run块中的配置只影响当前块的执行,覆盖之前的配置。必须位于run块中的命令有:

  • allocate channel
  • switch

11、为备份和恢复操作配置数据库

将数据库配置为归档模式。

配置FRA。


12、归档模式

数据库数据被修改时重做数据会被写入到联机重做日志文件,当写满后,归档进程复制联机重做日志文件到归档位置进行保存。因为联机重做日志文件是循环写入,在归档模式下,只能向已经归档的联机重做日志文件进行写入,确保每个联机重做日志文件都会被归档。


13、配置归档模式

使用EM也可以使用SQL。需要数据库处于mount状态。且必须干净关闭(不能使用abort)。

使用SQL步骤如下:

SQL> archive log list;

Database log mode              No Archive Mode

Automatic archival             Disabled

Archive destination            USE_DB_RECOVERY_FILE_DEST

Oldest online log sequence     173

Current log sequence           175

SQL> shutdown immediate

Database closed.

Database dismounted.

ORACLE instance shut down.

SQL> startup mount

ORACLE instance started.

Total System Global Area  889389056 bytes

Fixed Size                  2258360 bytes

Variable Size             662702664 bytes

Database Buffers          218103808 bytes

Redo Buffers                6324224 bytes

Database mounted.

SQL> alter database archivelog;

Database altered.

SQL> alter database open;

Database altered.

SQL> archive log list;

Database log mode              Archive Mode

Automatic archival             Enabled

Archive destination            USE_DB_RECOVERY_FILE_DEST

Oldest online log sequence     173

Next log sequence to archive   175

Current log sequence           175

  • 当数据库处于NOARCHIVELOG模式(默认),只能恢复到最后一次备份的时刻,之后的事务都将丢失。
  • 当数据库处于ARCHIVELOG模式,可以恢复到最后一次提交的时刻,大多数生产数据库都运行中归档模式。

注意:切换到归档模式后需要对数据库进行一次备份。


14、配置归档日志位置

Oracle建议指定多个归档位置,因为如果只有1个且空间不足的话,数据库会hang住。

Oracle建议通过设置log_archive_dest_n初始化参数指定本地和远程归档位置,可以指定10个,n从1到10。

  • 如果指定本地位置,使用"location=",后面跟本地目录,例如log_archive_dest_1='location=/disk3/arch'
  • 如果指定备库远程位置,使用"service=",后面跟备库实例的网络服务名,例如log_archive_dest_2='service=standy1'

如果是Oracle标准版,则只能设置log_archive_dest和log_archive_duplex_dest这两个初始化参照指定2个本地磁盘目录作为归档位置。


15、保证归档日志成功

如果指定了不止一个归档位置,则需要设置log_archive_min_succeed_dest初始化参数指定必须归档成功的最小数量。如果归档成功的数量不满足设置,则联机重做日志文件不能重用。

上图中3个归档位置,2个本地,1个远程,log_archive_min_succeed_dest设置为2,意味着只要有2个位置归档成功,就可以重用联机重做日志文件,即使有1个失败了,也不会影响数据库的正常运行。

如果使用了log_archive_dest_n参数设置归档位置,根据n的大小,则log_archive_min_succeed_dest可以从1到10,如果使用了log_archive_dest,则log_archive_min_succeed_dest只能为1或者2。

可以使用mandatory或者optional,指定归档位置是必须归档还是可选归档(默认),例如:

log_archive_dest_1='location=/disk3/arch mandatory'

如果必须归档位置归档失败,则联机重做日志文件不能重用,忽略log_archive_min_succeed_dest的设置。

log_archive_dest初始化参数指定的归档位置是必须归档的位置。

SQL> show parameter log_archive_min_succeed_dest

NAME                                 TYPE        VALUE

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

log_archive_min_succeed_dest         integer     1


16、指定保留策略

使用保留策略设置备份可以保留多久。可以通过rman的configure命令或者EM进行配置。

恢复窗口保留策略:

用于恢复出现在一段时期内的逻辑错误,将错误的对象恢复到某个时间点,这一段时期称为恢复窗口。指定恢复窗口为多少天,备份必须满足以下条件:

SYSDATE – backup_checkpoint_time >= recovery_window

可以使用下面的命令语法配置恢复窗口保留策略:

RMAN> CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF DAYS;

如果没有使用恢复目录,那么恢复窗口需要小于等于控制文件记录保留时间参数control_file_record_keep_time指定的值,避免写入控制文件中的备份信息被覆盖掉而失效。如果使用了恢复目录,需要确保control_file_record_keep_time大于恢复目录同步时间,同步发生在:

  • 创建一个备份,会自动进行隐式同步
  • 执行resync catalog命令

冗余保留策略:

用于指定保留多少份备份。默认为1,表示任何时间都必须有一份备份,超过1份后老的备份会被标记为过期。使用下面的命令配置冗余保留策略:

RMAN> CONFIGURE RETENTION POLICY TO REDUNDANCY ;

禁用保留策略:

如果使用了其他的备份软件管理备份,可以禁用保留策略,使用如下命令:

RMAN> CONFIGURE RETENTION POLICY TO NONE;


17、恢复窗口保留策略:例子

上图中的保留策略要求恢复到过去7天内的任何时间。不需要用于7天窗口恢复的备份和日志已经过期。保留策略配置如下:

RMAN> CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 7 DAYS;

用于恢复到恢复窗口中的指定时间点所需要的数据仅包括Backup B和Log201到Log500之间的某些日志。由于Backup B位于恢复窗口之前,则之前的Backup A就不需要了,如果只有备份C,则不能恢复到恢复窗口开始的时间点。需要的是备份窗口开始之前的最后的备份以及之后的所有日志。


18、使用快速恢复区

快速恢复区是所有与恢复相关的文件的一个统一位置。包括2种类型的文件:永久的和临时的。

永久类型有:

  • 控制文件:根据初始化参数设置,在创建数据库的时候会在快速恢复区创建一个控制文件副本
  • 联机重做日志文件副本:在创建数据库的时候,通过logfile语句指定联机重做日志文件位置,如果没有使用logfile语句,则通过以下参数指定:
    • db_create_online_log_dest_n:如果指定了一个或者多个,则仅使用该位置
    • db_create_file_dest:创建文件的首选位置
    • db_recovery_file_dest:快速恢复区位置

临时类型:

  • 归档日志文件:如果配置了快速恢复区,则log_archive_dest_1自动设置为快速恢复区。
  • 闪回日志:启动闪回数据库会产生闪回日志
  • 控制文件自动备份:rman自动备份控制文件时,默认位置为快速恢复区
  • 数据文件拷贝:使用backup as copy命令创建数据文件镜像拷贝到快速恢复区
  • rman文件:使用rman进行备份的默认位置

19、定义快速恢复区

定义快速恢复区需要设置下面参数:

  • db_recovery_file_dest_size:设置快速恢复区最大可用空间,建议至少为数据库的大小,最小至少要可以存放还没有备份到磁带的归档日志文件,根据备份策略和恢复要求进行调整
  • db_recovery_file_dest:指定位置

20、快速恢复区管理

当快速恢复区可用空间过小,且没有文件可以被删除,就会发出警告,但rman仍旧会在快速恢复区创建备份,直到快速恢复区占满到100%。所以需要设置db_recovery_file_dest_size为合适的值来存放备份。

当写入到快速恢复区的文件请求空间时,会删除在过期列表中的文件,并将信息写入的告警日志。

当快速恢复区使用到85%,则会发出告警,使用到97%,则会发出严重告警,这是系统内部设置,不能更改。告警示例如下:

WARNING: db_recovery_file_dest_size of 52428800 bytes is 100.00% used, and has 0 remaining bytes available.

可以通过dba_outstanding_alerts数据字典查询告警信息以及建议:

SQL> select object_type,message_type,message_level,reason,suggested_action

  2  from dba_outstanding_alerts;

OBJECT_TYPE     MESSAGE_TYPE MESSAGE_LEVEL REASON                                             SUGGESTED_ACTION

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

TABLESPACE      Warning                  5 Tablespace [INVENTORY] is [90 percent] full        Add space to the tablespace

TABLESPACE      Warning                  1 Tablespace [TBS_03] is [100 percent] full          Add space to the tablespace

如果快速恢复区满了,可以选择增加磁盘空间,备份文件到另外的地方,使用rman删除快速恢复区的文件或者修改rman的保留策略。


21、快速恢复区空间使用

为避免快速恢复区空间不足,可以使用如下建议:

  • 使用rman删除不必要的文件
  • 使用rman备份快速恢复区
  • 修改rman保留策略到最小值
  • 修改rman归档日志删除策略
  • 增加磁盘空间,增大db_recovery_file_dest_size

不要把不受rman管理的文件放到快速恢复区,如果不是使用rman删除快速恢复区的文件,需要再使用rman删除对应的记录(crosscheck和delete)回收空间。例如备份了归档日志文件后,要删除这些已经成功备份了的归档日志文件,可以使用以下rman命令:

BACKUP ARCHIVELOG ALL DELETE ALL INPUT;

配置归档日志删除策略

使用CONFIGURE ARCHIVELOG DELETE POLICY命令对所有归档位置配置删除策略。

归档日志可以被数据库自动删除也可以通过发出rman命令进行删除:

  • 只有在快速恢复区的归档日志才可以被数据库自动删除
  • 使用BACKUP ... DELETE INPUT或者DELETE ARCHIVELOG手动删除任何位置的归档日志
  • 默认是CONFIGURE ARCHIVELOG DELETION POLICY TO NONE

22、自动执行

当使用了类似流的多个组件的时候,简化了归档日志的管理,提供了可用性。

当如Data Guard,Streams,Flashback Database等不再需要归档日志了,才会被删除。

当配置归档删除规则,对所有的归档位置有效,包括FRA。BACKUP ... DELETE INPUT和DELETE ... ARCHIVELOG都会使用该规则。

当备份快速恢复区时,此时快速恢复区不能访问,此时备份归档日志只能备份到其他位置。


23、监控FRA

例子:通过V$FLASH_RECOVERY_AREA_USAGE视图查看快速恢复区使用情况

SQL> SELECT * FROM V$FLASH_RECOVERY_AREA_USAGE;

FILE_TYPE            PERCENT_SPACE_USED PERCENT_SPACE_RECLAIMABLE NUMBER_OF_FILES

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

CONTROL FILE                        .25                         0               1

REDO LOG                           3.79                         0               3

ARCHIVED LOG                      10.84                      5.67              12

BACKUP PIECE                      34.13                     23.69              10

IMAGE COPY                            0                         0               0

FLASHBACK LOG                         0                         0               0

FOREIGN ARCHIVED LOG                  0                         0               0

7 rows selected.

例子:通过EM查看快速恢复区度量


24、使用快速恢复区的好处

简化备份的管理。

Oracle推荐使用快速恢复区自动管理备份文件的磁盘空间分配。


25、相关习题

(1)You are using the flash recovery area (fast recovery area in 11g Release 2) to store backup related files in your database. After regular monitoring of space usage in the flash recovery area. You realize that the flash recovery area is (jetting filled up very fast and it is running out of space. Your database flash recovery area is low on specie and you have no more room on disk. Proactively, which two options could you use to make more space available in the flash recovery [Choose two]

A.

Change the RMAN archived log deletion policy.

B.

Use the RMAN CROSSCHECK command to reclaim the archived log space.

C.

Change the RMAN retention policy to retain backups for a shorter period of time.

D.

Use OS command to move files from the flash recovery area to some other location

答案:BD

(2) You want to set the following initialization parameters for your database instance:

LOG_ARCHIVE_DEST_1 = 'LOCATION=/disk1/arch'

LOG_ARCHIVE_DEST_2 = 'LOCATION=/disk2/arch'

LOG_ARCHIVE_DEST_3 = 'LOACTION=/disk3/arch'

LOG_ARCHIVE_DEST_4 = 'LOCATION=/disk4/arch MANDATORY'

Identify the statement that correctly describes this setting.

A.  The MANDATORY location must be a flash recovery area.

B.  The optional destinations may not use the flash recovery area.

C.  This setting is not allowed because the first destination is not set as MANDATORY.

D.  The online redo log file is not allowed to be overwritten if the archived log cannot be created in the fourth destination.

答案:D

(3)You have configured flash recovery area in your database and you set the following Initialization parameters for your database instance:

LOG_ARCHIVE_DEST 1 = ,,LOCATION=/disk1/arch MANDATORY'

LOG _ARCHIEVE_DEST 2 = ,,LOCATION=/disk2/arch'

LOG_ARCHIVK_DEST_3 = ,,LOCATION=/diSk3/arch

LOG_ARCH1VK_DEST_4 = ' LOCATION=/disk4/arch'

LOG_ARCHIVE_MIN-SUCCEED_DEST = 2

While the database instance is functional, you realized that the destination set by the LOG_ARCHIVE_DEST_I parameter is not available for the archived redo log file to be created in. All redo log groups have been used. What happens in an event of log switch?

A.  The online redo log file is not allowed to be overwritten.

B.  The archived redo log files are written to the flash recovery area until the MANDATORY destination is made available.

C.  The database instance will crash because the archived redo log file cannot be created in a destination set as MANDATORY.

D.  The destination set by the LOG_ARCHIVE_DEST_1 parameter is ignored and the archived redo log files are created in the next two available locations to guarantee archive log success.

答案:A

(4)Which of the following parameters defines the location where Oracle should create archived redo logs?

A.  LOG_ARCHIVE_1

B.  LOG_DESTINATION_1

C.  LOG_ARCHIVED_DESTINATION_1

D.  LOG_ARCHIVE_DEST_1

E.  LOG_ARCHIVE_SOURCE_1

答案:D

(5)Archived redo logs can be copied to more than one destination by Oracle.

A.  True

B.  False

答案:A

(6)What will be the result of the following configuration?

Log_archive_dest_1=location=c:\oracle\arch\mydb

Log_archive_dest_2=location=z:\oracle\arch\mydb

A.  An error will occur during database startup because the second parameter is not valid.

B.  An error will occur during database startup since you are trying to create archived redo logs intwo different locations.

C.  Archived redo logs will be created in two different locations by the ARCH process.

D.  Archived redo logs will be created in two different locations by the LGWR process.

E.  Neither parameter setting is valid, so the database will not start up.

答案:C

(7)If you issue the command shutdown abort prior to trying to put the database in ARCHIVELOG mode, what will be the result when you issue the command alter database archivelog?

A.  The alter database archivelog command will fail.

B.  The alter database archivelog inconsistent command must be used to put the database in ARCHIVELOG mode.

C.  The alter database archivelog command will succeed.

D.  The alter database archivelog command will ask if you want to make the database consistent first.

E.  There is no alter database archivelog command. The correct command is alter database alterlogging.

答案:A

(8)Your archive-log destination directory runs out of space. What is the impact of this on the database?

A.  None. The database will switch over to the stand-by archive-log destination directory.

B.  A warning message will be written to the alert log of the database, but no adverse impacts to the database will be experienced.

C.  The database will shut down, and will not restart until you correct the out-of-space situation.

D.  The database will continue to try to write to the archive-log destination directory for one hour.

After one hour, the database will shut down normally.

E.  Once Oracle has cycled through all online redo logs, it will stop processing any DML or DDL until the out-of-space condition is corrected.

答案:E

(9)How many individual archive-log destination directories are supported by Oracle Database11g?

A.  7

B.  1

C.  10

D.  11

E.  21

答案:C

(10)You want to use the automatic management of backup and recovery operations features for your database.

Which configuration must you set?

A.  Enable the flash recovery area and specify it as the archived redo log destination.

B.  Disable the flash recovery area and start the database instance in ARCHIVELOG mode.

C.  Enable the flash recovery area but do not specify it as the archived redo log destination.

D.  Disable the flash recovery area and start the database instance in NOARCHIVELOG mode.

答案:A

(11)Which three types of files can be automatically placed in the flash recovery area (fast recovery area in 11g Release 2)?  (Choose three.)

A.  Alert log file

B.  Archived redo log files

C.  Control file autobackups

D.  Server Parameter file (SPFILE)

E.  Recovery Manager (RMAN) backup piece

答案:BCE

(12)While Monitoring the space usage in your database that is in ARCHIVELOG mode you observed that the flash recovery area does not have enough free space to accommodate any more files and you do not have necessary permissions to add more space to it.

Identify the two events that can occur in the event of a log switch? (Choose two.)

A.  An entry is created in the alert log file and the database instance continues to function normally

B.  The log switch hangs occur for transactions until free space is available in the flash recovery area

C.  The Oracle database server deletes a file that is on the obsolete file list to make free space in the flash recovery area

D.  The database instance status is implicitly changed to RESTRICTED mode and file creations to the flash recovery area are prevented

答案:BC

(13)Which options would you consider while configuring a flash recovery area (fast recovery area in 11g Release 2) for your production database that is running in ARCHIVELOG mode? (Choose all that apply.)

A.  Setting the FAST_START_MTTR_TARGET to set the mean time to recover

B.  Setting the RECOVERY_PARALLELISM parameter to twice the number of CPUs

C.  Using the DB_RECOVERY_FILE_DEST parameter to set the location for flash recovery area

D.  Using the DB_RECOVERY_FILE_DEST_SIZE parameter to define the disk space limit for the recovery files created in the flash recovery area

答案:CD


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

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-5-7 23:37 , Processed in 0.093802 second(s), 20 queries .

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

© 2001-2020

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