zoukankan      html  css  js  c++  java
  • oracle 03-14 执行数据库恢复

    Performing Database Recovery

    [root@yf ~]# su - oracle
    上一次登录:六 6月 27 16:02:16 CST 2020pts/1 上
    [oracle@yf ~]$ export DISPLAY=:0.0
    [oracle@yf ~]$ . oraenv
    ORACLE_SID = [oracle] ? orcl
    The Oracle base has been set to /u01/app/oracle
    [oracle@yf ~]$ rman target /      恢复备份工具rman是recovery manager的缩写

    Recovery Manager: Release 18.0.0.0.0 - Production on Sat Jun 27 16:03:44 2020
    Version 18.3.0.0.0

    Copyright (c) 1982, 2018, Oracle and/or its affiliates. All rights reserved.

    connected to target database: ORCL (DBID=1568463734)

    RMAN> show all;

    using target database control file instead of recovery catalog
    RMAN configuration parameters for database with db_unique_name ORCL are:
    CONFIGURE RETENTION POLICY TO REDUNDANCY 1; # default
    CONFIGURE BACKUP OPTIMIZATION OFF; # default
    CONFIGURE DEFAULT DEVICE TYPE TO DISK; # default
    CONFIGURE CONTROLFILE AUTOBACKUP ON; # default
    CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '%F'; # default
    CONFIGURE DEVICE TYPE DISK PARALLELISM 1 BACKUP TYPE TO BACKUPSET; # default
    CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
    CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
    CONFIGURE MAXSETSIZE TO UNLIMITED; # default
    CONFIGURE ENCRYPTION FOR DATABASE OFF; # default
    CONFIGURE ENCRYPTION ALGORITHM 'AES128'; # default
    CONFIGURE COMPRESSION ALGORITHM 'BASIC' AS OF RELEASE 'DEFAULT' OPTIMIZE FOR LOAD TRUE ; # default
    CONFIGURE RMAN OUTPUT TO KEEP FOR 7 DAYS; # default
    CONFIGURE ARCHIVELOG DELETION POLICY TO NONE; # default
    CONFIGURE SNAPSHOT CONTROLFILE NAME TO '/u01/app/oracle/product/18c/dbs/snapcf_orcl.f'; # default

    RMAN> backup database plus archivelog;    (运行backup database plus archivelog,的运行步骤是;

       1.alter system archive log current;  归档当前日志
       2.backup archivelog all;        备份所有归档日志
       3.backup database;          备份数据库
       4.alter system archive log current;  归档当前日志
       5.backup archivelog recently generated ;   备份刚生成的归档日志

    Starting backup at 27-JUN-20
    current log archived
    allocated channel: ORA_DISK_1
    channel ORA_DISK_1: SID=274 device type=DISK
    channel ORA_DISK_1: starting archived log backup set
    channel ORA_DISK_1: specifying archived log(s) in backup set
    input archived log thread=1 sequence=26 RECID=1 STAMP=1044134510
    input archived log thread=1 sequence=27 RECID=2 STAMP=1044134923
    input archived log thread=1 sequence=28 RECID=3 STAMP=1044203984
    channel ORA_DISK_1: starting piece 1 at 27-JUN-20
    channel ORA_DISK_1: finished piece 1 at 27-JUN-20
    piece handle=/u01/app/oracle/fast_recovery_area/ORCL/ORCL/backupset/2020_06_27/o1_mf_annnn_TAG20200627T163944_hhg1gk43_.bkp tag=TAG20200627T163944 comment=NONE
    channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
    Finished backup at 27-JUN-20

    Starting backup at 27-JUN-20
    using channel ORA_DISK_1   归档日志
    channel ORA_DISK_1: starting full datafile backup set
    channel ORA_DISK_1: specifying datafile(s) in backup set
    input datafile file number=00003 name=/u01/app/oracle/oradata/ORCL/sysaux01.dbf    数据文件
    input datafile file number=00001 name=/u01/app/oracle/oradata/ORCL/system01.dbf
    input datafile file number=00004 name=/u01/app/oracle/oradata/ORCL/undotbs01.dbf
    input datafile file number=00005 name=/u01/app/oracle/oradata/ORCL/inventory03.dbf
    input datafile file number=00008 name=/u01/app/oracle/oradata/ORCL/undotbs02.dbf
    input datafile file number=00002 name=/u01/app/oracle/oradata/ORCL/inventory02.dbf
    input datafile file number=00007 name=/u01/app/oracle/oradata/ORCL/users01.dbf
    channel ORA_DISK_1: starting piece 1 at 27-JUN-20
    channel ORA_DISK_1: finished piece 1 at 27-JUN-20
    piece handle=/u01/app/oracle/fast_recovery_area/ORCL/ORCL/backupset/2020_06_27/o1_mf_nnndf_TAG20200627T163946_hhg1gln4_.bkp tag=TAG20200627T163946 comment=NONE
    channel ORA_DISK_1: backup set complete, elapsed time: 00:00:35
    Finished backup at 27-JUN-20

    Starting backup at 27-JUN-20
    current log archived
    using channel ORA_DISK_1
    channel ORA_DISK_1: starting archived log backup set
    channel ORA_DISK_1: specifying archived log(s) in backup set
    input archived log thread=1 sequence=29 RECID=4 STAMP=1044204021
    channel ORA_DISK_1: starting piece 1 at 27-JUN-20
    channel ORA_DISK_1: finished piece 1 at 27-JUN-20
    piece handle=/u01/app/oracle/fast_recovery_area/ORCL/ORCL/backupset/2020_06_27/o1_mf_annnn_TAG20200627T164021_hhg1hp1s_.bkp tag=TAG20200627T164021 comment=NONE
    channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
    Finished backup at 27-JUN-20

    Starting Control File and SPFILE Autobackup at 27-JUN-20
    piece handle=/u01/app/oracle/fast_recovery_area/ORCL/ORCL/autobackup/2020_06_27/o1_mf_s_1044204023_hhg1hqn5_.bkp comment=NONE
    Finished Control File and SPFILE Autobackup at 27-JUN-20   控制文件

    RMAN> exit

    Recovery Manager complete.

    Objectives
    After completing this lesson, you should be able to:
    • Determine the need for performing recovery
    • Describe and use available options, such as Recovery Manager (RMAN) and the Data Recovery Advisor
    • Perform recovery:
    – Control file
    – Redo log file
    – Data file

    目标

    完成本课程后,您应该能够:

    •确定执行恢复的需要

    •描述并使用可用选项,如Recovery Manager(RMAN)和Data Recovery Advisor

    •执行恢复:

    –控制文件

    –重做日志文件

    –数据文件

    Opening a Database
    To open a database:
    • All control files must be present and synchronized
    • All online data files must be present and synchronized
    • At least one member of each redo log group must be present

    打开数据库

    打开数据库:

    •所有控制文件必须存在并同步

    •所有在线数据文件必须存在并同步

    •每个重做日志组必须至少有一个成员

    STARTUP

    SHUTDOWN
    NOMOUNT
    MOUNT
    OPEN

    关闭

    诺蒙特

    安装

    打开

    Keeping a Database Open
    After the database is open, it fails in case of the loss of:
    • Any control file
    • A data file belonging to the system or undo tablespaces
    • An entire redo log group (As long as at least one member of the group is available, the instance remains open.)

    保持数据库打开

    数据库打开后,如果丢失:

    •任何控制文件

    •属于系统或撤消表空间的数据文件

    •整个重做日志组(只要组中至少有一个成员可用,实例就保持打开状态)

    Data Recovery Advisor
    • Fast detection, analysis, and repair of failures
    • Handling of down-time and runtime failures
    • Minimizing disruptions for users
    • User interfaces:
    – Enterprise Manager Cloud Control
    – RMAN command line

    数据恢复顾问

    •快速检测、分析和修复故障

    •处理停机时间和运行时故障

    •最大限度地减少对用户的干扰

    •用户界面:

    –Enterprise Manager云控制

    –RMAN命令行

    Loss of a Control File
    If a control file is lost or corrupted, the instance normally aborts.
    • If control files are stored in ASM disk groups, recovery options are as follows:
    – Perform guided recovery using Enterprise Manager.
    – Put database in NOMOUNT mode and use an RMAN command to restore control file from existing control file.

    RMAN> restore controlfile from
    '+DATA/orcl/controlfile/current.260.695209463';


    • If control files are stored as regular file system files, then:
    – Shut down the database
    – Copy existing control file to replace lost control file
    After control file is successfully restored, open the database.

    丢失控制文件

    如果控制文件丢失或损坏,实例通常会中止。

    •如果控制文件存储在ASM磁盘组中,恢复选项如下:

    –使用Enterprise Manager执行引导恢复。

    –将数据库置于NOMOUNT模式,并使用RMAN命令从现有控制文件还原控制文件。

    •如果控制文件存储为常规文件系统文件,则:

    –关闭数据库

    –复制现有控制文件以替换丢失的控制文件

    成功还原控制文件后,打开数据库

    Loss of a Redo Log File
    If a member of a redo log file group is lost and if the group still has at least one member, note the following results:
    • Normal operation of the instance is not affected.
    • You receive a message in the alert log notifying you that a member cannot be found.
    • You can restore the missing log file by dropping the lost redo log member and adding a new member.
    • If the group with the missing log file has been archived, you can clear the log group to re-create the missing file.

    重做日志文件丢失

    如果重做日志文件组的成员丢失,并且该组至少还有一个成员,请注意以下结果:

    •不影响实例的正常运行。

    •您在警报日志中收到一条消息,通知您找不到成员。

    •您可以通过删除丢失的重做日志成员并添加新成员来还原丢失的日志文件。

    •如果丢失日志文件的组已存档,则可以清除日志组以重新创建丢失的文件。

    Loss of a Data File in NOARCHIVELOG Mode
    If the database is in NOARCHIVELOG mode and if any data file is lost, perform the following tasks:
    1. Shut down the instance if it is not already down.
    2. Restore the entire database—including all data and control files—from the backup.
    3. Open the database.
    4. Have users re-enter all changes that were made since the last backup.

    在NOARCHIVELOG模式下丢失数据文件

    如果数据库处于NOARCHIVELOG模式,并且任何数据文件丢失,请执行以下任务:

    1如果实例尚未关闭,请将其关闭。

    2从备份中还原整个数据库,包括所有数据和控制文件。

    3打开数据库。

    4让用户重新输入自上次备份以来所做的所有更改

    Loss of a Noncritical Data File in ARCHIVELOG Mode
    If a data file is lost or corrupted, and if that file does not belong to the SYSTEM or UNDO tablespace, you restore and recover the missing data file.

    ARCHIVELOG模式下非关键数据文件丢失

    如果数据文件丢失或损坏,并且该文件不属于系统或撤消表空间,则可以还原和恢复丢失的数据文件。

    Loss of a System-Critical Data File in ARCHIVELOG Mode

    If a data file is lost or corrupted, and if that file belongs to the SYSTEM or UNDO tablespace, perform the following tasks:
    1. The instance may or may not shut down automatically. If it does not, use SHUTDOWN ABORT to bring the instance down.
    2. Mount the database.
    3. Restore and recover the missing data file.
    4. Open the database.

    在ARCHIVELOG模式下丢失系统关键数据文件

    如果数据文件丢失或损坏,并且该文件属于系统或撤消表空间,请执行以下任务:

    1实例可能会自动关闭,也可能不会自动关闭。如果没有,请使用SHUTDOWN ABORT关闭实例。

    2装入数据库。

    3还原并恢复丢失的数据文件。

    4打开数据库。

    SQL> desc hr.instance_test
    Name Null? Type
    ----------------------------------------- -------- ----------------------------
    EMPLOYEE_ID NUMBER(6)
    FIRST_NAME VARCHAR2(20)
    LAST_NAME NOT NULL VARCHAR2(25)
    EMAIL NOT NULL VARCHAR2(25)
    PHONE_NUMBER VARCHAR2(20)
    HIRE_DATE NOT NULL DATE
    JOB_ID NOT NULL VARCHAR2(10)
    SALARY NUMBER(8,2)
    COMMISSION_PCT NUMBER(2,2)
    MANAGER_ID NUMBER(6)
    DEPARTMENT_ID NUMBER(4)

    SQL> select count(*) from hr.instance_test;

    COUNT(*)
    ----------
    107

    SQL> select tablespace_name from dba_tables where table_name='INSTANCE_TEST';

    TABLESPACE_NAME
    ------------------------------
    INVENTORY

    [oracle@yf ~]$ cd /u01/app/oracle/oradata/ORCL/
    [oracle@yf ORCL]$ ls
    control01.ctl inventory03.dbf redo01.log redo03.log system01.dbf undotbs01.dbf users01.dbf
    inventory02.dbf redo01_b.log redo02.log sysaux01.dbf temp01.dbf undotbs02.dbf

    [oracle@yf ORCL]$ rm inventory02.dbf    删除inventory02 下面尝试修复

    [oracle@yf ORCL]$ rman target /

    Recovery Manager: Release 18.0.0.0.0 - Production on Sat Jun 27 17:39:45 2020
    Version 18.3.0.0.0

    Copyright (c) 1982, 2018, Oracle and/or its affiliates. All rights reserved.

    connected to target database: ORCL (DBID=1568463734)

    RMAN> list failure;

    using target database control file instead of recovery catalog
    Database Role: PRIMARY

    no failures found that match specification

    SQL> conn / as sysdba
    Connected.
    SQL> select* from instance_test;
    select* from instance_test
    *
    ERROR at line 1:
    ORA-00942: table or view does not exist    此时查询该表,已经失败了。此时用hr登陆,能查询该表,但已经不能insert into了

    SQL> conn hr/hr
    Connected.
    SQL> select* from instance_test;

    RMAN> list failure;   查看数据库错误;

    RMAN> advise failure;   查看修复建议,可通过vi命令查看修复脚本

    RMAN> repair failure;  选择YES即可执行修复

    Quiz
    An Oracle Database instance will not fail if the following event occurs:
    a. Loss of a control file if there is a remaining multiplexed control file
    b. Loss of the SYSTEM tablespace
    c. Loss of one redo log member if there is a remaining multiplexed redo log member from the same group of the lost member
    d. Loss of the active undo tablespace

    测验

    如果发生以下事件,Oracle数据库实例不会失败:

    a、 如果存在剩余的多路复用控制文件,则丢失控制文件

    b、 系统表空间丢失

    c、 如果丢失成员的同一组中有剩余的多路复用重做日志成员,则丢失一个重做日志成员   正确

    d、 活动撤消表空间丢失

    Summary
    In this lesson, you should have learned how to:
    • Determine the need for performing recovery
    • Describe and use available options, such as Recovery Manager (RMAN) and the Data Recovery Advisor
    • Perform recovery:
    – Control file
    – Redo log file
    – Data file

    摘要

    在本课中,您应该学习如何:

    •确定执行恢复的需要

    •描述并使用可用选项,如Recovery Manager(RMAN)和Data Recovery Advisor

    •执行恢复:

    –控制文件

    –重做日志文件

    –数据文件

    Practice: Overview
    This practice covers recovering from the loss of a:
    • Control file
    • Noncritical data file
    • System-critical data file

    练习:概述

    这一做法包括从下列损失中恢复:

    •控制文件

    •非关键数据文件

    •系统关键数据文件

  • 相关阅读:
    DVWA——Brute Force(暴力破解)
    Sqli-Labs 闯关 less 54-65
    C#静态构造函数和析构函数片段化认知
    for、foreach和MoveNext循环效率粗比较
    实现一次请求加载多个js或者css
    asp.net使用httphandler打包多CSS或JS文件以加快页面加载速度
    C#向文件写、读数据
    计算机管理cmd命令行
    有二级目录的IIS配置
    WIN7 64位系统安装JDK并配置环境变量
  • 原文地址:https://www.cnblogs.com/cloud7777/p/13198582.html
Copyright © 2011-2022 走看看