How to Create Transportable Tablespaces Where the Source and Destination are ASM-Based (Doc ID 394798.1)
APPLIES TO:
Oracle Database - Enterprise Edition - Version 10.1.0.2 to 11.2.0.3 [Release 10.1 to 11.2]
Oracle Database Cloud Schema Service - Version N/A and later
Oracle Database Exadata Express Cloud Service - Version N/A and later
Oracle Database Exadata Cloud Machine - Version N/A and later
Oracle Cloud Infrastructure - Database Service - Version N/A and later
Information in this document applies to any platform.
***Checked for relevance on 28-May-2010***
GOAL
The purpose of this note is to describe the method to create transportable tablespaces(TTS) where the source and destination databases are ASM-based. This method uses standard utilities such as; DataPump and the database package dbms_file_transfer. The dbms_file_transfer package will be used to transfer the Datapump metadata and datafiles to the remote database server.
本说明的目的是描述在源数据库和目标数据库均基于ASM的情况下创建可传输表空间(TTS)的方法。此方法使用标准实用程序,例如;DataPump 和数据库包 dbms_file_transfer。dbms_file_transfer 软件包将用于将Datapump元数据和数据文件传输到远程数据库服务器。
This note will illustrate a working example of creating and plugging in transportable tablespaces. In the example two servers, host1 and host2 are in different locations, with each one on an independent Hitachi storage array. Server host1 is the source database and will house database named db1. The server host2, which is deemed the target server and will subscribe to the transportable tables, will house the database called db2.
本文将说明创建和插入传输表空间的工作示例。在示例中,两台服务器host1和host2位于不同的位置,每台服务器都位于一个独立的 Hitachi 存储阵列上。服务器host1是源数据库,并将包含名为db1的数据库。服务器host2被视为目标服务器,并将订阅可移动表,该服务器将容纳名为db2的数据库。
SOLUTION
If the platform of the source and target nodes are different with different endianess, then refer to Note 371556.1
如果源节点和目标节点的平台具有不同的字节序,则请参见Note 371556.1
This note will illustrate a working example of creating and plugging in transportable tablespaces. In the example two servers, host1 and host2 are in different locations, with each one on an independent Hitachi storage array. Server host1 is the source database and will house database named db1. The server host2, which is deemed the target server and will subscribe to the transportable tables, will house the database called db2.
本文将说明创建和插入传输表空间的工作示例。在示例中,两台服务器host1和host2位于不同的位置,每台服务器都位于一个独立的 Hitachi 存储阵列上。服务器host1是源数据库,并将包含名为db1的数据库。服务器host2被视为目标服务器,并将订阅可移动表,该服务器将容纳名为db2的数据库。
TTS Implementation illustration TTS实施说明
Preliminary effort to setup TTS 初步设置TTS
1. Create or use two existing tablespaces on the source database. Although having two tablespaces is not necessary, it was merely shown here to exercise object dependency. Note that OMF is being employed in this illustration, thus please set the init.ora parameter DB_CREATE_FILE_DEST to the appropriate disk group name.
在源数据库上创建或使用两个现有表空间。尽管没有必要具有两个表空间,但此处仅显示了行使对象依赖性。注意,在此示例中使用了OMF,因此,请将init.ora参数DB_CREATE_FILE_DEST设置为适当的磁盘组名称。
SQL> show parameter db_create_file_dest NAME TYPE VALUE ---------------------- ----------- ------------------------------ db_create_file_dest string +DATA SQL> create tablespace tts_1; SQL> create tablespace tts_2;
2. Create a table in TTS_1 and an index in TTS_2 to ensure the tablespaces have object dependencies:
在TTS_1中创建一个表,并在TTS_2中创建一个索引,以确保表空间具有对象依赖性
SQL> connect scott/tiger Connected. SQL> create table emp_copy tablespace tts_1 as select * from emp; Select count(*) from emp_copy; 10 rows returned SQL> create index emp_copy_i on emp_copy (empno) 2 tablespace tts_2;
3. Check to make sure that you have a self contained transportable set. Oracle provides a PLSQL package that aids in this check.
检查并确保您拥有一个独立的可运输套件。Oracle提供了一个PLSQL软件包来帮助进行此检查
SQL> EXECUTE DBMS_TTS.TRANSPORT_SET_CHECK(tts_1,tts_2, TRUE);
Then query the TRANSPORT_SET_VIOLATIONS view, to see if any dependency violations exist.
然后查询TRANSPORT_SET_VIOLATIONS视图,以查看是否存在任何依赖关系违规。
SQL> SELECT * FROM TRANSPORT_SET_VIOLATIONS; No rows returned
4. Create a new Service names entry, which will point to the destination database where the tablespaces will be transported. For example, add the following lines to tnsnames.ora:
创建一个新的 Service names 条目,该条目指向将在其中传输表空间的目标数据库。例如,将以下行添加到tnsnames.ora:
DB2 = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = host2)(PORT = 1521)) ) (CONNECT_DATA = (SERVICE_NAME = host2.us.oracle.com) (INSTANCE_NAME = db2) ) )
5. As SYSTEM, create a database link between the two databases. This is needed because we will be using the DBMS_FILE_TRANSFER package to move metadata between the two databases.
作为SYSTEM,在两个数据库之间创建 database link。这是必需的,因为我们将使用 DBMS_FILE_TRANSFER 包在两个数据库之间移动元数据
SQL> create database link db2 connect to system identified by manager1 using 'db2';
5. Create a directory object in the source database db1, to hold the dumpfile. Since we are using ASM, this needs to be an ASM object:
在源数据库db1中创建一个目录对象,以保存dump文件。由于我们使用的是ASM,因此它必须是一个ASM对象
make sure the directory path ends with an ' ' 确保目录路径以''
SQL> create directory tts_dump as '+DATA';
6. Create another directory object in the source database, which points to an operating system path, for the log file:
在源数据库中为日志文件创建另一个指向操作系统路径的目录对象:
SQL> create directory tts_dump_log as '/export/home/tts_log';
7. Create a directory object in the source database that points to the datafiles.
在源数据库中创建一个指向数据文件的目录对象。
SQL> create directory tts_datafile as '+DATA/db1/datafile';
8. Grant read/write access to the user you will perform the export as (only needed if using a non-privileged user):
授予对您将要执行导出的用户的读/写访问权限(仅在使用非特权用户时才需要)
SQL> grant read, write on directory tts_dump to system; SQL> grant read, write on directory tts_dump_log to system; SQL> grant read, write on directory tts_dump_datafile to system;
9. Repeat the last four steps (5-8) on the target database db2, as well.
.同样,对目标数据库db2重复最后四个步骤(5-8)
10. Make all tablespaces in the transportable set, to read-only.
将可移动集中的所有表空间设置为只读。
SQL> ALTER TABLESPACE tts_1 READ ONLY; SQL> ALTER TABLESPACE tts_2 READ ONLY;
11. Check the status of the tablespaces on the source database
检查源数据库上表空间的状态
SQL> select tablespace_name, status from dba_tablespaces; TABLESPACE_NAME STATUS ------------------------------ --------- SYSTEM ONLINE UNDOTBS1 ONLINE SYSAUX ONLINE TEMP ONLINE USERS ONLINE UNDOTBS2 ONLINE TTS_1 READ ONLY TTS_2 READ ONLY
Export metadata 导出元数据
12. Export the metadata for the two tablespaces 导出两个表空间的元数据
[ora10g@host1]$ expdp system/manager1 directory=tts_dump dumpfile=tts1_db1.dmp logfile=tts_dump_log:tts.log transport_tablespaces=tts_1,tts_2 transport_full_check=y Starting "SYSTEM"."SYS_EXPORT_TRANSPORTABLE_02": system/******** directory=tts_datafile dumpfile=tts1.dmp logfile=tts_dump_log:tts.log transport _tablespaces=tts_1,tts_2 transport_full_check=y Processing object type TRANSPORTABLE_EXPORT/PLUGTS_BLK Processing object type TRANSPORTABLE_EXPORT/TABLE Processing object type TRANSPORTABLE_EXPORT/INDEX Processing object type TRANSPORTABLE_EXPORT/INDEX_STATISTICS Processing object type TRANSPORTABLE_EXPORT/TABLE_STATISTICS Processing object type TRANSPORTABLE_EXPORT/POST_INSTANCE/PLUGTS_BLK Master table "SYSTEM"."SYS_EXPORT_TRANSPORTABLE_02" successfully loaded/unloaded ***********************************************************************Dump file set for SYSTEM.SYS_EXPORT_TRANSPORTABLE_02 is: +DATA/tts1.dmp Job "SYSTEM"."SYS_EXPORT_TRANSPORTABLE_02" successfully completed at 14:00:34
Movement of data and Enabling TTS 数据移动并启用TTS
--After the metadata export, we can revert back the table in read write mode 元数据导出后,我们可以以读写模式还原表
13. Use DBMS_FILE_TRANSFER to send the dump file across to the target
使用 DBMS_FILE_TRANSFER 将转储文件发送到目标
[ora10g@host1]$ sqlplus system/manger1 SQL> begin 2 dbms_file_transfer.put_file 3 (source_directory_object => 'tts_dump', 4 source_file_name => 'tts1_db1.dmp', 5 destination_directory_object => 'tts_dump', 6 destination_file_name => 'tts1_db1.dmp', 7 destination_database => 'db2'); 8 end; 9 /
14. Check the file names on the source database for the two tablespaces being transported.
检查源数据库上正在传输的两个表空间的文件名
SQL> SELECT file_name FROM dba_data_files 2 WHERE tablespace_name LIKE 'TTS%'; FILE_NAME ------------------------------------------------- +DATA/db2/datafile/tts_1.294.590721319 +DATA/db2/datafile/tts_2.295.586721335
15. Transfer the two datafiles to the target database using DBMS_FILE_TRANSFER.
使用DBMS_FILE_TRANSFER将两个数据文件传输到目标数据库。
TTS1 datafile
SQL> begin 2 dbms_file_transfer.put_file 3 (source_directory_object => 'tts_datafile', 4 source_file_name => 'tts_1.294.570721319', 5 destination_directory_object => ' tts_datafile', 6 destination_file_name => 'tts1_db1.dbf', 7 destination_database => 'db2'); 8 end; 9 /
TTS2 datafile
SQL> begin 2 dbms_file_transfer.put_file 3 (source_directory_object => 'tts_datafile', 4 source_file_name => 'tts_2.295.586721335', 5 destination_directory_object => 'tts_datafile', 6 destination_file_name => 'tts2_db1.dbf', 7 destination_database => 'db2'); 8 end; 9 /
16. On the host2 (target server) import the datafile metadata using DataPump.
在host2(目标服务器)上,使用DataPump导入数据文件元数据
imp.par has the following contents: imp.par具有以下内容
directory=tts_dump dumpfile=tts1_db1.dmp logfile=tts_dump_log:tts1.log TRANSPORT_DATAFILES='+DATA1/tts1_db1.dbf','+DATA1/tts2_db1.dbf' keep_master=y
Note, for the TRANSPORT_DATAFILES parameter, you can either use the alias names (files names in the dbms_file_transfer), or use the systems generated names generated by DBMS_FILE_TRANSFER (these start with the name 'File_Transfer.xxxx.xxxxxx'). To determine the name system generated names, use the asmcmd line tool by simply doing a 'cd +DATA/db2/datafile', followed by the 'ls -l' command.
注意,对于 TRANSPORT_DATAFILES 参数,可以使用别名(dbms_file_transfer 中的文件名),也可以使用由 DBMS_FILE_TRANSFER 生成的系统生成的名称(这些名称以'File_Transfer.xxxx.xxxxxx'开头)。 要确定系统生成的名称,请使用asmcmd行工具,只需执行'cd +DATA/db2/datafile',然后执行'ls -l'命令即可。
[ora10g@host2]$ impdp system/oracle parfile=imp.par Master table "SYSTEM"."SYS_IMPORT_TRANSPORTABLE_03" successfully loaded/unloaded Starting "SYSTEM"."SYS_IMPORT_TRANSPORTABLE_03": system/******** parfile=impdp.par Processing object type TRANSPORTABLE_EXPORT/PLUGTS_BLK Processing object type TRANSPORTABLE_EXPORT/TABLE Processing object type TRANSPORTABLE_EXPORT/INDEX Processing object type TRANSPORTABLE_EXPORT/INDEX_STATISTICS Processing object type TRANSPORTABLE_EXPORT/TABLE_STATISTICS Processing object type TRANSPORTABLE_EXPORT/POST_INSTANCE/PLUGTS_BLK Job "SYSTEM"."SYS_IMPORT_TRANSPORTABLE_03" successfully completed at 15:05:00
17. Switch the tablespaces back to read-write mode. 将表空间切换回读写模式
SQL> ALTER TABLESPACE tts_1 READ WRITE; SQL> ALTER TABLESPACE tts_2 READ WRITE;
18. Verify that the datafiles are successfully plugged in. 验证是否成功插入
SQL> select name from v$datafile; NAME -------------------------------------------------- +DATA/db2/datafile/system.271.599658207 +DATA/db2/datafile/undotbs1.268.599658207 +DATA/db2/datafile/sysaux.270.599658207 +DATA/db2/datafile/users.267.599658209 +DATA/db2/datafile/example.262.599658459 +DATA/db2/datafile/tts2_db1.dbf +DATA/db2/datafile/tts1_db1.dbf
19. Validate the data got there by selecting the required tables.
通过选择所需的表来验证那里的数据
SQL> create table emp_copy tablespace tts_1 as select * from emp; SQL> Select count(*) from emp_copy; 10 rows returned
-----
NOTE: Similar procedure is applicable for filesystem to ASM and viceversa
注意:类似的过程适用于ASM到文件系统,反之亦然
REFERENCES
NOTE:371556.1 - How to Migrate to different Endian Platform Using Transportable Tablespaces With RMAN
来源:https://www.cnblogs.com/zylong-sys/p/12014046.html