通过dblink使用expdp能不能导出9i库的数据?

expdp/impdp是10g推出的导入导出工具,9i下是没有该工具的,有人提议用10g的expdp,通过dblink导出9i的数据,乍一听感觉是那么回事,但究竟行不行,咱们实验说明。

1. 登录到一台10g/11g的服务器,首先创建连接到9i库TEST的一个链接tlink:

SQL> create database link tlink connect to test identified by test using 'TEST';

Database link created.

2. 编辑expdp导出的配置文件:

userid=user/pwd			- expdp使用的本机数据库用户
directory=expdp_dir		- directory路径
dumpfile=testtkt.dump
logfile=testtkt.log
tables=test.t_r			- 要导出的9i库表t_r
network_link=tlink		- 链接到的9i库dblink

3. 执行expdp:

[oracle11g@Node1 expdp_dir]$ expdp parfile=tlink.par

Export: Release 11.2.0.1.0 - Production on Mon May 18 13:35:57 2015

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 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
ORA-39006: internal error
ORA-39065: unexpected master process exception in DISPATCH
ORA-00904: "SYS"."KUPM$MCP"."GET_ENDIANNESS": invalid identifier

ORA-39097: Data Pump job encountered unexpected error -904

提示一系列ORA错误。

expdp不像exp,他是将导出转变成一个Oracle内部的job任务,有一点可以证明,就是使用exp导出时用ctrl+c中断,此时导出过程整体中断,如果使用expdp导出时用ctrl+c中断,此时导出过程并未中断,因为其已经转变为Oracle的一个任务,和客户端无关,退出交互模式后,会进入export的命令行模式,有status、start、stop等命令可以用。

从上面的报错可以看到ORA-00904: "SYS"."KUPM$MCP"."GET_ENDIANNESS": invalid identifier,关于904的错误描述:

[oracle11g@Node1 expdp_dir]$ oerr ora 904
00904, 00000, "%s: invalid identifier"
// *Cause:
// *Action:

说明是找不到对应的标识符,再看看SYS.KUPM$MCP大概是什么:

SQL> desc sys.KUPM$MCP;
PROCEDURE CLOSE_JOB
FUNCTION DISPATCH RETURNS KUPC$_MESSAGE
 Argument Name                  Type                    In/Out Default?
 ------------------------------ ----------------------- ------ --------
 REQUEST                        KUPC$_MESSAGE           IN
PROCEDURE FILE_LOG_MESSAGE
 Argument Name                  Type                    In/Out Default?
 ------------------------------ ----------------------- ------ --------
 ERRCODE                        NUMBER                  IN
 PARAMETER1                     VARCHAR2                IN     DEFAULT
 PARAMETER2                     VARCHAR2                IN     DEFAULT
 PARAMETER3                     VARCHAR2                IN     DEFAULT
 PARAMETER4                     VARCHAR2                IN     DEFAULT
 PARAMETER5                     VARCHAR2                IN     DEFAULT
 PARAMETER6                     VARCHAR2                IN     DEFAULT
 PARAMETER7                     VARCHAR2                IN     DEFAULT
 PARAMETER8                     VARCHAR2                IN     DEFAULT
PROCEDURE FILE_TO_WORKER
 Argument Name                  Type                    In/Out Default?
 ------------------------------ ----------------------- ------ --------
 MESSAGE                        KUPC$_MESSAGE           IN
FUNCTION GET_ENDIANNESS RETURNS NUMBER
PROCEDURE MAIN
 Argument Name                  Type                    In/Out Default?
 ------------------------------ ----------------------- ------ --------
 JOB_NAME                       VARCHAR2                IN
 JOB_OWNER                      VARCHAR2                IN
 RESTART_JOB                    BINARY_INTEGER          IN
 DEBUG_INFO                     BINARY_INTEGER          IN
PROCEDURE MAINLOOP
PROCEDURE SET_DEBUG
 Argument Name                  Type                    In/Out Default?
 ------------------------------ ----------------------- ------ --------
 DEBUG_FLAGS                    BINARY_INTEGER          IN
FUNCTION VALIDATE_EXPRESSION RETURNS NUMBER
 Argument Name                  Type                    In/Out Default?
 ------------------------------ ----------------------- ------ --------
 EXPR_VALUE                     VARCHAR2                IN

其实他包含了若干函数,GET_ENDIANNESS是其中一个(从名称上看,貌似是获得“大小端信息”),显然是没找到对应函数,忘了从什么地方看到过关于这个函数的描述(如果哪位高人记得,可以回复下),他在9i中是不存在的,可以证明expdp导出过程是需要调用这个函数的,但这个函数在9i中是没有定义的,因此9i下是不能使用expdp。

4. 我们接着看dblink导出10g以上版本的库

SQL> create database link ldplink connect to puser identified by puser_pwd using 'link_10g';

Database link created.

5. 编辑expdp配置文件:

[oracle11g@Node1 expdp_dir]$ vi link_10g.par
userid=user/pwd

directory=expdp_dirdumpfile=link_10g.dumplogfile=link_10g.logtables=puser.l_rnetwork_link=link_10g

6. 执行expdp:

[oracle11g@Node1 expdp_dir]$ expdp parfile=link_10g.par 

Export: Release 11.2.0.1.0 - Production on Mon May 18 13:40:45 2015

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 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
ORA-31631: privileges are required
ORA-39149: cannot link privileged user to non-privileged user

这回又提示ORA-31631和ORA-39149两个错误。

[oracle11g@Node1 expdp_dir]$ oerr ora 31631
31631, 00000, "privileges are required" 
// *Cause:  The necessary privileges are not available for operations such
//          as: restarting a job on behalf of another owner, using a device
//          as a member of the dump file set, or ommiting a directory
//          object associated with any of the various output files.  
//          Refer to any following error messages for additional information.
// *Action: Select a different job to restart, try a different operation, or
//          contact a database administrator to acquire the needed privileges.

提示是缺少权限。

[oracle11g@Node1 expdp_dir]$ oerr ora 39149
39149, 00000, "cannot link privileged user to non-privileged user"
// *Cause:  A Data Pump job initiated be a user with 
//          EXPORT_FULL_DATABASE/IMPORT_FULL_DATABASE roles specified a
//          network link that did not correspond to a user with
//          equivalent roles on the remote database.
// *Action: Specify a network link that maps users to identically privileged 
//          users in the remote database.

这个错误提示的更加明确,提示使用dblink并且具有EXPORT_FULL_DATABASE/IMPORT_FULL_DATABASE角色的执行用户,对应远端的用户并没有相应的角色权限。有点绕,简单讲,就是我这里使用expdp的数据库用户user,是有DBA权限的,因此具有EXPORT_FULL_DATABASE/IMPORT_FULL_DATABASE角色权限,但远端数据库用户puser只是普通用户,没有此权限,因此有这个提示错误。

解决方案1:

远端库中设置:

SQL> grant exp_full_database to puser;

Grant succeeded.

再次执行expdp:

[oracle11g@Node1 expdp_dir]$ expdp parfile=link_10g.par 

Export: Release 11.2.0.1.0 - Production on Mon May 18 13:51:37 2015

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 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Starting "USER"."SYS_EXPORT_TABLE_01":  user/******** parfile=link_10g.par 
Estimate in progress using BLOCKS method...
Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 64 KB
Processing object type TABLE_EXPORT/TABLE/TABLE
Processing object type TABLE_EXPORT/TABLE/INDEX/INDEX
Processing object type TABLE_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
Processing object type TABLE_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
Processing object type TABLE_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
. . exported "PUSER"."L_R"                          20.49 KB      28 rows
Master table "BISAL"."SYS_EXPORT_TABLE_01" successfully loaded/unloaded
******************************************************************************
Dump file set for USER.SYS_EXPORT_TABLE_01 is:
  /home/oracle11g/expdp_dir/link_10g.dump
Job "USER"."SYS_EXPORT_TABLE_01" successfully completed at 13:51:56

解决方案2:

杨长老的这篇博文(http://blog.itpub.net/4227/viewspace-448665/)说明了此问题。对于这个问题,还有种方法,就是新建一个本地用户,不授予EXPORT_FULL_DATABASE/IMPORT_FULL_DATABASE角色。

总结

1. 9i是不支持expdp的,即使从10g的expdp使用dblink连到9i,也是不行的,从上述实验可以看到,有些expdp使用的函数是在9i中没有定义的。

2. 使用dblink方式的expdp导出,要求要么本地用户没有EXPORT_FULL_DATABASE/IMPORT_FULL_DATABASE角色,要么本地用户有这两个角色,但此时要求远端用户有EXPORT_FULL_DATABASE角色,否则就会提示ORA-31631和ORA-39149这两个错误。

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

发表于

我来说两句

0 条评论
登录 后参与评论

扫码关注云+社区

领取腾讯云代金券