Oracle 12C实现跨网络传输数据库详解
前言
跨网络传输数据库,可以通过使用network_link参数来执行导入操作,导入操作将使用数据库链路,不需要生成dump文件。
操作步骤如下:
1、在目标数据库中创建链接到源数据库的数据链路。执行导入操作的用户必须要有datapump_imp_full_database权限,并且连接到源数据库的数据链路也必须连接到一个有datapump_exp_full_database角色的用户。在源数据库中用户不能有sysdba管理权限。
2、在源数据库上将所有用户表空间置为只读模式
3、将源数据库中所有用户表空间相关的数据文件传输到目标数据库。如果源平台与目标平台的字节编码不同,那么查询v$transportable_platform视图来进行查看。并且将可以使用以下一种方法来转换数据文件:
.使用dbms_file_transfer包中的get_file或put_file过程来传输数据文件。这些过程会自动将数据文件的字节编码转换为目标平台的字节编码。
.使用rman的convert命令来将数据文件的字节编码转换为目标平台的字节编码。
4、在目标数据库上执行导入操作。使用data pump工具来导入所有用户表空间的元数据与管理表空间的元数据与真实数据。
确保以下参数正确设置:
.transportable=always .transport_datafiles=list_of_datafiles .full=y .network_link=database_link .version=12
如果源数据库为11.2.0.3或11g之后的版本,那么必须设置version=12。如果源数据库与目标数据库都是12c,那么version参数不用设置。
如果源数据库包含任何加密表空间或表空间包含加密列,那么你必须指定encryption_pwd_prompt=yes或指定encryption_password参数。
data pump跨网络导入将会复制所有用户表空间所存储对象的元数据与管理表空间中的元与用户对象的真实数据。当导入完成后,用户表空间将会置于读写模式。
5、可选操作将源数据库中的所有用户表空间置为读写模式。
下面的例子是将源数据库jyrac传输到目标数据库jypdb
1.在目标数据库中以sys用户来创建链接到源数据库的数据链路。源数据库中的用户为jy
sql> conn sys/xxzx7817600@jypdb as sysdba connected. sql> create public database link jyrac_link 2 connect to jy identified by "jy" 3 using '(description = 4 (address_list = 5 (address = (protocol = tcp)(host =10.138.130.153)(port = 1521)) 6 ) 7 (connect_data = 8 (server = dedicated) 9 (service_name =jyrac) 10 ) 11 )'; database link created.
2.在源数据库上将所有用户表空间置为只读模式
sql> select tablespace_name,status from dba_tablespaces; tablespace_name status ------------------------------ --------- system online sysaux online undotbs1 online temp online users online undotbs2 online example online test online 8 rows selected. sql> alter tablespace test read only; tablespace altered. sql> alter tablespace users read only; tablespace altered. sql> alter tablespace example read only; tablespace altered. sql> select tablespace_name,status from dba_tablespaces; tablespace_name status ------------------------------ --------- system online sysaux online undotbs1 online temp online users read only undotbs2 online example read only test read only 8 rows selected.
3.在目标数据库中使用dbms_file_transfer包中的get_file过程将源数据库中所有用户表空间相关的数据文件传输到目标数据库上
在源数据库中创建目录tts_datafile(存储数据文件)
sql> create or replace directory tts_datafile as '+datadg/jyrac/datafile/'; directory created. sql> grant execute,read,write on directory tts_datafile to public; grant succeeded.
在目标数据库中创建目录tts_datafile(存储数据文件)
sql> create or replace directory tts_datafile as '+data/jy/4b2c6373ae2547cce053ab828a0a7ca3/datafile/'; directory created. sql> grant execute,read,write on directory tts_datafile to public; grant succeeded.
在目标数据库中执行dbms_file_transfer.get_file过程将源数据库中所有用户表空间所相关的数据文件传输到目标数据库中
sql> exec dbms_file_transfer.get_file(source_directory_object =>'tts_datafile',source_file_name => 'test01.dbf',source_database =>'jyrac_link',destination_directory_object => 'tts_datafile',destination_file_name => 'test01.dbf'); pl/sql procedure successfully completed. sql> exec dbms_file_transfer.get_file(source_directory_object =>'tts_datafile',source_file_name => 'example.260.930413057',source_database =>'jyrac_link',destination_directory_object => 'tts_datafile',destination_file_name => 'example01.dbf'); pl/sql procedure successfully completed. sql> exec dbms_file_transfer.get_file(source_directory_object =>'tts_datafile',source_file_name => 'users.263.930413057',source_database =>'jyrac_link',destination_directory_object => 'tts_datafile',destination_file_name => 'users01.dbf'); pl/sql procedure successfully completed.
asmcmd [+data/jy/4b2c6373ae2547cce053ab828a0a7ca3/datafile] > ls -lt type redund striped time sys name datafile unprot coarse jun 02 16:00:00 n users01.dbf => +data/jy/4b2c6373ae2547cce053ab828a0a7ca3/datafile/file_transfer.298.945620417 datafile unprot coarse jun 02 16:00:00 n test01.dbf => +data/jy/4b2c6373ae2547cce053ab828a0a7ca3/datafile/file_transfer.300.945620337 datafile unprot coarse jun 02 16:00:00 n example01.dbf => +data/jy/4b2c6373ae2547cce053ab828a0a7ca3/datafile/file_transfer.299.945620391 datafile unprot coarse jun 02 16:00:00 y file_transfer.300.945620337 datafile unprot coarse jun 02 16:00:00 y file_transfer.299.945620391 datafile unprot coarse jun 02 16:00:00 y file_transfer.298.945620417 datafile unprot coarse jun 02 00:00:00 n testtb01.dbf => +data/jy/4b2c6373ae2547cce053ab828a0a7ca3/datafile/testtb.295.944828399 datafile unprot coarse jun 02 00:00:00 y undo_2.277.939167063 datafile unprot coarse jun 02 00:00:00 y undotbs2.278.945029905 datafile unprot coarse jun 02 00:00:00 y undotbs1.273.939167015 datafile unprot coarse jun 02 00:00:00 y testtb.295.944828399 datafile unprot coarse jun 02 00:00:00 y system.274.939167015 datafile unprot coarse jun 02 00:00:00 y sysaux.275.939167015
4.在目标数据库上执行导入操作。使用data pump工具来导入所有用户表空间的元数据与管理表空间的元数据与真实数据。
[oracle@jytest1 tts]$ impdp system/xxzx7817600@jypdb_175 full=y network_link=jyrac_link transportable=always transport_datafiles='+data/jy/4b2c6373ae2547cce053ab828a0a7ca3/datafile/test01.dbf','+data/jy/4b2c6373ae2547cce053ab828a0a7ca3/datafile/example01.dbf','+data/jy/4b2c6373ae2547cce053ab828a0a7ca3/datafile/users01.dbf' version=12 directory=tts_dump_log logfile=import.log import: release 12.2.0.1.0 - production on fri jun 2 16:30:40 2017 copyright (c) 1982, 2017, oracle and/or its affiliates. all rights reserved. connected to: oracle database 12c enterprise edition release 12.2.0.1.0 - 64bit production starting "system"."sys_import_full_01": system/********@jypdb_175 full=y network_link=jyrac_link transportable=always transport_datafiles=+data/jy/4b2c6373ae2547cce053ab828a0a7ca3/datafile/test01.dbf,+data/jy/4b2c6373ae2547cce053ab828a0a7ca3/datafile/example01.dbf,+data/jy/4b2c6373ae2547cce053ab828a0a7ca3/datafile/users01.dbf version=12 directory=tts_dump_log logfile=import.log estimate in progress using blocks method... processing object type database_export/plugts_full/full/plugts_tablespace processing object type database_export/plugts_full/plugts_blk processing object type database_export/early_options/views_as_tables/table_data processing object type database_export/normal_options/table_data processing object type database_export/normal_options/views_as_tables/table_data ....... processing object type database_export/schema/dimension processing object type database_export/end_plugts_blk processing object type database_export/final_post_instance_impcallout/marker processing object type database_export/schema/table/post_instance/procact_instance processing object type database_export/schema/table/post_instance/procdepobj processing object type database_export/schema/post_schema/procobj processing object type database_export/schema/post_schema/procact_schema processing object type database_export/audit processing object type database_export/post_system_impcallout/marker ora-39082: object type procedure:"apex_030200"."f" created with compilation warnings ora-39082: object type procedure:"apex_030200"."apex_admin" created with compilation warnings ora-39082: object type procedure:"apex_030200"."htmldb_admin" created with compilation warnings job "system"."sys_import_full_01" completed with 1689 error(s) at fri jun 2 16:43:47 2017 elapsed 0 00:13:03
传输完成后我们抽查用户jy的dba_tables表的数据在传输后是否与源数据库中的数据一致。
源数据库
sql> conn sys/xxzx7817600@jyrac as sysdba connected. sql> select count(*) from jy.dba_tables; count(*) ---------- 2141
目标数据库
sql> conn sys/xxzx7817600@jypdb as sysdba connected. sql> select count(*) from jy.dba_tables; count(*) ---------- 2141
查询传输后用户表空间的状态是否为online,可以看到test,example,users表空间状态为online
sql> select tablespace_name,status from dba_tablespaces; tablespace_name status ------------------------------ --------- system online sysaux online undotbs1 online temp online undo_2 online users online testtb online temp2 online temp3 online example online test online undotbs2 online 12 rows selected.
5.将源数据库中的所有用户表空间设置为读写模式
sql> alter tablespace test read write; tablespace altered. sql> alter tablespace example read write; tablespace altered. sql> alter tablespace users read write; tablespace altered. sql> select tablespace_name,status from dba_tablespaces; tablespace_name status ------------------------------ --------- system online sysaux online undotbs1 online temp online users online undotbs2 online example online test online 8 rows selected.
到此通过网络执行完整数据库传输的操作就完成了。
总结
以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作能带来一定的帮助,如果有疑问大家可以留言交流,谢谢大家对的支持。