Copiando Arquivo de Dados pelo ASMCMD no Banco de Dados Oracle 11g

Este artigo tem como objetivo demonstrar como copiar um arquivo de dados (datafile) de um Disco de Grupo para outro no Banco de Dados Oracle 11g.

Segue a demonstração abaixo.

Vamos entrar no banco de dados.

[oracle@linux11gasmdi ~]$ sqlplus sys/******** as sysdba

SQL*Plus: Release 11.2.0.3.0 Production on Tue Apr 2 17:09:57 2013

Copyright (c) 1982, 2011, Oracle.  All rights reserved.

Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - Production
With the Partitioning, Automatic Storage Management, OLAP, Data Mining
and Real Application Testing options

Vamos verificar as tablespaces.

SQL> select * from v$tablespace;

       TS# NAME                           INC BIG FLA ENC
---------- ------------------------------ --- --- --- ---
         0 SYSTEM                         YES NO  YES
         1 SYSAUX                         YES NO  YES
         2 UNDOTBS1                       YES NO  YES
         4 USERS                          YES NO  YES
         3 TEMP                           NO  NO  YES
         6 EXAMPLE                        YES NO  YES

6 rows selected.

SQL>

Vamos verificar os datafiles.

SQL> col file_name for a45
SQL> set lines 500
SQL> select file_name from dba_data_files;

FILE_NAME
---------------------------------------------
+DGDATA/orcl/users01.dbf
+DGDATA/orcl/undotbs01.dbf
+DGDATA/orcl/sysaux01.dbf
+DGDATA/orcl/system01.dbf
+DGDATA/orcl/example01.dbf
SQL>

Vamos verificar os Discos de Grupos.

SQL> select name from v$asm_diskgroup;

NAME
------------------------------
DGARCH
DGDATA
DGREDOA
DGREDOB
SQL>

Vamos copiar um datafile da Tablespace EXAMPLE.
Vamos colocar a tablespace neste momento em offline.

SQL> alter tablespace EXAMPLE offline;

Tablespace altered.

SQL> !
[oracle@linux11gasmdi ~]$

Vamos carregar as variáveis de ambiente do Grid. Pode-se exportar o ORACLE_HOME que está no arquivo oratab “/etc/oratab” do Grid (+ASM) ou se for RAC (+ASMn) aonde “n” é o número do node ou carregar um arquivo que já está com as variáveis de ambiente para o Grid.
Vou mostrar primeiramente com o oratab.

[oracle@linux11gasmdi ~]$ cat /etc/oratab
#Backup file is  /u01/app/oracle/product/11.2.0/grid/srvm/admin/oratab.bak.linux11gasmdi line added by Agent
#

# This file is used by ORACLE utilities.  It is created by root.sh
# and updated by either Database Configuration Assistant while creating
# a database or ASM Configuration Assistant while creating ASM instance.

# A colon, ':', is used as the field terminator.  A new line terminates
# the entry.  Lines beginning with a pound sign, '#', are comments.
#
# Entries are of the form:
#   $ORACLE_SID:$ORACLE_HOME:<N|Y>:
#
# The first and second fields are the system identifier and home
# directory of the database respectively.  The third filed indicates
# to the dbstart utility that the database should , "Y", or should not,
# "N", be brought up at system boot time.
#
# Multiple entries with the same $ORACLE_SID are not allowed.
#
#
+ASM:/u01/app/oracle/product/11.2.0/grid:N
orcl:/u01/app/oracle/product/11.2.0/db_1:N         # line added by Agent
[oracle@linux11gasmdi ~]$ export ORACLE_HOME=/u01/app/oracle/product/11.2.0/grid
[oracle@linux11gasmdi ~]$ export ORACLE_SID=+ASM

Com o arquivo já com as variáveis de ambiente do grid, vamos entrar no asm e realizar a copia do datafile para outro disco de grupo.

[oracle@linux11gasmdi ~]$ . /etc/grid.sh
[oracle@linux11gasmdi ~]$ asmcmd
ASMCMD> ls -l +DGDATA/orcl/example01.dbf
Type      Redund  Striped  Time             Sys  Name
                                            N    example01.dbf => +DGDATA/ORCL/DATAFILE/UNKNOWN.262.811462599
ASMCMD> cp +DGDATA/orcl/example01.dbf +DGARCH/orcl/example01.dbf
copying +DGDATA/orcl/example01.dbf -> +DGARCH/orcl/example01.dbf
ASMCMD> rm +DGDATA/orcl/example01.dbf
ASMCMD> exit
[oracle@linux11gasmdi ~]$ exit
exit

Vamos alterar o datafile no controlfile para que o mesmo reconheça o novo destino do datafile e colocar a tablespace online.

SQL> ALTER DATABASE RENAME FILE '+DGDATA/orcl/example01.dbf' TO '+DGARCH/orcl/example01.dbf';

Database altered.

SQL> alter tablespace EXAMPLE online;

Tablespace altered.

SQL> exit
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - Production
With the Partitioning, Automatic Storage Management, OLAP, Data Mining
and Real Application Testing options
[oracle@linux11gasmdi ~]$

Pronto realizamos a copia do datafile para outro disco de grupo.
Lembrando que para este procedimento seja realizado apenas no 11g, na versão 10g deve-se utilizar a ferramenta RMAN.

%name Copiando Arquivo de Dados pelo ASMCMD no Banco de Dados Oracle 11g

Autor: Maycon Tomiasi

Formado em Tecnologia da Informação na FIPP (Faculdade de Informática de Presidente Prudente), Analista DBA Oracle pela Teiko Soluções em Tecnologia da Informação, residente em Blumenau/ SC, Certificado OCP 10g/11g/12c, OCS 11g Implementation, OCE 11g Performance Tuning, OCE 11g RAC & GRID e OPN Specialist. Conhecimentos em PHP.