How to move ASM database files from one diskgroup to another

 

 

       The preferred way of doing the file movement amoung ASM DISKGROUPS is using RMAN. RMAN is critical to Automatic Storage Management and is responsible for tracking the ASM filenames and for deleting obsolete ASM files. Since ASM files cannot be accessed through normal operating system interfaces, RMAN is the preferred means of copying ASM file.


The steps involved in moving a datafile from a diskgroup to another is as given below.

1) Identify the data file to be moved.
2) Identify the diskgroup on to which the file has to be moved.
3) Take the file offline.
4) Copy the file to new diskgroup using Either RMAN or DBMS_FILE_TRANSFER.
5) Rename the file to point to new location.
6) Recover the file.
7) Bring the file online.
8) Verify the new file locations.
9) Delete the file from its original location.



详细步骤如下:


1) Identify the data file to be moved.
 ----------------------------------------
         In database instance

         SQL:ORCL> SELECT FILE_NAME FROM DBA_DATA_FILES:
                            +ASMDSK2/orcl/datafile/users.256.565313879 <======= Move this to ASDSK1.
                            +ASMDSK1/orcl/sysaux01.dbf
                            +ASMDSK1/orcl/undotbs01.dbf
                            +ASMDSK1/orcl/system01.dbf

2) Identify the diskgroup on to which the file has to be moved.
--------------------------------------------------------------
      In ASM instance

SQL:ASM> SELECT GROUP_NUMBER, NAME FROM V$ASM_DISKGROUP;

                           GROUP_NUMBER NAME
                             ------------ ---------
                                             1 ASMDSK1
                                             2 ASMDSK2

3) Take the file offline.

--------------------------
SQL:ORCL> ALTER DATABASE DATAFILE '+ASMDSK2/orcl/datafile/users.256.565313879' OFFLINE;


 4) Now Copy the file from Source diskgroup ASMDSK1 to target Diskgroup ASMDSK2.
--------------------------------------------------------------------------------------------
   Either
  
    4. a)   DBMS_FILE_TRANSFER   package or
     4. b)   RMAN 

  

 can be used for this step.
       ( The step 5 to step 8  is based on the filenames  from method b).

        4.a).Using DBMS_FILE_TRANSFER package 
       
        SQL:ORCL>create or replace directory orcl1 as '+asmdsk1/orcl/datafile';
        SQL:ASM> Alter disgroup asmdsk2 add directory  '+asmdsk2/test';
        SQL:ORCL> create or replace directory orcl2 as '+asmdsk2/test';
        
        SQL:ORCL>
                BEGIN
                  DBMS_FILE_TRANSFER.COPY_FILE(
                  source_directory_object => 'ORCL1',
                  source_file_name => 'users.259.565359071',
                  destination_directory_object => 'ORCL2',
                  destination_file_name => 'USERS01.DBF');
                END;                           

Database altered.

 

          4 b).Using RMAN copy the file to new diskgroup.

            $ rman target system@orcl10
            target database Password:
            connected to target database: ORCL (DBID=1089529226)

            RMAN>
RMAN> COPY DATAFILE '+ASMDSK2/orcl/datafile/users.256.565313879' TO '+ASMDSK1';

                   Starting backup at 03-AUG-05
                   using target database controlfile instead of recovery catalog
                   allocated channel: ORA_DISK_1
                   channel ORA_DISK_1: sid=146 devtype=DISK
                   channel ORA_DISK_1: starting datafile copy
                   input datafile fno=00004 name=+ASMDSK2/orcl/datafile/users.256.565313879
                   output filename=+ASMDSK1/orcl/datafile/users.259.565359071 tag=TAG20050803T12110
                   9 recid=2 stamp=565359071
                   channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:03
                   Finished backup at 03-AUG-05

 

5)  Rename the file to point to new location.
-------------------------------------------
      
If you have used DBMS_FILE_TRANSFER (method 4 a)) use the following command to rename:
       SQL:ORCL> ALTER DATABASE RENAME FILE '+ASMDSK2/orcl/datafile/users.256.565313879' TO '+ASMDSK1/orcl/datafile/users.259.565359071'

Database altered.

      If you have used RMAN (method 4 b) use the following option of RMAN
                 RMAN run {
                                      set newname for datafile '+ASMDSK2/orcl/datafile/users.256.565313879'                                                                         to '+ASMDSK1/orcl/datafile/users.259.565359071' ;
                                    switch datafile all; --
更新控制文件
                                    }

6)  Recover the file.
-------------------
           SQL:ORCL> RECOVER DATAFILE '+ASMDSK1/orcl/datafile/users.259.565359071'
                             Media recovery complete.

7)  Bring the file online.
-----------------------
             SQL:ORCL>ALTER DATABASE DATAFILE '+ASMDSK1/orcl/datafile/users.259.565359071' ONLINE

                                 Database altered.

8) Verify the new file location.
---------------------------------
           SQL:ORCL> SELECT FILE_NAME FROM DBA_DATA_FILES;

                    FILE_NAME
                   -------------------------------------------------------------------------------
                  +ASMDSK1/orcl/datafile/users.259.565359071
                  +ASMDSK1/orcl/sysaux01.dbf
                  +ASMDSK1/orcl/undotbs01.dbf
                  +ASMDSK1/orcl/system01.dbf

 

9) Delete the file from its original location either per SQLPLUS or per ASMCMD:

   e.g.: SQL:ASM> ALTER DISKGROUP ASMDSK2 DROP FILE users.256.565313879;

   or:   ASMCMD> rm -rf <filename>

Note:
      Most Automatic Storage Management files do not need to be manually deleted because, as Oracle managed files, they are removed automatically when they are no longer needed.

      However, if you need to drop an Oracle Managed File (OMF) manually you should use the fully qualified filename if you reference the file. Otherwise you will get an error (e.g. ORA-15177).

   e.g.: SQL:ASM> ALTER DISKGROUP ASMDSK2 DROP FILE '+ASMDSK2/orcl/datafile/users.256.565313879';

 

Note: The steps provided above assume that the database is open and in Archivelog mode.    Besides these steps are not appropriated for system or sysaux datafiles. For System and Sysaux an approach similar to the one given below can be used:

 

   1. Create a Copy of datafile in target Diskgroup:
      RMAN> backup as copy tablespace system format '<New DG>'; 
       RMAN> backup as copy tablespace sysaux format '<New DG>';

   2. Then shutdown the database and restart to a mounted state

      RMAN> shutdown immediate;
      RMAN> startup mount; 

   3. switch the datafiles to the copy

     RMAN> switch tablespace system to copy;
      RMAN> switch tablespace sysaux to copy;

   4. Recover the changes made to these tablespaces;
      RMAN> recover database;

 

 

 

 

From Oracle

-------------------------------------------------------------------------------------------------------

QQ: 492913789
Email: ahdba@qq.com
Blog: http://www.cndba.cn/dave

DBA1 群:62697716();   DBA2 群:62697977()   DBA3 群:62697850()  

DBA 超级群:63306533();  DBA4 群: 83829929  DBA5群: 142216823   

聊天 群:40132017   聊天2群:69087192

--加群需要在备注说明Oracle表空间和数据文件的关系,否则拒绝申请

<think>好的,用户现在的问题是想查找未被数据库记录的文件列表,也就是那些存在于文件系统中但未被数据库跟踪的文件。我需要结合之前的引用内容来给出合适的解决方案。 首先,引用[1]提到FBDA存储修改前的行数据到归档中,并维护元数据。这可能涉及到数据库如何跟踪文件,但用户的问题是关于未被跟踪的文件,所以可能需要对比数据库记录和实际文件系统。 引用[2]提到了/etc/oratab文件列出多个ASM实例,以及ORA-12157错误,这可能与Oracle的存储管理有关。ASM(自动存储管理)用于管理数据库文件,如果用户使用ASM,可能需要通过ASM实例来检查管理的文件,未被ASM管理的文件可能不在数据库记录中。 引用[3]是关于Oracle Real Application Testing的参考资料,可能不直接相关,但其中提到的Oracle文档可能有帮助,比如《Oracle Database SQL Language Reference》或RAT Testing Guide,但用户的问题更偏向于文件管理。 接下来,用户需要找出未被数据库跟踪的文件。可能的步骤包括: 1. **确定数据库文件目录**:数据库通常有特定的数据文件目录,比如Oracle的datafiles、redo logs等,这些在参数文件中配置,如通过`SELECT name FROM v$datafile;`查询。 2. **对比文件系统文件列表**:使用操作系统命令(如`find`或`ls`)列出指定目录下的所有文件,然后排除数据库记录中的文件。 3. **处理ASM实例**:如果使用ASM,可能需要通过ASMCMD工具来查看管理的文件,未被ASM管理的文件可能位于其他位置。 4. **检查归档和日志文件**:引用[1]中的FBDA归档文件可能属于数据库跟踪的一部分,但用户可能想排除这些。 需要注意权限问题,比如访问ASM需要特定权限,或者操作系统文件的读取权限。此外,临时文件或日志文件可能未被正式记录,需要根据具体情况处理。 可能的相关问题包括如何处理ASM管理的文件,如何确保文件系统与数据库记录一致,或者如何清理未跟踪的文件。需要建议用户谨慎操作,避免删除重要文件,并在生产环境中备份。</think>要查找未被数据库跟踪的文件列表,需结合数据库的文件管理机制和操作系统的文件系统进行对比分析。以下是具体步骤: --- ### **1. 确定数据库跟踪的文件范围** 数据库通常通过以下方式记录文件: - **数据文件**:存储表空间数据,路径记录在`v$datafile`视图中 ```sql SELECT name FROM v$datafile; -- Oracle示例 ``` - **日志文件**:如重做日志、归档日志(参考FBDA的归档机制[^1]) - **控制文件**:记录数据库结构,路径在参数文件中定义 - **ASM管理的文件**:若使用自动存储管理(ASM),文件由ASM实例统一管理[^2] --- ### **2. 获取操作系统文件列表** 在数据库服务器上,通过命令列出存储路径中的文件: ```bash find /oracle/data -type f # 假设数据库文件存储在/oracle/data目录 ``` --- ### **3. 对比差异** 将数据库记录的文件名与操作系统文件列表进行对比,筛选出未被记录的文件。例如: ```sql -- 生成数据库文件列表导出到文件 SPOOL /tmp/db_files.txt SELECT name FROM v$datafile; SELECT member FROM v$logfile; SPOOL OFF ``` ```bash # 使用grep对比差异 grep -vFf /tmp/db_files.txt /tmp/os_files.txt > /tmp/untracked_files.txt ``` --- ### **4. 特殊场景处理** - **ASM环境**:通过`asmcmd`工具查询ASM实例管理的文件 ```bash asmcmd ls '+DATA/orcl' # 列出ASM磁盘组中的文件 ``` - **OCFS2文件系统**:注意共享存储权限问题(参考ORA-12157错误场景[^2]) --- ### **5. 注意事项** - **临时文件**:如`tempfile`可能动态创建,需检查`v$tempfile` - **外部表文件**:通过`CREATE DIRECTORY`定义的外部路径需单独分析 - **备份/归档文件**:FBDA归档的旧版本数据可能单独存储[^1] ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值