程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> SyBase數據庫 >> SyBase教程 >> 通過dblink使用expdp能不能導出9i庫的數據?

通過dblink使用expdp能不能導出9i庫的數據?

編輯:SyBase教程

通過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:

對於這個問題,還有種方法,就是新建一個本地用戶,不授予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這兩個錯誤。

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved