表空间移动(transporting tablespaces)

--表空间移动(transporting tablespaces)
--------------------------------------2014/01/15
 
1. 表空间传输步骤简介。
 
              a. 选择一个自包含的表空间集合。
              b. 在源数据库端,设置需要传输的表空间集合为只读状态。
              c. 在源数据库端,导出表空间中的metadata。
              d. 传输dmp文件和表空间数据文件到目标数据库服务器中。
              e. 将源数据库端表空间恢复成读写状态。
              f. 在目标数据库中建立与表空间对应的用户信息。如果使用impdp,可以选者remap_schema重新定位用户,不过重定位的用户也必须是存在的。
             g. 在目标数据库中倒入表空间。
 
2. 操作步骤。
 
源:windows服务器
 
SQL> create tablespace tran datafile ‘D:\app\Hujie\oradata\august\tran01.DBF’ size 30M;
SQL> create user tran identified by tran default tablespace tran;
SQL> grant connect,resource to tran;
SQL> conn tran/tran;
SQL> create table tran as select * from dict;
 
SQL> select count(1) from tran; 
  COUNT(1)
----------
       835 
SQL> conn sys/dba as sysdba
Connected.
SQL> alter tablespace tran read only;
 
Tablespace altered.
 
SQL> quit
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
 
C:\Users\Hujie>exp '/ as sysdba' tablespaces=tran transport_tablespace=y file=exp_trans.dmp
 
Export: Release 11.2.0.1.0 - Production on Wed Jan 15 09:05:34 2014
 
Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.
 
 
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Export done in WE8MSWIN1252 character set and AL16UTF16 NCHAR character set
Note: table data (rows) will not be exported
About to export transportable tablespace metadata...
For tablespace TRAN ...
. exporting cluster definitions
. exporting table definitions
. . exporting table                           TRAN
. exporting referential integrity constraints
. exporting triggers
. end transportable tablespace metadata export
Export terminated successfully without warnings.
 
将exp_trans.dmp和D:\app\Hujie\oradata\august\tran01.DBF传输到目标linux服务器目录/u01下。
 
目标:linux服务器
SQL> create user tran identified by tran;
 
User created.
 
SQL> grant connect , resource to tran;
 
Grant succeeded.
 
SQL> quit
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
[Oracle@localhost u01]$ ls
app  august01.ctl  exp_trans.dmp  TRAN_lx.DBF(改名测试,原名:TRAN.DBF
 
[Oracle@localhost u01]$ imp \'/ as sysdba\' tablespaces=tran transport_tablespace=y file=exp_trans.dmp datafiles=/u01/TRAN_lx.DBF
 
Import: Release 11.2.0.1.0 - Production on Tue Jan 14 18:06:20 2014
 
Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.
 
 
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
 
Export file created by EXPORT:V11.02.00 via conventional path
About to import transportable tablespace(s) metadata...
import done in ZHS16GBK character set and AL16UTF16 NCHAR character set
import server uses WE8MSWIN1252 character set (possible charset conversion)
export client uses WE8MSWIN1252 character set (possible charset conversion)
. importing SYS's objects into SYS
. importing SYS's objects into SYS
. importing TRAN's objects into TRAN
. . importing table                         "TRAN"
. importing SYS's objects into SYS
Import terminated successfully without warnings.
 
[Oracle@localhost u01]$ sqlplus /nolog
 
SQL*Plus: Release 11.2.0.1.0 Production on Tue Jan 14 18:06:33 2014
 
Copyright (c) 1982, 2009, Oracle.  All rights reserved.
 
SQL> conn tran/tran
Connected.
SQL> select count(1) from tran;
 
  COUNT(1)
----------
       835
 
*改变数据文件的名字不影响导入,所以没有必要使用rman来对文件改名。
RMAN> convert datafile ‘/u01/TRAN.DBF’ db_file_name_convert ‘/u01/TRAN.DBF’,’/u01/TRAN_lx.DBF’;

----使用expdp和impdp参数略微有些不同,请参考下面例子。
导入:
$ expdp \'/ as sysdba\' dumpfile=expdat.dmp direcotry=data_pump_dir transport_tablespaces=sales_1,sales_2 logfile=tts_export.log
导出:
$ impdp \'/ as sysdba\' dumpfile=expdat.dmp dirctory=data_pump_dir transport_datafiles=
    '/u01/oradata/sales_101.dbf',
    '/u01/oradata/sales_201.dbf'
    remap_schema=sales1:crm1 remap_schema=sales2:crm2
    logfile=tts_import.log ----对于用户的切换,imp也可以实现,请看下面例子。
SQL> drop user tran cascade;

User dropped.

SQL> drop tablespace tran;

Tablespace dropped.

SQL> create user nart identified by nart;

User created.

SQL> grant connect,resource to nart;

Grant succeeded.
[Oracle@localhost u01]$ imp \'/ as sysdba\' tablespaces=tran transport_tablespace=y file=exp_trans.dmp datafiles=/u01/TRAN_lx.DBF fromuser=tran touser=nart;
Import: Release 11.2.0.1.0 - Production on Tue Jan 14 19:11:24 2014
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Export file created by EXPORT:V11.02.00 via conventional path
About to import transportable tablespace(s) metadata...
import done in ZHS16GBK character set and AL16UTF16 NCHAR character set
import server uses WE8MSWIN1252 character set (possible charset conversion)
export client uses WE8MSWIN1252 character set (possible charset conversion)
. importing TRAN's objects into NART
. . importing table "TRAN"
Import terminated successfully without warnings.
[Oracle@localhost u01]$ sqlplus /nolog
SQL*Plus: Release 11.2.0.1.0 Production on Tue Jan 14 19:11:41 2014
Copyright (c) 1982, 2009, Oracle.  All rights reserved.
SQL> conn nart/nart
Connected.
SQL> select table_name from user_tables;
TABLE_NAME
------------------------------------------------------------
TRAN
SQL> select count(1) from tran;
  COUNT(1)
----------
835
 
上一篇:Sliverlight实例之 绘制扇形和环形图


下一篇:linux查看磁盘使用情况命令