zoukankan      html  css  js  c++  java
  • Rename Oracle Managed File (OMF) datafiles in ASM(ZT)

    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
  • 相关阅读:
    从 0 → 1,学习Linux该这么开始!
    Web和移动开发的未来
    css-div中文字过多(内容超出div宽度)后自动换行
    js+css--单选按钮,自定义选中的颜色???(性别按钮,男女)
    css-按钮中有图片和文字,怎么才能让文字和图片都中??
    js-点出弹框后(除了点击窗口上的叉子),点其他地方能够关闭窗口???
    css-外面元素的高度,由里面的元素进行撑开(由内部的高度决定)
    js-将传来的数据排序,让(全部)这个小按钮小圈圈,始终排列在最前面
    echart--如何在折线图上添加矩形背景(可以借用bar柱状图的实现效果)
    echart-如何将x轴和y轴的原点进行重合???
  • 原文地址:https://www.cnblogs.com/cqubityj/p/3508404.html
Copyright © 2011-2022 走看看