Transport the tablespace on Same OS platform

Transport the tablespace on Same OS platform

You want to transport tablespaces using RMAN backups instead of performing the transportable tablespaces operation  on the live production database.

Source Database : MYTEST

Target Database : MYDB

Transportable Tablespace : TRANSPORT

  • You can also transport tablespaces from a “live” database using an alternative transport tablespace technique explained in the Oracle manula,The disadvantages in that method is that the transportable tablespces must be put in  a read only mode, thus affecting database availablity. it not only may be time consuming to put the tablespace into read only mode but users cann’t write to those tablespaces for the duration of the tablespace transport. You don’t have any of these limitations when you use RMAN backups as the basis of your transportable tablespace operation.
  • RMAN backups to create transportable tablespaces is that your RMAN backups must be recoverable to the SCN at which you want the transportable tablespaces.
  • RMAN creates an auxiliary database instance through which it creates the transportable tablespace sets. RMAN does quites a few things in order to prepare the transportable table set.

The following example shows how to transport tablespaces on identical operating system platforms by utilizing RMAN backups.

Step 1: Make sure the tablespaces you plan to transport are self contained. To be considered self contained, the tablespaces se you want to transport
muchn’t contain references pointing outside those tablespaces, such as an index on a table that doesn’t belong to one of the tablespaces you’re transporting.

SQL> execute sys.dbms_tts.transport_set_check(‘transport’,TRUE);

PL/SQL procedure successfully completed.

Step 2: Generate the transportable tablespace set by issuing the transport tablespace command.

RMAN> transport tablespace ‘TRANSPORT’
2> tablespace destination ‘/home/oracle/oracle/transporttbs’
3> auxiliary destination ‘/home/oracle/oracle/auxdest’;

Creating automatic instance, with SID=’gjEd’

initialization parameters used for automatic instance:
db_name=MYTEST
compatible=10.2.0.1.0
db_block_size=8192
db_files=200
db_unique_name=tspitr_MYTEST_gjEd
large_pool_size=1M
shared_pool_size=110M
#No auxiliary parameter file used
db_create_file_dest=/home/oracle/oracle/auxdest
control_files=/home/oracle/oracle/auxdest/cntrl_tspitr_MYTEST_gjEd.f

starting up automatic instance MYTEST

Oracle instance started

Total System Global Area     201326592 bytes

Fixed Size                     1218508 bytes
Variable Size                146802740 bytes
Database Buffers              50331648 bytes
Redo Buffers                   2973696 bytes
Automatic instance created

contents of Memory Script:
{
# set the until clause
set until  scn 580515;
# restore the controlfile
restore clone controlfile;
# mount the controlfile
sql clone ‘alter database mount clone database’;
# archive current online log for tspitr to a resent until time
sql ‘alter system archive log current’;
# avoid unnecessary autobackups for structural changes during TSPITR
sql ‘begin dbms_backup_restore.AutoBackupFlag(FALSE); end;’;
# resync catalog after controlfile restore
resync catalog;
}
executing Memory Script

executing command: SET until clause

Starting restore at 29-MAY-10
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: sid=37 devtype=DISK

channel ORA_AUX_DISK_1: starting datafile backupset restore
channel ORA_AUX_DISK_1: restoring control file
channel ORA_AUX_DISK_1: reading from backup piece /home/oracle/oracle/product/10.2.0/db_1/flash_recovery_area/MYTEST/autobackup/2010_05_29/o1_mf_s_720285190_60216pdz_.bkp
channel ORA_AUX_DISK_1: restored backup piece 1
piece handle=/home/oracle/oracle/product/10.2.0/db_1/flash_recovery_area/MYTEST/autobackup/2010_05_29/o1_mf_s_720285190_60216pdz_.bkp tag=TAG20100529T151310
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:03
output filename=/home/oracle/oracle/auxdest/cntrl_tspitr_MYTEST_gjEd.f
Finished restore at 29-MAY-10

sql statement: alter database mount clone database

sql statement: alter system archive log current

sql statement: begin dbms_backup_restore.AutoBackupFlag(FALSE); end;

starting full resync of recovery catalog
full resync complete
released channel: ORA_DISK_1
released channel: ORA_AUX_DISK_1

contents of Memory Script:
{
# generated tablespace point-in-time recovery script
# set the until clause
set until  scn 580515;
# set an omf destination filename for restore
set newname for clone datafile  1 to new;
# set an omf destination filename for restore
set newname for clone datafile  2 to new;
# set an omf destination filename for restore
set newname for clone datafile  3 to new;
# set an omf destination tempfile
set newname for clone tempfile  1 to new;
# set a destination filename for restore
set newname for datafile  8 to
“/home/oracle/oracle/transporttbs/transport01.dbf”;
# rename all tempfiles
switch clone tempfile all;
# restore the tablespaces in the recovery set plus the auxilliary tablespaces
restore clone datafile  1, 2, 3, 8;
switch clone datafile all;
#online the datafiles restored or flipped
sql clone “alter database datafile  1 online”;
#online the datafiles restored or flipped
sql clone “alter database datafile  2 online”;
#online the datafiles restored or flipped
sql clone “alter database datafile  3 online”;
#online the datafiles restored or flipped
sql clone “alter database datafile  8 online”;
# make the controlfile point at the restored datafiles, then recover them
recover clone database tablespace  “TRANSPORT”, “SYSTEM”, “UNDOTBS1″, “SYSAUX” delete archivelog;
alter clone database open resetlogs;
# PLUG HERE the creation of a temporary tablespace if export fails due to lack
# of temporary space.
# For example in Unix these two lines would do that:
#sql clone “create tablespace aux_tspitr_tmp
#           datafile ”/tmp/aux_tspitr_tmp.dbf” size 500K”;
}
executing Memory Script

executing command: SET until clause

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

renamed temporary file 1 to /home/oracle/oracle/auxdest/TSPITR_MYTEST_GJED/datafile/o1_mf_temp_%u_.tmp in control file

Starting restore at 29-MAY-10
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: sid=39 devtype=DISK

channel ORA_AUX_DISK_1: starting datafile backupset restore
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
restoring datafile 00001 to /home/oracle/oracle/auxdest/TSPITR_MYTEST_GJED/datafile/o1_mf_system_%u_.dbf
restoring datafile 00002 to /home/oracle/oracle/auxdest/TSPITR_MYTEST_GJED/datafile/o1_mf_undotbs1_%u_.dbf
restoring datafile 00003 to /home/oracle/oracle/auxdest/TSPITR_MYTEST_GJED/datafile/o1_mf_sysaux_%u_.dbf
restoring datafile 00008 to /home/oracle/oracle/transporttbs/transport01.dbf
channel ORA_AUX_DISK_1: reading from backup piece /home/oracle/oracle/product/10.2.0/db_1/flash_recovery_area/MYTEST/backupset/2010_05_29/o1_mf_nnndf_TAG20100529T154405_60230pbp_.bkp
channel ORA_AUX_DISK_1: restored backup piece 1
piece handle=/home/oracle/oracle/product/10.2.0/db_1/flash_recovery_area/MYTEST/backupset/2010_05_29/o1_mf_nnndf_TAG20100529T154405_60230pbp_.bkp tag=TAG20100529T154405
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:01:38
Finished restore at 29-MAY-10

datafile 1 switched to datafile copy
input datafile copy recid=9 stamp=720287348 filename=/home/oracle/oracle/auxdest/TSPITR_MYTEST_GJED/datafile/o1_mf_system_602372kr_.dbf
datafile 2 switched to datafile copy
input datafile copy recid=10 stamp=720287348 filename=/home/oracle/oracle/auxdest/TSPITR_MYTEST_GJED/datafile/o1_mf_undotbs1_602372qx_.dbf
datafile 3 switched to datafile copy
input datafile copy recid=11 stamp=720287348 filename=/home/oracle/oracle/auxdest/TSPITR_MYTEST_GJED/datafile/o1_mf_sysaux_602372o0_.dbf
datafile 8 switched to datafile copy
input datafile copy recid=12 stamp=720287348 filename=/home/oracle/oracle/transporttbs/transport01.dbf

sql statement: alter database datafile  1 online

sql statement: alter database datafile  2 online

sql statement: alter database datafile  3 online

sql statement: alter database datafile  8 online

Starting recover at 29-MAY-10
using channel ORA_AUX_DISK_1

starting media recovery

archive log thread 1 sequence 15 is already on disk as file /home/oracle/oracle/product/10.2.0/db_1/flash_recovery_area/MYTEST/archivelog/2010_05_29/o1_mf_1_15_6022vddo_.arc
archive log thread 1 sequence 16 is already on disk as file /home/oracle/oracle/product/10.2.0/db_1/flash_recovery_area/MYTEST/archivelog/2010_05_29/o1_mf_1_16_60235d3p_.arc
archive log filename=/home/oracle/oracle/product/10.2.0/db_1/flash_recovery_area/MYTEST/archivelog/2010_05_29/o1_mf_1_15_6022vddo_.arc thread=1 sequence=15
archive log filename=/home/oracle/oracle/product/10.2.0/db_1/flash_recovery_area/MYTEST/archivelog/2010_05_29/o1_mf_1_16_60235d3p_.arc thread=1 sequence=16
media recovery complete, elapsed time: 00:00:03
Finished recover at 29-MAY-10

database opened

contents of Memory Script:
{
#mark read only the tablespace that will be exported
sql clone “alter tablespace TRANSPORT read only”;
# create directory for datapump export
sql clone “create or replace directory STREAMS_DIROBJ_DPDIR as ”
/home/oracle/oracle/transporttbs””;
# export the tablespaces in the recovery set
host ‘expdp userid=/”/@/(DESCRIPTION=/(ADDRESS=/(PROTOCOL=beq/)/(PROGRAM=/home/oracle/oracle/product/10.2.0/db_1/bin/oracle/)/(ARGV0=oraclegjEd/)/(ARGS=^’/(DESCRIPTION=/(LOCAL=YES/)/(ADDRESS=/(PROTOCOL=beq/)/)/)^’/)/(ENVS=^’ORACLE_SID=gjEd^’/)/)/(CONNECT_DATA=/(SID=gjEd/)/)/) as sysdba/” transport_tablespaces=
TRANSPORT dumpfile=
dmpfile.dmp directory=
STREAMS_DIROBJ_DPDIR logfile=
explog.log’;
}
executing Memory Script

sql statement: alter tablespace TRANSPORT read only

sql statement: create or replace directory STREAMS_DIROBJ_DPDIR as ”/home/oracle/oracle/transporttbs”

Export: Release 10.2.0.1.0 – Production on Saturday, 29 May, 2010 15:49:28

Copyright (c) 2003, 2005, Oracle.  All rights reserved.

Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 – Production
With the Partitioning, OLAP and Data Mining options
Starting “SYS”.”SYS_EXPORT_TRANSPORTABLE_01″:  userid=”/********@(DESCRIPTION=(ADDRESS=(PROTOCOL=beq)(PROGRAM=/home/oracle/oracle/product/10.2.0/db_1/bin/oracle)(ARGV0=oraclegjEd)(ARGS=/(DESCRIPTION=/(LOCAL=YES/)/(ADDRESS=/(PROTOCOL=beq/)/)/))(ENVS=ORACLE_SID=gjEd))(CONNECT_DATA=(SID=gjEd))) AS SYSDBA” transport_tablespaces= TRANSPORT dumpfile=dmpfile.dmp directory=STREAMS_DIROBJ_DPDIR logfile=explog.log
Processing object type TRANSPORTABLE_EXPORT/PLUGTS_BLK
Processing object type TRANSPORTABLE_EXPORT/POST_INSTANCE/PLUGTS_BLK
Master table “SYS”.”SYS_EXPORT_TRANSPORTABLE_01″ successfully loaded/unloaded
******************************************************************************
Dump file set for SYS.SYS_EXPORT_TRANSPORTABLE_01 is:
/home/oracle/oracle/transporttbs/dmpfile.dmp
Job “SYS”.”SYS_EXPORT_TRANSPORTABLE_01″ successfully completed at 15:49:48

host command complete
/*
The following command may be used to import the tablespaces.
Substitute values for <logon> and <directory>.
impdp <logon> directory=<directory> dumpfile= ‘dmpfile.dmp’ transport_datafiles= /home/oracle/oracle/transporttbs/transport01.dbf
*/
————————————————————–
– Start of sample PL/SQL script for importing the tablespaces
————————————————————–
– creating directory objects
CREATE DIRECTORY STREAMS$DIROBJ$1 AS  ‘/home/oracle/oracle/transporttbs/’;
CREATE DIRECTORY STREAMS$DIROBJ$DPDIR AS  ‘/home/oracle/oracle/transporttbs’;
/* PL/SQL Script to import the exported tablespaces */
DECLARE
– the datafiles
tbs_files     dbms_streams_tablespace_adm.file_set;
cvt_files     dbms_streams_tablespace_adm.file_set;
– the dumpfile to import
dump_file     dbms_streams_tablespace_adm.file;
dp_job_name   VARCHAR2(30) := NULL;
– names of tablespaces that were imported
ts_names       dbms_streams_tablespace_adm.tablespace_set;
BEGIN
– dump file name and location
dump_file.file_name :=  ‘dmpfile.dmp’;
dump_file.directory_object := ‘STREAMS$DIROBJ$DPDIR’;
– forming list of datafiles for import
tbs_files( 1).file_name :=  ‘transport01.dbf’;
tbs_files( 1).directory_object :=  ‘STREAMS$DIROBJ$1′;
– import tablespaces
dbms_streams_tablespace_adm.attach_tablespaces(
datapump_job_name      => dp_job_name,
dump_file              => dump_file,
tablespace_files       => tbs_files,
converted_files        => cvt_files,
tablespace_names       => ts_names);
– output names of imported tablespaces
IF ts_names IS NOT NULL AND ts_names.first IS NOT NULL THEN
FOR i IN ts_names.first .. ts_names.last LOOP
dbms_output.put_line(‘imported tablespace ‘|| ts_names(i));
END LOOP;
END IF;
END;
/
– dropping directory objects
DROP DIRECTORY STREAMS$DIROBJ$1;
DROP DIRECTORY STREAMS$DIROBJ$DPDIR;
————————————————————–
– End of sample PL/SQL script
————————————————————–

Removing automatic instance
shutting down automatic instance
Oracle instance shut down
Automatic instance removed
auxiliary instance file /home/oracle/oracle/auxdest/cntrl_tspitr_MYTEST_gjEd.f deleted
auxiliary instance file /home/oracle/oracle/auxdest/TSPITR_MYTEST_GJED/datafile/o1_mf_system_602372kr_.dbf deleted
auxiliary instance file /home/oracle/oracle/auxdest/TSPITR_MYTEST_GJED/datafile/o1_mf_undotbs1_602372qx_.dbf deleted
auxiliary instance file /home/oracle/oracle/auxdest/TSPITR_MYTEST_GJED/datafile/o1_mf_sysaux_602372o0_.dbf deleted
auxiliary instance file /home/oracle/oracle/auxdest/TSPITR_MYTEST_GJED/datafile/o1_mf_temp_6023bh4x_.tmp deleted
auxiliary instance file /home/oracle/oracle/auxdest/TSPITR_MYTEST_GJED/onlinelog/o1_mf_1_6023b963_.log deleted
auxiliary instance file /home/oracle/oracle/auxdest/TSPITR_MYTEST_GJED/onlinelog/o1_mf_2_6023bb7g_.log deleted
auxiliary instance file /home/oracle/oracle/auxdest/TSPITR_MYTEST_GJED/onlinelog/o1_mf_3_6023bc3y_.log deleted

Operation :

  • RMAN starts an auxiliary instance in nomount mode, you don’t have to specify a parameter file for this auixliary instance, RMAN automatically creates the file.
  • RMAN restores a backup of the target database control file and uses it to mount the auxiliary database.
  • Using the switch operation, RMAN restores all datafiles from the target database for the auxiliary instance. These files are restored to the location specified by the auxiliary destination clause in the transportable tablespace command.
  • RMAN also stores the files pertaining to the tablepsaces in the transportable tablspace set in the location specified by the tablespace destination parameter in the transport tablespace command.
  • Once the datafile from the target database are all restored to the auxiliary database location, RMAN performs a point in time recovery of the auxiliary instance.
  • Rman invoked the data pump Export utility to create teh export dump file containg the tablespaces in the transportable tablespace set.
  • Export dump file is places in the location specified by the tablespace destination clause of the transport tablespace command.
  • RMAN alsp generates a Data pump import script you can use to plug in the transported tablespaces into target database.
  • RMAN shuts down the auxiliary instance and automatically deletes all the files created and used during the transport tablespace process. The only files that remain are the transportable set files,
    data pump export log and sample Datapump Import the tablespaces.

Step 4:  Run import script files to target database. The script files generated when you’re done tablespace transport command used by rman , source database.

RMAN> SQL> select name from v$database;

NAME
———
MYDB

SQL> conn system/azar@mydb
Connected.
SQL> CREATE DIRECTORY STREAMS$DIROBJ$1 AS  ‘/home/oracle/oracle/transporttbs/’;

Directory created.

SQL> CREATE DIRECTORY STREAMS$DIROBJ$DPDIR AS  ‘/home/oracle/oracle/transporttbs’;

Directory created.

SQL>DECLARE
– the datafiles
tbs_files     dbms_streams_tablespace_adm.file_set;
cvt_files     dbms_streams_tablespace_adm.file_set;
– the dumpfile to import
dump_file     dbms_streams_tablespace_adm.file;
dp_job_name   VARCHAR2(30) := NULL;
– names of tablespaces that were imported
ts_names       dbms_streams_tablespace_adm.tablespace_set;
BEGIN
– dump file name and location
dump_file.file_name :=  ‘dmpfile.dmp’;
dump_file.directory_object := ‘STREAMS$DIROBJ$DPDIR’;
– forming list of datafiles for import
tbs_files( 1).file_name :=  ‘transport01.dbf’;
tbs_files( 1).directory_object :=  ‘STREAMS$DIROBJ$1′;
– import tablespaces
dbms_streams_tablespace_adm.attach_tablespaces(
datapump_job_name      => dp_job_name,
dump_file              => dump_file,
tablespace_files       => tbs_files,
converted_files        => cvt_files,
tablespace_names       => ts_names);
– output names of imported tablespaces
IF ts_names IS NOT NULL AND ts_names.first IS NOT NULL THEN
FOR i IN ts_names.first .. ts_names.last LOOP
dbms_output.put_line(‘imported tablespace ‘|| ts_names(i));
END LOOP;
END IF;
END;
31  /

PL/SQL procedure successfully completed.

SQL> select tablespace_name from dba_data_files;

TABLESPACE_NAME
——————————
SYSTEM
UNDOTBS1
SYSAUX
USERS
TRANSPORT

SQL>

Possible Error :-

RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of tranport tablespace command at 05/29/2010 15:36:00
RMAN-06004: ORACLE error from recovery catalog database: RMAN-20202: tablespace not found in the recovery catalog

If you don’t have backup copy of your transportable tablespace in RMAN backupsets, the above error will be shown.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值