(Les16 執行資料庫恢復)-表空間恢復

来源:https://www.cnblogs.com/also-brook/archive/2018/05/22/9072904.html
-Advertisement-
Play Games

NOARCHIVELOG模式下丟失了數據文件 資料庫處於NOARCHIVELOG模式時,如果丟失任何數據文件,執行以下步驟 1.如果實例尚未關閉,請關閉實例 2.從備份還原整個資料庫,包括所有數據文件和控制文件 3.打開資料庫 4.讓用戶重新輸入自上次備份以來所做的所有更改 ARCHIVELOG模式 ...


NOARCHIVELOG模式下丟失了數據文件     資料庫處於NOARCHIVELOG模式時,如果丟失任何數據文件,執行以下步驟         1.如果實例尚未關閉,請關閉實例         2.從備份還原整個資料庫,包括所有數據文件和控制文件         3.打開資料庫         4.讓用戶重新輸入自上次備份以來所做的所有更改   ARCHIVELOG模式下丟失了非關鍵性數據文件(SYSTEM,UNDO除外)         僅僅恢復當前數據文件不用整庫恢復,不需要停機         1.數據文件離線         2.restore數據文件,介質恢復         3.recover事務         4.數據文件聯機   ARCHIVELOG模式下丟失了關鍵性數據文件(SYSTEM,UNDO...)         資料庫關鍵性數據文件丟失,需要停機恢復         1.實例可能會也可能不會自動關閉。如果未自動關閉,請使用SHUTDOWN ABORT關閉實例         2.裝載資料庫,MOUNT         3.還原並恢復缺失的數據文件,restore datafile/database          4.recover datafile/database         5.打開資料庫       歸檔模式下恢復非關鍵表空間  
set linesize 300
set pagesize 600
col file_name format a50
col tablespace_name format a20
select tablespace_name,file_name from dba_data_files;
 
 
創建一個非關鍵表空間進行測試
 
create tablespace redo_data  datafile '/u01/app/oracle/oradata/xiocpt0/redo_data01.dbf' size 32M autoextend on next 32M maxsize 1024M;
 
 
 
SQL> create tablespace redo_data  datafile '/u01/app/oracle/oradata/xiocpt0/redo_data01.dbf' size 32M autoextend on next 32M maxsize 1024M;
 
Tablespace created.
 
SQL> set linesize 300
set pagesize 600
col file_name format a50
col tablespace_name format a20
select tablespace_name,file_name from dba_data_files;
 
 
TABLESPACE_NAME      FILE_NAME
-------------------- --------------------------------------------------
USERS                /u01/app/oracle/oradata/xiocpt0/users01.dbf
UNDOTBS1             /u01/app/oracle/oradata/xiocpt0/undotbs01.dbf
SYSAUX               /u01/app/oracle/oradata/xiocpt0/sysaux01.dbf
SYSTEM               /u01/app/oracle/oradata/xiocpt0/system01.dbf
REDO_DATA            /u01/app/oracle/oradata/xiocpt0/redo_data01.dbf
 
 
 
 
 
BACKUP AS COMPRESSED BACKUPSET DATABASE PLUS ARCHIVELOG;
 
對數據進行一次完全備份
 
RMAN> shutdown immediate
RMAN> startup mount
RMAN> run
{
allocate channel c1 device type disk format '/u01/backup/backup01_%U' ;
backup as compressed backupset database;
backup current controlfile;
alter database open;
}
 
 
RMAN> list backup;
 
 
List of Backup Sets
===================
 
 
BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
7       Full    321.23M    DISK        00:00:38     22-MAY-18
        BP Key: 7   Status: AVAILABLE  Compressed: YES  Tag: TAG20180522T151208
        Piece Name: /u01/backup/backup01_08t3hoq8_1_1
  List of Datafiles in backup set 7
  File LV Type Ckp SCN    Ckp Time  Name
  ---- -- ---- ---------- --------- ----
  1       Full 1058982    22-MAY-18 /u01/app/oracle/oradata/xiocpt0/system01.dbf
  2       Full 1058982    22-MAY-18 /u01/app/oracle/oradata/xiocpt0/sysaux01.dbf
  3       Full 1058982    22-MAY-18 /u01/app/oracle/oradata/xiocpt0/undotbs01.dbf
  4       Full 1058982    22-MAY-18 /u01/app/oracle/oradata/xiocpt0/users01.dbf
  5       Full 1058982    22-MAY-18 /u01/app/oracle/oradata/xiocpt0/redo_data01.dbf
 
BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
8       Full    1.05M      DISK        00:00:03     22-MAY-18
        BP Key: 8   Status: AVAILABLE  Compressed: YES  Tag: TAG20180522T151208
        Piece Name: /u01/backup/backup01_09t3horl_1_1
  SPFILE Included: Modification time: 22-MAY-18
  SPFILE db_unique_name: XIOCPT0
  Control File Included: Ckp SCN: 1058982      Ckp time: 22-MAY-18
 
BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
9       Full    9.64M      DISK        00:00:01     22-MAY-18
        BP Key: 9   Status: AVAILABLE  Compressed: NO  Tag: TAG20180522T151257
        Piece Name: /u01/backup/backup01_0at3horp_1_1
  Control File Included: Ckp SCN: 1058982      Ckp time: 22-MAY-18
 
 
 
創建表並指定表空間
 
SQL> create table REDO_DATA(
  2  id number,
  3  name varchar2(20)
  4  )
  5  tablespace REDO_DATA;
 
Table created.
 
SQL> declare
v_count number;
 
begin
  for i in 1..1000 loop
  insert into redo_data values(i,'name0'||i);
  end loop;
end;
/  2    3    4    5    6    7    8    9
 
PL/SQL procedure successfully completed.
 
SQL> commit;
 
Commit complete.
 
SQL> select count(*) from REDO_DATA;
 
  COUNT(*)
----------
      1000
 
 
 
 
恢復非關鍵表空間
 
 
sql 'alter tablespace redo_data offline';---離線需恢復的表空間
 
 
restore tablespace redo_data;---還原表空間
recover tablespace redo_data;---恢復表空間,期間的事務進行應用
  
  
sql 'alter tablespace redo_data online';---恢復完成,將表空間線上
 
 
刪除數據文件
SQL> !rm -rf /u01/app/oracle/oradata/xiocpt0/redo_data01.dbf
 
SQL> select count(*) from REDO_DATA;
 
  COUNT(*)
----------
      1000
 
SQL> commit;
 
Commit complete.
 
SQL> declare
v_count number;
 
begin
  for i in 1..1000 loop
  insert into redo_data values(i,'name0'||i);
  end loop;
end;
/  2    3    4    5    6    7    8    9
 
PL/SQL procedure successfully completed.
 
SQL> commit;
 
Commit complete.
 
SQL>  select count(*) from REDO_DATA;
 
  COUNT(*)
----------
      2000
 
SQL> !ls -l /u01/app/oracle/oradata/xiocpt0/redo_data01.dbf
ls: cannot access /u01/app/oracle/oradata/xiocpt0/redo_data01.dbf: No such file or directory
 
SQL> select table_name ,tablespace_name from dba_tables where table_name='REDO_DATA';
 
TABLE_NAME                     TABLESPACE_NAME
------------------------------ --------------------
REDO_DATA                      REDO_DATA
 
SQL> alter system switch logfile;
 
System altered.
 
SQL>  alter system checkpoint;
 
System altered.
 
SQL> select count(*) from REDO_DATA;
 
  COUNT(*)
----------
      2000
 
SQL> declare
v_count number;
 
begin
  for i in 1..1000 loop
  insert into redo_data values(i,'name0'||i);
  end loop;
end;
/  2    3    4    5    6    7    8    9
 
PL/SQL procedure successfully completed.
 
SQL> declare
v_count number;
 
begin
  for i in 1..1000 loop
  insert into redo_data values(i,'name0'||i);
  end loop;
end;
/  2    3    4    5    6    7    8    9
 
PL/SQL procedure successfully completed.
 
SQL> declare
v_count number;
 
begin
  for i in 1..1000 loop
  insert into redo_data values(i,'name0'||i);
  end loop;
end;
/  2    3    4    5    6    7    8    9
 
PL/SQL procedure successfully completed.
 
SQL> commit;
 
Commit complete.
 
SQL> !ls -l /u01/app/oracle/oradata/xiocpt0/redo_data01.dbf
ls: cannot access /u01/app/oracle/oradata/xiocpt0/redo_data01.dbf: No such file or directory
 
SQL> select count(*) from REDO_DATA;
select count(*) from REDO_DATA
                     *
ERROR at line 1:
ORA-00376: file 5 cannot be read at this time
ORA-01110: data file 5: '/u01/app/oracle/oradata/xiocpt0/redo_data01.dbf'
 
 
開始執行還原/恢復操作
 
RMAN> sql 'alter tablespace redo_data offline';
 
sql statement: alter tablespace redo_data offline
 
RMAN>
restore tablespace redo_data;
RMAN>
 
Starting restore at 22-MAY-18
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=19 device type=DISK
 
channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00005 to /u01/app/oracle/oradata/xiocpt0/redo_data01.dbf
channel ORA_DISK_1: reading from backup piece /u01/backup/backup01_08t3hoq8_1_1
channel ORA_DISK_1: piece handle=/u01/backup/backup01_08t3hoq8_1_1 tag=TAG20180522T151208
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
Finished restore at 22-MAY-18
 
RMAN>   recover tablespace redo_data;
 
Starting recover at 22-MAY-18
using channel ORA_DISK_1
 
starting media recovery
 
archived log for thread 1 with sequence 74 is already on disk as file /u01/archive/arch_976375926_1_74.arc
archived log for thread 1 with sequence 75 is already on disk as file /u01/archive/arch_976375926_1_75.arc
archived log for thread 1 with sequence 76 is already on disk as file /u01/archive/arch_976375926_1_76.arc
archived log for thread 1 with sequence 77 is already on disk as file /u01/archive/arch_976375926_1_77.arc
archived log for thread 1 with sequence 78 is already on disk as file /u01/archive/arch_976375926_1_78.arc
archived log for thread 1 with sequence 79 is already on disk as file /u01/archive/arch_976375926_1_79.arc
archived log for thread 1 with sequence 80 is already on disk as file /u01/archive/arch_976375926_1_80.arc
archived log for thread 1 with sequence 81 is already on disk as file /u01/archive/arch_976375926_1_81.arc
archived log for thread 1 with sequence 82 is already on disk as file /u01/archive/arch_976375926_1_82.arc
archived log for thread 1 with sequence 83 is already on disk as file /u01/archive/arch_976375926_1_83.arc
archived log for thread 1 with sequence 84 is already on disk as file /u01/archive/arch_976375926_1_84.arc
archived log for thread 1 with sequence 85 is already on disk as file /u01/archive/arch_976375926_1_85.arc
archived log file name=/u01/archive/arch_976375926_1_74.arc thread=1 sequence=74
archived log file name=/u01/archive/arch_976375926_1_75.arc thread=1 sequence=75
archived log file name=/u01/archive/arch_976375926_1_76.arc thread=1 sequence=76
archived log file name=/u01/archive/arch_976375926_1_77.arc thread=1 sequence=77
archived log file name=/u01/archive/arch_976375926_1_78.arc thread=1 sequence=78
archived log file name=/u01/archive/arch_976375926_1_79.arc thread=1 sequence=79
archived log file name=/u01/archive/arch_976375926_1_80.arc thread=1 sequence=80
media recovery complete, elapsed time: 00:00:00
Finished recover at 22-MAY-18
 
RMAN>   sql 'alter tablespace redo_data online';
 
sql statement: alter tablespace redo_data online
 
 
 
SQL>  select count(*) from REDO_DATA;
 
  COUNT(*)
----------
      5000

 

 

    歸檔模式下恢復關鍵表空間          資料庫關鍵性數據文件丟失,需要停機恢復         1.實例可能會也可能不會自動關閉。如果未自動關閉,請使用SHUTDOWN ABORT關閉實例         2.裝載資料庫,MOUNT         3.還原並恢復缺失的數據文件,restore datafile/database          4.recover datafile/database         5.打開資料庫  
SQL> set linesize 300
set pagesize 600
col file_name format a50
col tablespace_name format a20
select tablespace_name,file_name from dba_data_files;SQL> SQL> SQL> SQL>
 
TABLESPACE_NAME      FILE_NAME
-------------------- --------------------------------------------------
USERS                /u01/app/oracle/oradata/xiocpt0/users01.dbf
UNDOTBS1             /u01/app/oracle/oradata/xiocpt0/undotbs01.dbf
SYSAUX               /u01/app/oracle/oradata/xiocpt0/sysaux01.dbf
SYSTEM               /u01/app/oracle/oradata/xiocpt0/system01.dbf
REDO_DATA            /u01/app/oracle/oradata/xiocpt0/redo_data01.dbf
 
SQL>
SQL> !rm -rf /u01/app/oracle/oradata/xiocpt0/system01.dbf
 
 
startup mount ---將資料庫啟動到mount
restore tablespace system;---指定關鍵表空間進行還原
recover tablespace system;---恢復表空間
sql 'alter database open';---將資料庫打開
 
 
[oracle@t-xi-oracle01 ~]$ rman  target /
 
Recovery Manager: Release 11.2.0.4.0 - Production on Tue May 22 15:30:33 2018
 
Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.
 
connected to target database (not started)
 
RMAN> startup mount
 
Oracle instance started
database mounted
 
Total System Global Area     409194496 bytes
 
Fixed Size                     2253744 bytes
Variable Size                322964560 bytes
Database Buffers              79691776 bytes
Redo Buffers                   4284416 bytes
 
RMAN> restore tablespace system;
 
Starting restore at 22-MAY-18
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=18 device type=DISK
 
channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00001 to /u01/app/oracle/oradata/xiocpt0/system01.dbf
channel ORA_DISK_1: reading from backup piece /u01/backup/backup01_08t3hoq8_1_1
channel ORA_DISK_1: piece handle=/u01/backup/backup01_08t3hoq8_1_1 tag=TAG20180522T151208
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:45
Finished restore at 22-MAY-18
 
RMAN> recover tablespace system;
 
Starting recover at 22-MAY-18
using channel ORA_DISK_1
 
starting media recovery
 
archived log for thread 1 with sequence 74 is already on disk as file /u01/archive/arch_976375926_1_74.arc
archived log for thread 1 with sequence 75 is already on disk as file /u01/archive/arch_976375926_1_75.arc
archived log for thread 1 with sequence 76 is already on disk as file /u01/archive/arch_976375926_1_76.arc
archived log for thread 1 with sequence 77 is already on disk as file /u01/archive/arch_976375926_1_77.arc
archived log for thread 1 with sequence 78 is already on disk as file /u01/archive/arch_976375926_1_78.arc
archived log for thread 1 with sequence 79 is already on disk as file /u01/archive/arch_976375926_1_79.arc
archived log for thread 1 with sequence 80 is already on disk as file /u01/archive/
              
您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • https://technet.microsoft.com/zh-cn/library/2008.12.linux.aspx ...
  • 前言: 本文是對Muhammad Irfan的這篇博客MySQL "Got an Error Reading Communication Packet" Errors的翻譯,如有翻譯不對或不好的地方,敬請指出,大家一起學習進步。尊重原創和翻譯勞動成果,轉載時請註明出處。謝謝! 英文原文地址:http... ...
  • 在SQL Server中,索引是優化SQL性能的一大法寶。但是由於各種原因,索引會被當做“銀彈”濫用,一方面有些開發人員(甚至是部分資料庫管理員)有一些陋習,不管三七二十一,總是根據所謂的"感覺"或“經驗”先增加一些索引,而不管這些索引是否未被使用或是否合理。另外一方面在資料庫的生命周期中,需求總是... ...
  • MySQL有很多種複製,至少從概念上來看,傳統的主從複製,半同步複製,GTID複製,多線程複製,以及組複製(MGR)。咋一看起來很多,各種各樣的複製,其實從原理上看,各種複製的原理並無太大的異同。每一種複製的出現都是有其原因的,是解決(或者說是彌補)前一種的複製方案的潛在的問題的。新的複製方式的出現 ...
  • 文件結構 config import os IP_PORT = ('127.0.0.1',8080) BASE_DIR = os.path.dirname(os.path.dirname(__file__)) BASE_UPLOAD_MOVIE = os.path.join(BASE_DIR,'up ...
  • ## ## binlog文件生成:在每條二進位日誌寫入到日誌文件後,會判斷該文件是否超過max_binlog_size,如果超過則生成一個新的binlog relay log文件生成:每從Master fetch一個events後,判斷當前文件是否超過max_relay_log_size 如果超過則 ...
  • 摘要:相信大家都使用過子查詢,因為使用子查詢可以一次性的完成很多邏輯上需要多個步驟才能完成的SQL操作,比較靈活,我也喜歡用,可最近因為一條包含子查詢的select count(*)語句導致點開管理系統的一個功能模塊列表時,耗時44幾秒,到了不可容忍的地步,定位發現是因為未加索引和用了子查詢導致,不 ...
  • 最近在做管理系統,查詢sql很慢, 根據explain的結果,一步步優化sql,下麵就是可以用到的資料,覺得簡單明瞭,轉載他人, 多用些函數,if 、case等 減少子查詢 1)、id列數字越大越先執行,如果說數字一樣大,那麼就從上往下依次執行,id列為null的就表是這是一個結果集,不需要使用它來 ...
一周排行
    -Advertisement-
    Play Games
  • 移動開發(一):使用.NET MAUI開發第一個安卓APP 對於工作多年的C#程式員來說,近來想嘗試開發一款安卓APP,考慮了很久最終選擇使用.NET MAUI這個微軟官方的框架來嘗試體驗開發安卓APP,畢竟是使用Visual Studio開發工具,使用起來也比較的順手,結合微軟官方的教程進行了安卓 ...
  • 前言 QuestPDF 是一個開源 .NET 庫,用於生成 PDF 文檔。使用了C# Fluent API方式可簡化開發、減少錯誤並提高工作效率。利用它可以輕鬆生成 PDF 報告、發票、導出文件等。 項目介紹 QuestPDF 是一個革命性的開源 .NET 庫,它徹底改變了我們生成 PDF 文檔的方 ...
  • 項目地址 項目後端地址: https://github.com/ZyPLJ/ZYTteeHole 項目前端頁面地址: ZyPLJ/TreeHoleVue (github.com) https://github.com/ZyPLJ/TreeHoleVue 目前項目測試訪問地址: http://tree ...
  • 話不多說,直接開乾 一.下載 1.官方鏈接下載: https://www.microsoft.com/zh-cn/sql-server/sql-server-downloads 2.在下載目錄中找到下麵這個小的安裝包 SQL2022-SSEI-Dev.exe,運行開始下載SQL server; 二. ...
  • 前言 隨著物聯網(IoT)技術的迅猛發展,MQTT(消息隊列遙測傳輸)協議憑藉其輕量級和高效性,已成為眾多物聯網應用的首選通信標準。 MQTTnet 作為一個高性能的 .NET 開源庫,為 .NET 平臺上的 MQTT 客戶端與伺服器開發提供了強大的支持。 本文將全面介紹 MQTTnet 的核心功能 ...
  • Serilog支持多種接收器用於日誌存儲,增強器用於添加屬性,LogContext管理動態屬性,支持多種輸出格式包括純文本、JSON及ExpressionTemplate。還提供了自定義格式化選項,適用於不同需求。 ...
  • 目錄簡介獲取 HTML 文檔解析 HTML 文檔測試參考文章 簡介 動態內容網站使用 JavaScript 腳本動態檢索和渲染數據,爬取信息時需要模擬瀏覽器行為,否則獲取到的源碼基本是空的。 本文使用的爬取步驟如下: 使用 Selenium 獲取渲染後的 HTML 文檔 使用 HtmlAgility ...
  • 1.前言 什麼是熱更新 游戲或者軟體更新時,無需重新下載客戶端進行安裝,而是在應用程式啟動的情況下,在內部進行資源或者代碼更新 Unity目前常用熱更新解決方案 HybridCLR,Xlua,ILRuntime等 Unity目前常用資源管理解決方案 AssetBundles,Addressable, ...
  • 本文章主要是在C# ASP.NET Core Web API框架實現向手機發送驗證碼簡訊功能。這裡我選擇是一個互億無線簡訊驗證碼平臺,其實像阿裡雲,騰訊雲上面也可以。 首先我們先去 互億無線 https://www.ihuyi.com/api/sms.html 去註冊一個賬號 註冊完成賬號後,它會送 ...
  • 通過以下方式可以高效,並保證數據同步的可靠性 1.API設計 使用RESTful設計,確保API端點明確,並使用適當的HTTP方法(如POST用於創建,PUT用於更新)。 設計清晰的請求和響應模型,以確保客戶端能夠理解預期格式。 2.數據驗證 在伺服器端進行嚴格的數據驗證,確保接收到的數據符合預期格 ...