Thursday, May 22, 2014

Switch datafile to non-default location using RMAN

1.Script to switch the datafile to non-default location
cat rman_switch.cmd
run
{
sql "alter database datafile 6 offline";
set newname for datafile 6 to '+DATA/cvrman/datafile/tbs1_new.dbf';
restore datafile 6;
switch datafile 6;
recover datafile 6;
sql "alter database datafile 6 online";
}
2. Output
$ rman target="/"

Recovery Manager: Release 11.2.0.4.0 - Production on Thu May 22 08:05:30 2014

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

connected to target database: CVRMAN (DBID=657566608)

RMAN> @ rman_switch.cmd

RMAN> run
2> {
3> sql "alter database datafile 6 offline";
4> set newname for datafile 6 to '+DATA/cvrman/datafile/tbs1_new.dbf';
5> restore datafile 6;
6> switch datafile 6;
7> recover datafile 6;
8> sql "alter database datafile 6 online";
9> }
using target database control file instead of recovery catalog
sql statement: alter database datafile 6 offline

executing command: SET NEWNAME

Starting restore at 22-MAY-14
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=34 device type=DISK
allocated channel: ORA_DISK_2
channel ORA_DISK_2: SID=24 device type=DISK
allocated channel: ORA_DISK_3
channel ORA_DISK_3: SID=51 device type=DISK
allocated channel: ORA_DISK_4
channel ORA_DISK_4: SID=49 device type=DISK
allocated channel: ORA_DISK_5
channel ORA_DISK_5: SID=50 device type=DISK

channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00006 to +DATA/cvrman/datafile/tbs1_new.dbf
channel ORA_DISK_1: reading from backup piece +DATA/cvrman/backupset/2014_05_22/nnndf0_tag20140522t051830_0.287.848207921
channel ORA_DISK_1: piece handle=+DATA/cvrman/backupset/2014_05_22/nnndf0_tag20140522t051830_0.287.848207921 tag=TAG20140522T051830
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
Finished restore at 22-MAY-14

datafile 6 switched to datafile copy
input datafile copy RECID=82 STAMP=848217961 file name=+DATA/cvrman/datafile/tbs1_new.dbf

Starting recover at 22-MAY-14
using channel ORA_DISK_1
using channel ORA_DISK_2
using channel ORA_DISK_3
using channel ORA_DISK_4
using channel ORA_DISK_5

starting media recovery
media recovery complete, elapsed time: 00:00:01

Finished recover at 22-MAY-14

sql statement: alter database datafile 6 online

RMAN> **end-of-file**

RMAN> report schema;

Report of database schema for database with db_unique_name CVRMAN

List of Permanent Datafiles
===========================
File Size(MB) Tablespace           RB segs Datafile Name
---- -------- -------------------- ------- ------------------------
1    750      SYSTEM               ***     +DATA/cvrman/datafile/system.256.847354793
2    640      SYSAUX               ***     +DATA/cvrman/datafile/sysaux.257.847354793
3    50       UNDOTBS1             ***     +DATA/cvrman/datafile/undotbs1.318.848201233
4    5        USERS                ***     +DATA/cvrman/datafile/users.259.847354795
5    345      EXAMPLE              ***     +DATA/cvrman/datafile/example.308.847525493
6    10       TBS1                 ***     +DATA/cvrman/datafile/tbs1_new.dbf

List of Temporary Files
=======================
File Size(MB) Tablespace           Maxsize(MB) Tempfile Name
---- -------- -------------------- ----------- --------------------
1    20       TEMP                 32767       +DATA/cvrman/tempfile/temp.268.847355331



No comments: