Recently I was asked to rename a tablespace. The environment was Oracle version 11.2.0.3 (both database and clusterware/ASM).

This is the test case I build to understand how that works:
(I couldn’t find a clean, straightforward description how to do that, which is why I blog it here)

I created an empty tablespace ‘test1′ for test purposes:

SYS@v11203 AS SYSDBA> create bigfile tablespace test1 datafile size 10m;

(I use bigfile tablespaces only with ASM. Adding datafiles is such a labour intensive work, bigfile tablespaces elimenate that, when auto extent is correctly set)

A tablespace can be easily renamed with the alter tablespace rename command:

SYS@v11203 AS SYSDBA> alter tablespace test1 rename to test2;

This changes the Oracle data dictionary to reflect a new name. This doesn’t touch the underlying datafile.

To rename the datafile in ASM, offline the tablespace, copy the datafile using RMAN, rename the datafile in the Oracle data dictionary, and online the tablespace again:

Offline the tablespace:

SYS@v11203 AS SYSDBA> alter tablespace test2 offline;

Copy the datafile using RMAN:

RMAN> copy datafile '+DATA/v11203/datafile/test1.268.789380535' to '+DATA';

Starting backup at 23-JUL-12
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=28 device type=DISK
channel ORA_DISK_1: starting datafile copy
input datafile file number=00007 name=+DATA/v11203/datafile/test1.268.789380535
output file name=+DATA/v11203/datafile/test2.269.789380645 tag=TAG20120723T082404 RECID=1 STAMP=789380644
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01
Finished backup at 23-JUL-12

Rename the datafile in the Oracle data dictionary:

SYS@v11203 AS SYSDBA> alter database rename file '+DATA/v11203/datafile/test1.268.789380535' to '+DATA/v11203/datafile/test2.269.789380645';

Please mind the ‘old’ filename is at ‘input datafile’, and the ‘new’ filename is at ‘output file name’ with the RMAN output.

Next, and finally: online the tablespace:

SYS@v11203 AS SYSDBA> alter tablespace test2 online;

(the old datafile is gone)

Update:

The RMAN copy command and data dictionary update could also be done with RMAN backup as copy and switch datafile:

Status of the database after renaming:

SYS@v11203 AS SYSDBA> select file_id, file_name, tablespace_name from dba_data_files;

Offline the tablespace (my database is in NOARCHIVELOG, online backup (as copy) can only be done in ARCHIVELOG, when doing so, the datafile needs recovery):

RMAN> sql "alter tablespace test2 offline";

sql statement: alter tablespace test2 offline

Backup the datafile as copy. It is very convenient to use file number (file_id), this makes it much simpler to do this:

RMAN> backup as copy datafile 7 format '+DATA';

Starting backup at 23-JUL-12
using channel ORA_DISK_1
channel ORA_DISK_1: starting datafile copy
input datafile file number=00007 name=+DATA/v11203/datafile/test1.269.789411511
output file name=+DATA/v11203/datafile/test2.268.789411665 tag=TAG20120723T170105 RECID=2 STAMP=789411665
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01
Finished backup at 23-JUL-12

Now switch to the backup copy:

RMAN> switch datafile 7 to copy;

datafile 7 switched to datafile copy "+DATA/v11203/datafile/test2.268.789411665"

And online the tablespace again:

RMAN> sql "alter tablespace test2 online";

sql statement: alter tablespace test2 online

Please mind this leaves the old datafile in place, so it needs to be removed explicitly:

RMAN> delete noprompt copy of datafile 7;

released channel: ORA_DISK_1
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=44 device type=DISK
List of Datafile Copies
======================= Key File S Completion Time Ckp SCN Ckp Time
------- ---- - --------------- ---------- ---------------
5 7 A 23-JUL-12 1779771 23-JUL-12
Name: +DATA/v11203/datafile/test1.268.789415137 deleted datafile copy
datafile copy file name=+DATA/v11203/datafile/test1.268.789415137 RECID=5 STAMP=789415216
Deleted 1 objects

An alternative is to do this with asmcmd, but it’s far less elegant:

$ asmcmd rm -f +DATA/v11203/datafile/test1.269.789411511

Rename Oracle Managed File (OMF) datafiles in ASM(ZT)的更多相关文章

  1. ORACLE managed file(OMF)

    ORACLE managed file (OMF) Oracle自动创建和删除OMF文件 不用操心文件的命名约定 在手动管理文件时容易错误删除数据文件(OMF降低这种风险) Oracle自动删除不再需 ...

  2. Oracle管理文件OMF (oracle managed files)

    简化dba的管理操作 1:启用 omf 23:16:04 SYS@orcl> show parameter DB_CREATE_FILE_DEST NAME TYPE VALUE ------- ...

  3. [置顶] How to create Oracle 11g R2 database manually in ASM?

    Step 1: Specify an Instance Identifier (SID) export ORACLE_SID=maomi Step 2: Ensure That the Require ...

  4. 基于CentOS与VmwareStation10搭建Oracle11G RAC 64集群环境:4.安装Oracle RAC FAQ-4.2.Oracleasm Createdisk ASM磁盘失败:Instantiating disk: failed

    1.错误信息:Instantiating disk: failed [root@linuxrac1 /]# /usr/sbin/oracleasm createdisk OCR_VOTE /dev/s ...

  5. 基于CentOS与VmwareStation10搭建Oracle11G RAC 64集群环境:3.安装Oracle RAC-3.1.安装并配置ASM驱动

    3.1.安装并配置ASM驱动 3.3.1.检查内核 [root@linuxrac2 etc]# uname -r 2.6.18-164.el5 下载以下rpm包(注意rpm包版本和Linux内核版本一 ...

  6. ORACLE CONTROL FILE 笔记

    控制文件包含的信息:   1.数据库的名字   2.联机重做日志文件和数据文件的名字和位置   3.数据库创建的时间戳   4.当前日志的序列号   5.检查点信息   6.备份信息   TIP:数据 ...

  7. Oracle 11gR2用gpnp profile存放ASM的spfile路径

    从Oracle 11gR2开始,GI集成了ASM,OCR/VOTEDISK也存放在ASM磁盘组了(11gR2以前需要存放于裸设备中),同时ASM的功能较10g也有很大增强. 我们先引入一个问题:11g ...

  8. Oracle 11gR2 RAC DBCA无法识别ASM磁盘组(ORA-19504,ORA-15045,ORA-17502,ORA-15081)

    ORA-19504: failed to create file "+DATA" ORA-15045: ASM file name '+DATA' is not in refere ...

  9. oracle RAC如何正确地删除ASM磁盘组

    1.登录到命令行 切换到grid用户 [grid@swnode1 ~]$ sqlplus / as sysasm SQL*Plus: Release Production on Wed May :: ...

随机推荐

  1. Spark 属性配置

    1.Spark1.x 属性配置方式 Spark属性提供了大部分应用程序的控制项,并且可以单独为每个应用程序进行配置. 在Spark1.0.0提供了3种方式的属性配置: SparkConf方式 Spar ...

  2. 中文乱码之myEclipse项目导入时中文乱码(待)

    方法1:检查默认的编码是否设置成utf-8. 步骤如图: window——>preferences... 若Text file encoding 中的编码为 Other == UTF-8 ,则已 ...

  3. Effective java第一章引言

    菜鸟一枚,开始读第一本书<Effective Java>(第二版)~ 看引言就有好多名词不懂(>_<) 导出的API由所有可在定义该API的包之外访问的API元素组成.一个包的 ...

  4. 可编辑的div模仿文本框缓存(使用AUTOCOMPLETE属性,off是不缓存,on是缓存(默认))

    用session实现的, 1.进当前页面就从session(a)中取( sessionStorage.getItem )(不管存在不存在,后续有合理的存储和删除); 2.离开当前页时删除这个sessi ...

  5. Spring初学之xml实现AOP前置通知、后置通知、返回通知、异常通知等

    实现两个整数的加减乘除,在每个方法执行前后打印日志. ArithmeticCalculator.java: package spring.aop.impl.xml; public interface ...

  6. WinDBG__独立安装文件

    debugging tools for windows 1. 来自于网页:http://rxwen.blogspot.hk/2010/04/standalone-windbg-v6120002633. ...

  7. PowerDesigner 学习

    1. 创建主键,不能为空,递增列,唯一约束(key 通过唯一索引) 数据库-->根据数据库的改动更新model  或者 根据修改后的model (比如新添加的字段)产生新sql代码 2.powe ...

  8. LINQ to Entities 不识别方法“Int32 ToInt32(System.String)”,因此该方法无法转换为存储表达式。

      通常原始代码如下: Where id=Convert.ToInt32(cousid) 更改后代码: Var currentid= Convert.ToInt32(cousid); Wehre id ...

  9. sgu176 有源汇上下界最小流

    题意:有一堆点和边,1起点,n终点,某些边有可能必须满流,要求满足条件的最小流 解法:按原图建边,满流的即上下界都是容量,但是这样按有源汇上下界可行流求出来的可能不是最小流,那么我们需要开始建边的时候 ...

  10. 使用Visio画UML模型

    Microsoft Office Visio“UML 模型图” 模板为创建复杂软件系统的面向对象的模型 (模型:建模系统的一种抽象表示,它从特定的视角并在某一抽象级别上指定建模系统.) 提供全面的支持 ...