随笔 - 404  文章 - 4  评论 - 0  阅读 - 25万

ORACLE表空间offline谈起,表空间备份恢复

从ORACLE表空间offline谈起,表空间备份恢复
将表空间置为offline,可能的原因包括维护、备份恢复等目的;
表空间处于offline状态,那么Oracle不会允许任何对该表空间中对象的SQL执行,表空间置为offline时仍处于活动状态的语句在交易级别并不会受影响。

实验一:RMAN备份恢复表空间
SQL> create tablespace test datafile '/data/app/oracle/oradata/ORCL/datafile/test01.dbf' size 1G ;
Tablespace created.
SQL> alter tablespace TEST add datafile '/data/app/oracle/oradata/ORCL/datafile/test02.dbf' size 1G;
Tablespace altered.
[oracle@prod ~]$ rman target /
Recovery Manager: Release 12.1.0.2.0 - Production on Thu Jun 14 11:26:31 2018
Copyright (c) 1982, 2014, Oracle and/or its affiliates. All rights reserved.
connected to target database: ORCL (DBID=1607304684)

RMAN> backup tablespace "TEST" tag "test";
RMAN> alter tablespace test offline;
模拟数据文件损坏
[oracle@prod ~]$ mv /data/app/oracle/oradata/ORCL/datafile/test01.dbf /data/app/oracle/oradata/ORCL/datafile/test01.dbf.bk
[oracle@prod ~]$ mv /data/app/oracle/oradata/ORCL/datafile/test02.dbf /data/app/oracle/oradata/ORCL/datafile/test02.dbf.bk
利用RMAN进行介质恢复
[oracle@prod ~]$ rman target /

Recovery Manager: Release 12.1.0.2.0 - Production on Thu Jun 14 11:28:30 2018
Copyright (c) 1982, 2014, Oracle and/or its affiliates. All rights reserved.
connected to target database: ORCL (DBID=1607304684)
RMAN> restore tablespace "TEST";
RMAN> recover tablespace "TEST";

Starting recover at 14-JUN-18
using channel ORA_DISK_1
starting media recovery
media recovery complete, elapsed time: 00:00:00
Finished recover at 14-JUN-18

RMAN> alter tablespace test online;

Statement processed

RMAN>

实验二:expdp/impdp备份恢复表空间
SQL> create tablespace test datafile '/data/app/oracle/oradata/ORCL/datafile/test01.dbf' size 1G ;
Tablespace created.
SQL> alter tablespace TEST add datafile '/data/app/oracle/oradata/ORCL/datafile/test02.dbf' size 1G;
Tablespace altered.
RMAN> backup tablespace "TEST" tag "test";
RMAN> alter tablespace test offline;

SQL>drop tablespace test;

RMAN> restore tablespace test;

Starting restore at 14-JUN-18
using channel ORA_DISK_1
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of restore command at 06/14/2018 11:58:48
RMAN-20202: Tablespace not found in the recovery catalog
RMAN-06019: could not translate tablespace name "TEST"
因为rman是用来在介质故障之后进行恢复的,手动进行的drop表空间不是介质故障,而且执行drop操作的时候表空间信息已经被从数据字典里删掉
所以,只能找个地方,把整个库恢复到drop表空间之前,再用导出,导入的方法把这个表空间导入原来的库中
SQL> create user elon identified by "elon" default tablespace test account unlock;
User created.
SQL> grant dba to elon;
SQL> create table test as select * from user_objects where rownum < 10;
SQL> insert into test select * from test;
SQL> commit;
逻辑备份表空间TEST
[oracle@prod ~]$ expdp system/xxxxxx DIRECTORY=DUMP DUMPFILE=test.dmp TABLESPACES="test"
SQL> drop tablespace test including contents and datafiles;

进行恢复:
SQL> create tablespace test datafile '/data/app/oracle/oradata/HBCG/datafile/test01.dbf' size 1G ;

[oracle@prod ~]$ impdp system/oracle DIRECTORY=DUMP DUMPFILE=test.dmp
SQL> select tablespace_name,status from dba_tablespaces where tablespace_name='TEST';

TABLESPACE_NAME STATUS
------------------------------ ---------
TEST ONLINE

 实验三:清理OFFLINE表空间

SQL> alter tablespace FDA online;

SQL> select owner,table_name from dba_tables where tablespace_name='FDA';
no rows selected
SQL> select * from dba_segments where segment_name='FDA';
no rows selected

[oracle@SQL ~]$expdp system/xxxxxx DIRECTORY=DATA_DUMP DUMPFILE=fda.dmp LOGFILE=fda.log  TABLESPACES="FDA" 

SQL> alter tablespace FDA offline;

SQL>drop tablespace FDA including contents and datafiles;

 

posted on   HelonTian  阅读(401)  评论(0编辑  收藏  举报
编辑推荐:
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

点击右上角即可分享
微信分享提示