《Oracle DBA工做筆記》第二章 經常使用工具和問題分析

《Oracle DBA工做筆記》第二章 經常使用工具和問題分析linux

1  BLOG文檔結構圖

wpsF1DD.tmp 

 

2  本文簡介

建榮的新書《Oracle DBA工做筆記》第二章的目錄以下圖,主要講解了SQL*Plus、exp/imp、expdp/impdp以及常見的問題分析,第二章的目錄以下:sql

wpsF1EE.tmp 

wpsF1EF.tmp 

下邊小麥苗將本身閱讀完第二章後整理的一些內容分享給你們。數據庫

3  第一章內容修改

3.1  刪除數據庫的幾種方式

這個內容是第一章(http://blog.itpub.net/26736162/viewspace-2121930/)小麥苗列出來的,可是中間發現一個問題,就是當要刪除的庫是rac庫的時候,採用dbca -silent靜默方式刪除數據庫是能夠的,可是使用drop database的方式就不行了,報錯:ORA-01586: database must be mounted EXCLUSIVE and not open for this operation,這個時候須要咱們關閉集羣參數cluster_database才能夠刪除,命令爲:alter system set cluster_database=false sid='*' scope=spfile;,因此小麥苗仍是推薦靜默的方式,不管建庫仍是刪庫靜默方式把不少內容自動完成,不用咱們作太多。windows

一、dbca靜默刪庫:dbca -silent -deleteDatabase -sourceDB mydbbash

二、SQL窗口:網絡

alter database close;session

alter system enable restricted session;oracle

drop database;app

三、SQL窗口:編輯器

sql > startup force mount restrict;

sql > drop database;

注意:強烈推薦第一種辦法,以上2和3的辦法如果rac庫須要設置cluster_database爲false後才能夠執行drop database,命令爲:alter system set cluster_database=false sid='*' scope=spfile;

 

4  第二章內容

4.1  orabase命令

簡單點說,這個命令能夠打印$ORACLE_BASE的值。

[ZFZHLHRDB1:oracle]:/oracle>which orabase

/oracle/app/11.2.0/grid/bin/orabase

[ZFZHLHRDB1:oracle]:/oracle>orabase

/oracle/app/oracle

[ZFZHLHRDB1:oracle]:/oracle>

 

 

4.2  SQL*Plus的使用

4.2.1  登陸配置

小麥苗的配置通常是這樣的:

[ZFZHLHRDB1:oracle]:/oracle>more $ORACLE_HOME/sqlplus/admin/glogin.sql

--

-- Copyright (c) 1988, 2011, Oracle and/or its affiliates.

-- All rights reserved.

--

-- NAME

--   glogin.sql

--

-- DESCRIPTION

--   SQL*Plus global login "site profile" file

--

--   Add any SQL*Plus commands here that are to be executed when a

--   user starts SQL*Plus, or uses the SQL*Plus CONNECT command.

--

-- USAGE

--   This script is automatically run

--

set sqlprompt "_user'@'_connect_identifier> "

[ZFZHLHRDB1:oracle]:/oracle>

[ZFZHLHRDB1:oracle]:/oracle>sqlplus / as sysdba

 

SQL*Plus: Release 11.2.0.4.0 Production on Tue Aug 2 14:45:02 2016

 

Copyright (c) 1982, 2013, Oracle.  All rights reserved.

 

Connected to an idle instance.

 

SYS@test1>

4.2.2  獲得show sga的定義語句

建榮這個章節講的很詳細,小麥苗直接列出最終的結果吧。咱們運行命令vi $ORACLE_HOME/bin/sqlplus打開sqlplus文件,匹配SGA能夠發現這麼一行代碼:

SELECT DECODE(NULL, '', 'Total System Global Area', '') NAME_COL_PLUS_SHOW_SGA,

       SUM(VALUE),

       DECODE(NULL, '', 'bytes', '') UNITS_COL_PLUS_SHOW_SGA

  FROM V$SGA

UNION ALL

SELECT NAME NAME_COL_PLUS_SHOW_SGA,

       VALUE,

       DECODE(NULL, '', 'bytes', '') UNITS_COL_PLUS_SHOW_SGA

  FROM V$SGA;

該行代碼的結果和執行show sga能夠獲得同樣的結果。

SYS@omflhr> show sga

 

Total System Global Area 1068937216 bytes

Fixed Size                  2253216 bytes

Variable Size             771755616 bytes

Database Buffers          289406976 bytes

Redo Buffers                5521408 bytes

SYS@omflhr> SELECT DECODE(NULL, '', 'Total System Global Area', '') NAME_COL_PLUS_SHOW_SGA,

  2         SUM(VALUE),

  3         DECODE(NULL, '', 'bytes', '') UNITS_COL_PLUS_SHOW_SGA

  4    FROM V$SGA

  5  UNION ALL

  6  SELECT NAME NAME_COL_PLUS_SHOW_SGA,

  7         VALUE,

  8         DECODE(NULL, '', 'bytes', '') UNITS_COL_PLUS_SHOW_SGA

  9    FROM V$SGA;

 

NAME_COL_PLUS_SHOW_SGA   SUM(VALUE) UNITS_COL_PLUS_

------------------------ ---------- ---------------

Total System Global Area 1068937216 bytes

Fixed Size                  2253216 bytes

Variable Size             771755616 bytes

Database Buffers          289406976 bytes

Redo Buffers                5521408 bytes

 

show sga的官方解釋:

Displays information about the current instance's System Global Area. You need SELECT ON V_$SGA object privileges otherwise you will receive a message

ORA-00942: table or view does not exist

show sga中,各部分的含義以下:

1. Total System Global Area:Fixed Size、Variable Size、 Database buffers和Redo Buffers的大小總和

2. Fixed Size: 這部分是Oracle內部使用的一個區,包括了數據庫與實例的控制信息、狀態信息、字典信息等,啓動時就被固定在SGA中,不會改變。Oracle經過這個區找到SGA其餘區,相似一個SGA各個組件的索引,裏面存儲了SGA 各部分組件的信息,能夠看做引導創建SGA的區域,不一樣平臺和不一樣版本下這部分的大小可能不同。

3. Variable Size: 包括Shared Pool ,Java Pool ,Large Pool,stream pool、遊標區和其餘結構。 

4. Database Buffers: 數據庫中數據塊緩衝的地方,是SGA中最大的地方,決定數據庫性能。爲db_cache_size、db_keep_cache_size、db_recycle_cache_size、 db_nk_cache_size的總大小,固然這是sga_target爲0的狀況,也就是手動SGA管理模式下,若是是自動SGA管理(sga_target>0),則這個值根據sga的分配狀況自動進行調整。

5. Redo Buffers:這部分是實際分配的Redo log buffer的大小,由初始化參數log_buffer根據SGA的最小分配單位granule 向上取整獲得。提供REDO緩衝的地方,在OLAP中不須要太大。在這裏要額外說明一點的是,對於v$parameter、v$sgastat、v$sga查詢值可能不同。v$parameter 裏面的值,是指用戶在初始化參數文件裏面設置的值,v$sgastat是oracle 實際分配的日誌緩衝區大小(由於緩衝區的分配值其實是離散的,也不是以block 爲最小單位進行分配的),v$sga 裏面查詢的值,是在oracle 分配了日誌緩衝區後,爲了保護日誌緩衝區,設置了一些保護頁,一般咱們會發現保護頁大小是8k(不一樣環境可能不同)

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      

4.2.3  SQL*Plus命令設置

關於更多SQL*Plus的命令設置請參考:【OH】SET System Variable Summary SQLPLUS 系統變量設置: http://blog.itpub.net/26736162/viewspace-2121072/

 

4.2.4  SQL*Plus沒法正常啓動

一、linux環境須要禁用SELinux,禁用方式:setenforce 0

二、環境變量設置不當,能夠查看.bash_profile或.profile文件,確保有export;切換用戶;ORACLE_HOME的值最後是沒有反斜槓「/」的;還有從windows到Linux拷貝的時候是否有^M亂碼字符等問題。

 

4.2.5  使用strace來診斷SQL*Plus的登陸問題

若sqlplus有一些特殊的問題,咱們可使用strace來跟蹤命令,跟蹤的命令很簡單:

--------------linux 跟蹤sqlplus進程

strace -o /tmp/output.txt -T -tt -e trace=all  sqlplus / as sysdba

------------- Unix 跟蹤sqlplus進程

truss -dfaie -o /tmp/sched_trace.out.02271 sqlplus '/as sysdba'

 

不過生成的文件須要調用操做系統的不少函數,看起來比較雲裏霧裏的。

 

4.3  exp/imp系列問題

4.3.1  使用query選項

Oracle的exp工具備一個query參數能夠指定一個where條件來有條件地導出記錄, 對於不常常用這個選項的人來講, 常常會遇到這樣的錯誤:

LRM-00112: multiple values not allowed for parameter 'query'

EXP-00019: failed to process parameters, type 'EXP HELP=Y' for help

EXP-00000: Export terminated unsuccessfully

這是由於在where條件中通常都會有空格, 而命令行下就會被釋成幾個命令行參數, 須要用單引號或雙引號將整個where條件括起來, 就能夠了,或者使用正斜槓\來對字符進行轉義,windows下和linux下不太同樣,這個就比較繁瑣了,可是有個通用的辦法就是使用parfile來解析,這個不管是windows仍是linux下均可以使用,舉個例子,咱們須要導出表test_query_lhr中的owner爲SCOTT的記錄,咱們能夠執行:

exp \'/ AS SYSDBA\'  tables=test_query_lhr file=/tmp/test_query_lhr_scott.dmp query=\" where owner=\'SCOTT\' \" log=/tmp/test_query_lhr_scott.log

 

[ZFZHLHRDB1:oracle]:/oracle>ORACLE_SID=raclhr1

[ZFZHLHRDB1:oracle]:/oracle>sqlplus / as sysdba

 

SQL*Plus: Release 11.2.0.4.0 Production on Tue Aug 2 15:18:56 2016

 

Copyright (c) 1982, 2013, Oracle.  All rights reserved.

 

 

Connected to:

Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production

With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,

Data Mining and Real Application Testing options

 

SYS@raclhr1> create table test_query_lhr as select * from dba_tables;

 

Table created.

 

SYS@raclhr1> select count(1) from test_query_lhr where owner='SCOTT';

 

  COUNT(1)

----------

         4

 

SYS@raclhr1> exit

Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production

With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,

Data Mining and Real Application Testing options

[ZFZHLHRDB1:oracle]:/oracle>exp \'/ AS SYSDBA\'  tables=test_query_lhr file=/tmp/test_query_lhr_scott.dmp query=\" where owner=\'SCOTT\' \" log=/tmp/test_query_lhr_scott.log

 

Export: Release 11.2.0.4.0 - Production on Tue Aug 2 15:23:08 2016

 

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

 

 

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production

With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,

Data Mining and Real Application Tes

Export done in ZHS16GBK character set and AL16UTF16 NCHAR character set

 

About to export specified tables via Conventional Path ...

. . exporting table                 TEST_QUERY_LHR          4 rows exported

Export terminated successfully without warnings.

下邊使用parfile的方式來導出:

[ZFZHLHRDB1:oracle]:/oracle>more /tmp/scottfile.par

query="where owner='SCOTT'"

[ZFZHLHRDB1:oracle]:/oracle> exp \'/ AS SYSDBA\'  tables=test_query_lhr file=/tmp/test_query_lhr_scott_01.dmp parfile=/tmp/scottfile.par log=/tmp/test_query_lhr_scott_01.log

 

Export: Release 11.2.0.4.0 - Production on Tue Aug 2 15:30:09 2016

 

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

 

 

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production

With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,

Data Mining and Real Application Tes

Export done in ZHS16GBK character set and AL16UTF16 NCHAR character set

 

About to export specified tables via Conventional Path ...

. . exporting table                 TEST_QUERY_LHR          4 rows exported

Export terminated successfully without warnings.

[ZFZHLHRDB1:oracle]:/oracle>

 

4.3.2  獲得對象的DDL語句

imp工具使用show=y log=get_ddl.sql的方式,能夠看到清晰的ddl腳本,同時也不會真正的執行數據導入:

exp  \'/ AS SYSDBA\'  tables=scott.emp  file=/tmp/exp_ddl_lhr_01.dmp  log=/tmp/exp_table.log  buffer=41943040 rows=n compress=n

imp \'/ AS SYSDBA\' file=/tmp/exp_ddl_lhr_01.dmp show=y log=/tmp/get_ddl.sql buffer=20480000  full=y

 

[ZFZHLHRDB1:oracle]:/oracle>exp  \'/ AS SYSDBA\'  tables=scott.emp  file=/tmp/exp_ddl_lhr_01.dmp  log=/tmp/exp_table.log  buffer=41943040 rows=n compress=n

 

Export: Release 11.2.0.4.0 - Production on Tue Aug 2 15:42:11 2016

 

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

 

 

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production

With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,

Data Mining and Real Application Tes

Export done in ZHS16GBK character set and AL16UTF16 NCHAR character set

Note: table data (rows) will not be exported

 

About to export specified tables via Conventional Path ...

Current user changed to SCOTT

. . exporting table                            EMP

Export terminated successfully without warnings.

[ZFZHLHRDB1:oracle]:/oracle>imp \'/ AS SYSDBA\' file=/tmp/exp_ddl_lhr_01.dmp show=y log=/tmp/get_ddl.sql buffer=20480000  full=y

 

Import: Release 11.2.0.4.0 - Production on Tue Aug 2 15:42:44 2016

 

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

 

 

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production

With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,

Data Mining and Real Application Tes

 

Export file created by EXPORT:V11.02.00 via conventional path

import done in ZHS16GBK character set and AL16UTF16 NCHAR character set

. importing SYS's objects into SYS

. importing SCOTT's objects into SCOTT

"ALTER SESSION SET CURRENT_SCHEMA= "SCOTT""

"CREATE TABLE "EMP" ("EMPNO" NUMBER(4, 0), "ENAME" VARCHAR2(10), "JOB" VARCH"

"AR2(9), "MGR" NUMBER(4, 0), "HIREDATE" DATE, "SAL" NUMBER(7, 2), "COMM" NUM"

"BER(7, 2), "DEPTNO" NUMBER(2, 0))  PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRAN"

"S 255 STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 FREELISTS 1 FREELIST "

"GROUPS 1 BUFFER_POOL DEFAULT) TABLESPACE "USERS" LOGGING NOCOMPRESS"

"CREATE UNIQUE INDEX "PK_EMP" ON "EMP" ("EMPNO" )  PCTFREE 10 INITRANS 2 MAX"

"TRANS 255 STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 FREELISTS 1 FREEL"

"IST GROUPS 1 BUFFER_POOL DEFAULT) TABLESPACE "USERS" LOGGING"

"ALTER SESSION SET CURRENT_SCHEMA= "SCOTT""

"ALTER TABLE "EMP" ADD  CONSTRAINT "PK_EMP" PRIMARY KEY ("EMPNO") USING INDE"

"X PCTFREE 10 INITRANS 2 MAXTRANS 255 STORAGE(INITIAL 65536 NEXT 1048576 MIN"

"EXTENTS 1 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT) TABLESPACE "US"

"ERS" LOGGING ENABLE "

"ALTER TABLE "EMP" ADD CONSTRAINT "FK_DEPTNO" FOREIGN KEY ("DEPTNO") REFEREN"

"CES "DEPT" ("DEPTNO") ENABLE NOVALIDATE"

"ALTER TABLE "EMP" ENABLE CONSTRAINT "FK_DEPTNO""

Import terminated successfully without warnings.

[ZFZHLHRDB1:oracle]:/oracle>

因爲格式比較混亂,直接運行會報錯,建榮的書中給了一段代碼來格式化:

[ZFZHLHRDB1:oracle]:/tmp>more /tmp/get_ddl.sql

 

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production

With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,

Data Mining and Real Application Tes

 

Export file created by EXPORT:V11.02.00 via conventional path

import done in ZHS16GBK character set and AL16UTF16 NCHAR character set

. importing SYS's objects into SYS

. importing SCOTT's objects into SCOTT

"ALTER SESSION SET CURRENT_SCHEMA= "SCOTT""

"CREATE TABLE "EMP" ("EMPNO" NUMBER(4, 0), "ENAME" VARCHAR2(10), "JOB" VARCH"

"AR2(9), "MGR" NUMBER(4, 0), "HIREDATE" DATE, "SAL" NUMBER(7, 2), "COMM" NUM"

"BER(7, 2), "DEPTNO" NUMBER(2, 0))  PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRAN"

"S 255 STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 FREELISTS 1 FREELIST "

"GROUPS 1 BUFFER_POOL DEFAULT) TABLESPACE "USERS" LOGGING NOCOMPRESS"

"CREATE UNIQUE INDEX "PK_EMP" ON "EMP" ("EMPNO" )  PCTFREE 10 INITRANS 2 MAX"

"TRANS 255 STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 FREELISTS 1 FREEL"

"IST GROUPS 1 BUFFER_POOL DEFAULT) TABLESPACE "USERS" LOGGING"

"ALTER SESSION SET CURRENT_SCHEMA= "SCOTT""

"ALTER TABLE "EMP" ADD  CONSTRAINT "PK_EMP" PRIMARY KEY ("EMPNO") USING INDE"

"X PCTFREE 10 INITRANS 2 MAXTRANS 255 STORAGE(INITIAL 65536 NEXT 1048576 MIN"

"EXTENTS 1 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT) TABLESPACE "US"

"ERS" LOGGING ENABLE "

"ALTER TABLE "EMP" ADD CONSTRAINT "FK_DEPTNO" FOREIGN KEY ("DEPTNO") REFEREN"

"CES "DEPT" ("DEPTNO") ENABLE NOVALIDATE"

"ALTER TABLE "EMP" ENABLE CONSTRAINT "FK_DEPTNO""

Import terminated successfully without warnings.

[ZFZHLHRDB1:oracle]:/tmp>more /tmp/gettabddl.sh

awk '

  / \"BEGIN /   { N=1; }

  / \"CREATE /   { N=1; }

  / \"CREATE INDEX/   { N=1; }

  / \"CREATE UNIQUE INDEX/  { N=1; }

  / \"ALTER /   { N=1; }

  / \" ALTER /   { N=1; }

  / \"ANALYZE /   { N=1; }

  / \"GRANT /    { N=1; }

  / \"COMMENT /   { N=1; }

  / \"AUDIT /     { N=1; }

  N==1 { printf "\n/\n"; N++ }

  /\"$/ {

    if (N==0) next;

    s=index( $0, "\"" );

    ln0=length( $0 )

    if ( s!=0 ) {

      lcnt++

      if ( lcnt >= 30 ) {

        ln=substr( $0,s+1,length( substr($0,s+1))-1)

        t=index( ln, ")," )

        if ( t==0 ) { t=index( ln, ", " ) }

        if ( t==0 ) { t=index( ln, ") " ) }

        if ( t > 0 ) {

          printf "%s\n%s",substr( ln,1,t+1), substr(ln, t+2)

          lcnt=0

        }

        else {

          printf "%s", ln

          if ( ln0 < 78 ) { printf "\n" ; lcnt=0 }

        }

      }

      else {

        printf "%s",substr( $0,s+1,length( substr($0,s+1))-1 )

        if ( ln0 < 78 ) { printf "\n" ; lcnt=0 }

      }

    }

  }

  END { printf "\n/\n"}

' $* |sed '1,2d; /^$/ d;

s/STORAGE *(INI/~    STORAGE (INI/g;

s/, "/,~    "/g;

s/ (\"/~   &/g;

s/PCT[FI]/~    &/g;

s/[( ]PARTITION /~&/g;

s/) TABLESPACE/)~    TABLESPACE/g;

s/   , / ,~/g;

s/ DATAFILE  /&~/' | tr "~" "\n"

[ZFZHLHRDB1:oracle]:/tmp>

[ZFZHLHRDB1:oracle]:/tmp>ksh /tmp/gettabddl.sh  /tmp/get_ddl.sql > /tmp/gen_tabddl.sql

[ZFZHLHRDB1:oracle]:/tmp>more /tmp/gen_tabddl.sql

ALTER SESSION SET CURRENT_SCHEMA= "SCOTT"

/

CREATE TABLE "EMP"

    ("EMPNO" NUMBER(4, 0),

    "ENAME" VARCHAR2(10),

    "JOB" VARCHAR2(9),

    "MGR" NUMBER(4, 0),

    "HIREDATE" DATE,

    "SAL" NUMBER(7, 2),

    "COMM" NUMBER(7, 2),

    "DEPTNO" NUMBER(2, 0)) 

    PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255

    STORAGE (INITIAL 65536 NEXT 1048576 MINEXTENTS 1 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)

    TABLESPACE "USERS" LOGGING NOCOMPRESS

/

CREATE UNIQUE INDEX "PK_EMP" ON "EMP"

    ("EMPNO" ) 

    PCTFREE 10 INITRANS 2 MAXTRANS 255

    STORAGE (INITIAL 65536 NEXT 1048576 MINEXTENTS 1 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)

    TABLESPACE "USERS" LOGGING

/

ALTER SESSION SET CURRENT_SCHEMA= "SCOTT"

/

ALTER TABLE "EMP" ADD  CONSTRAINT "PK_EMP" PRIMARY KEY

    ("EMPNO") USING INDEX

    PCTFREE 10 INITRANS 2 MAXTRANS 255

    STORAGE (INITIAL 65536 NEXT 1048576 MINEXTENTS 1 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)

    TABLESPACE "USERS" LOGGING ENABLE

/

ALTER TABLE "EMP" ADD CONSTRAINT "FK_DEPTNO" FOREIGN KEY

    ("DEPTNO") REFERENCES "DEPT"

    ("DEPTNO") ENABLE NOVALIDATE

/

ALTER TABLE "EMP" ENABLE CONSTRAINT "FK_DEPTNO"

/

[ZFZHLHRDB1:oracle]:/tmp>

這樣運行起來就方便多了。

4.3.3  常見問題

1、 EXP-00091: Exporting questionable statistics

[ZFZHLHRDB1:oracle]:/tmp>oerr exp 91

00091, 00000, "Exporting questionable statistics."

// *Cause:  Export was able export statistics, but the statistics may not be

//          usuable. The statistics are questionable because one or more of

//          the following happened during export: a row error occurred, client

//          character set or NCHARSET does not match with the server, a query

//          clause was specified on export, only certain partitions or

//          subpartitions were exported, or a fatal error occurred while

//          processing a table.

// *Action: To export non-questionable statistics, change the client character

//          set or NCHARSET to match the server, export with no query clause,

//          export complete tables. If desired, import parameters can be

//          supplied so that only non-questionable statistics will be imported,

//          and all questionable statistics will be recalculated.

 

該問題因爲客戶端的NLS_LANG設置有問題致使的:

1)查詢數據庫的字符集

SQL> select userenv('language') from dual;

USERENV('LANGUAGE')
----------------------------------------------------
AMERICAN_AMERICA.ZHS16GBK

2)設置Linux操做系統的NLS_LANG環境變量
[oracle@RH207 exp]$export NLS_LANG=AMERICAN_AMERICA.ZHS16GBK

 

2、 IMP-00013: only a DBA can import a file exported by another DBA

導入用戶的權限不夠,咱們能夠賦權:grant imp_full_database to user_xxx;便可。

若仍是報錯,能夠嘗試:alter user user_xxx default role all;確保查詢dba_role_privs中的DEFAULT_ROLE列的值爲YES。

 

4.3.4  使用strace來跟蹤exp

strace exp n1/n1 tables=scott.emp file=a.dmp

strace -c -p 25805

 

一4.3.5  從生成的dmp文件能夠獲取到的信息

1、 獲取基本信息:導出的版本、時間、導出的用戶

[ZFZHLHRDB1:oracle]:/tmp>strings exp_ddl_lhr_02.dmp | head -10

TEXPORT:V11.02.00  ====》版本號 

DSYS    ====》使用SYS用戶導出

RTABLES ====》基於表模式導出,RUSERS表示基於用戶模式,RENTIRE表示基於全庫模式

4096

Tue Aug 2 16:8:8 2016/tmp/exp_ddl_lhr_02.dmp====》生成的時間和文件地址

#C#G

#C#G

+00:00

BYTE

UNUSED

 

2、 獲取dmp文件中的表信息

[ZFZHLHRDB1:oracle]:/tmp>strings  exp_ddl_lhr_02.dmp | grep "CREATE TABLE"|awk '{print $3}'|sed 's/"//g'

EMP ====》說明exp_ddl_lhr_02.dmp中只有一個emp表

 

3、 解析dmp文件生成parfile文件

[ZFZHLHRDB1:oracle]:/tmp>strings  exp_ddl_lhr_03.dmp | grep "CREATE TABLE"|awk '{print $3}'|sed 's/"//g'|awk '{ if (FNR==1) print "tables="$1 ; else print ","$1 }'

tables=DEF$_AQCALL

,DEF$_AQERROR

,DEF$_CALLDEST

,DEF$_DEFAULTDEST

,DEF$_DESTINATION

,DEF$_ERROR

,DEF$_LOB

,DEF$_ORIGIN

,DEF$_PROPAGATOR

,DEF$_PUSHED_TRANSACTIONS

,MVIEW$_ADV_INDEX

[ZFZHLHRDB1:oracle]:/tmp>

其實這個可使用UE或editplus文本編輯器的列模式實現也很快。

4.4  expdp/impdp系列問題

 

4.4.1  使用query選項

好比咱們想導出SCOTT.EMP表中DEPTNO=20和SCOTT.DEPT表中DNAME='SALES'的記錄,咱們能夠在parfile中寫:query=SCOTT.EMP:"WHERE DEPTNO=20",SCOTT.DEPT:"WHERE DNAME='SALES'",示例以下:

SYS@raclhr1> select * from scott.emp where DEPTNO=20;

 

     EMPNO ENAME      JOB              MGR HIREDATE                   SAL       COMM     DEPTNO

---------- ---------- --------- ---------- ------------------- ---------- ---------- ----------

      7369 SMITH      CLERK           7902 1980-12-17 00:00:00        800                    20

      7566 JONES      MANAGER         7839 1981-04-02 00:00:00       2975                    20

      7788 SCOTT      ANALYST         7566 1987-04-19 00:00:00       3000                    20

      7876 ADAMS      CLERK           7788 1987-05-23 00:00:00       1100                    20

      7902 FORD       ANALYST         7566 1981-12-03 00:00:00       3000                    20

 

SYS@raclhr1> SELECT * FROM SCOTT.DEPT where DNAME='SALES';

 

    DEPTNO DNAME          LOC

---------- -------------- -------------

        30 SALES          CHICAGO

 

[ZFZHLHRDB1:oracle]:/oracle>more /tmp/scottfile.par

query=SCOTT.EMP:"WHERE DEPTNO=20",SCOTT.DEPT:"WHERE DNAME='SALES'"

 

[ZFZHLHRDB1:oracle]:/tmp>expdp \'/ AS SYSDBA\' directory=DATA_PUMP_DIR schemas=SCOTT dumpfile=test_query_lhr_scott_02.dmp parfile=/tmp/scottfile.par log=test_query_lhr_scott_02.log

 

Export: Release 11.2.0.4.0 - Production on Wed Aug 3 09:32:21 2016

 

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

 

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production

With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,

Data Mining and Real Application Testing options

Legacy Mode Active due to the following parameters:

Legacy Mode Parameter: "log=test_query_lhr_scott_02.log" Location: Command Line, Replaced with: "logfile=test_query_lhr_scott_02.log"

Legacy Mode has set reuse_dumpfiles=true parameter.

Starting "SYS"."SYS_EXPORT_SCHEMA_01":  "/******** AS SYSDBA" directory=DATA_PUMP_DIR schemas=SCOTT dumpfile=test_query_lhr_scott_02.dmp parfile=/tmp/scottfile.par logfile=test_query_lhr_scott_02.log reuse_dumpfiles=true

Estimate in progress using BLOCKS method...

Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA

Total estimation using BLOCKS method: 192 KB

Processing object type SCHEMA_EXPORT/USER

Processing object type SCHEMA_EXPORT/SYSTEM_GRANT

Processing object type SCHEMA_EXPORT/ROLE_GRANT

Processing object type SCHEMA_EXPORT/DEFAULT_ROLE

Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA

Processing object type SCHEMA_EXPORT/TABLE/TABLE

Processing object type SCHEMA_EXPORT/TABLE/INDEX/INDEX

Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/CONSTRAINT

Processing object type SCHEMA_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS

Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/REF_CONSTRAINT

Processing object type SCHEMA_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS

. . exported "SCOTT"."DEPT"                              5.859 KB       1 rows

. . exported "SCOTT"."EMP"                               8.195 KB       5 rows

. . exported "SCOTT"."SALGRADE"                          5.859 KB       5 rows

. . exported "SCOTT"."BONUS"                                 0 KB       0 rows

Master table "SYS"."SYS_EXPORT_SCHEMA_01" successfully loaded/unloaded

******************************************************************************

Dump file set for SYS.SYS_EXPORT_SCHEMA_01 is:

  /oracle/app/oracle/admin/raclhr1/dpdump/test_query_lhr_scott_02.dmp

Job "SYS"."SYS_EXPORT_SCHEMA_01" successfully completed at Wed Aug 3 09:32:34 2016 elapsed 0 00:00:12

 

4.4.2  使用include

只導出procedure,function和含有TEST的序列。

expdp \'/ AS SYSDBA\' directory=DATA_PUMP_DIR schemas=SCOTT dumpfile=test_include_lhr_scott_03.dmp logfile=test_include_lhr_scott_03.log job_name=my_job_lhr include=procedure,function,sequence:"like '%TEST%'"

或使用parfile文件:

include=procedure,function,sequence:"like '%TEST%'"

或:

include=procedure

include=function

include=sequence:"like '%TEST%'"

 

[ZFZHLHRDB1:oracle]:/tmp>expdp \'/ AS SYSDBA\' directory=DATA_PUMP_DIR schemas=SCOTT dumpfile=test_include_lhr_scott_05.dmp logfile=test_include_lhr_scott_05.log job_name=my_job_lhr parfile=/tmp/parfile.par

Export: Release 11.2.0.4.0 - Production on Wed Aug 3 10:06:04 2016

 

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

 

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production

With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,

Data Mining and Real Application Testing options

Starting "SYS"."MY_JOB_LHR":  "/******** AS SYSDBA" directory=DATA_PUMP_DIR schemas=SCOTT dumpfile=test_include_lhr_scott_05.dmp logfile=test_include_lhr_scott_05.log job_name=my_job_lhr parfile=/tmp/parfile.par

Estimate in progress using BLOCKS method...

Total estimation using BLOCKS method: 0 KB

Processing object type SCHEMA_EXPORT/SEQUENCE/SEQUENCE

Processing object type SCHEMA_EXPORT/FUNCTION/FUNCTION

Processing object type SCHEMA_EXPORT/PROCEDURE/PROCEDURE

Processing object type SCHEMA_EXPORT/FUNCTION/ALTER_FUNCTION

Processing object type SCHEMA_EXPORT/PROCEDURE/ALTER_PROCEDURE

Master table "SYS"."MY_JOB_LHR" successfully loaded/unloaded

******************************************************************************

Dump file set for SYS.MY_JOB_LHR is:

  /oracle/app/oracle/admin/raclhr1/dpdump/test_include_lhr_scott_05.dmp

Job "SYS"."MY_JOB_LHR" successfully completed at Wed Aug 3 10:06:10 2016 elapsed 0 00:00:05

4.4.3  獲得對象的DDL語句

IMP工具使用show=y log=get_ddl.sql的方式獲取ddl語句,一樣,impdp也能夠獲取到dmp文件的ddl語句。IMPDP工具給咱們提供了SQLFILE的命令行選項,只獲取DDL語句,並未真正的執行數據導入:

impdp hr/hr directory=mig_dir dumpfile=expdp_hr.dmp logfile=impdp_hr.log schemas=hr sqlfile=get_ddl.sql

 

--expdp \'/ AS SYSDBA\' directory=DATA_PUMP_DIR schemas=SCOTT  dumpfile=exptest_sql.dmp logfile=exp_exptest.dmp

impdp  \'/ AS SYSDBA\'  directory=DATA_PUMP_DIR dumpfile=exptest_sql.dmp  logfile=imp_exptest.log sqlfile=exptest.sql

 

[ZFXDESKDB1:oracle]:/oracle>expdp \'/ AS SYSDBA\' directory=DATA_PUMP_DIR schemas=SCOTT  dumpfile=exptest_sql.dmp logfile=exp_exptest.dmp

 

Export: Release 11.2.0.4.0 - Production on Wed Aug 3 15:14:55 2016

 

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

 

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production

With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,

Data Mining and Real Application Testing options

Starting "SYS"."SYS_EXPORT_SCHEMA_01":  "/******** AS SYSDBA" directory=DATA_PUMP_DIR schemas=SCOTT dumpfile=exptest_sql.dmp logfile=exp_exptest.dmp

Estimate in progress using BLOCKS method...

Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA

Total estimation using BLOCKS method: 256 KB

Processing object type SCHEMA_EXPORT/USER

Processing object type SCHEMA_EXPORT/SYSTEM_GRANT

Processing object type SCHEMA_EXPORT/ROLE_GRANT

Processing object type SCHEMA_EXPORT/DEFAULT_ROLE

Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA

Processing object type SCHEMA_EXPORT/TABLE/TABLE

Processing object type SCHEMA_EXPORT/TABLE/INDEX/INDEX

Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/CONSTRAINT

Processing object type SCHEMA_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS

Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/REF_CONSTRAINT

Processing object type SCHEMA_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS

. . exported "SCOTT"."DEPT"                              5.929 KB       4 rows

. . exported "SCOTT"."EMP"                               8.562 KB      14 rows

. . exported "SCOTT"."SALGRADE"                          5.859 KB       5 rows

. . exported "SCOTT"."TEST"                              5.007 KB       1 rows

. . exported "SCOTT"."BONUS"                                 0 KB       0 rows

Master table "SYS"."SYS_EXPORT_SCHEMA_01" successfully loaded/unloaded

******************************************************************************

Dump file set for SYS.SYS_EXPORT_SCHEMA_01 is:

  /oracle/app/oracle/admin/lhrdb/dpdump/exptest_sql.dmp

Job "SYS"."SYS_EXPORT_SCHEMA_01" successfully completed at Wed Aug 3 15:15:16 2016 elapsed 0 00:00:20

 

[ZFXDESKDB1:oracle]:/oracle>impdp  \'/ AS SYSDBA\'  directory=DATA_PUMP_DIR dumpfile=exptest_sql.dmp  logfile=imp_exptest.log sqlfile=exptest.sql

 

Import: Release 11.2.0.4.0 - Production on Wed Aug 3 15:16:06 2016

 

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

 

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production

With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,

Data Mining and Real Application Testing options

Master table "SYS"."SYS_SQL_FILE_FULL_01" successfully loaded/unloaded

Starting "SYS"."SYS_SQL_FILE_FULL_01":  "/******** AS SYSDBA" directory=DATA_PUMP_DIR dumpfile=exptest_sql.dmp logfile=imp_exptest.log sqlfile=exptest.sql

Processing object type SCHEMA_EXPORT/USER

Processing object type SCHEMA_EXPORT/SYSTEM_GRANT

Processing object type SCHEMA_EXPORT/ROLE_GRANT

Processing object type SCHEMA_EXPORT/DEFAULT_ROLE

Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA

Processing object type SCHEMA_EXPORT/TABLE/TABLE

Processing object type SCHEMA_EXPORT/TABLE/INDEX/INDEX

Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/CONSTRAINT

Processing object type SCHEMA_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS

Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/REF_CONSTRAINT

Processing object type SCHEMA_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS

Job "SYS"."SYS_SQL_FILE_FULL_01" successfully completed at Wed Aug 3 15:16:09 2016 elapsed 0 00:00:02

 

[ZFXDESKDB1:oracle]:/oracle>cd /oracle/app/oracle/admin/lhrdb/dpdump/

[ZFXDESKDB1:oracle]:/oracle/app/oracle/admin/lhrdb/dpdump>more exptest.sql

-- CONNECT SYS

ALTER SESSION SET EVENTS '10150 TRACE NAME CONTEXT FOREVER, LEVEL 1';

ALTER SESSION SET EVENTS '10904 TRACE NAME CONTEXT FOREVER, LEVEL 1';

ALTER SESSION SET EVENTS '25475 TRACE NAME CONTEXT FOREVER, LEVEL 1';

ALTER SESSION SET EVENTS '10407 TRACE NAME CONTEXT FOREVER, LEVEL 1';

ALTER SESSION SET EVENTS '10851 TRACE NAME CONTEXT FOREVER, LEVEL 1';

ALTER SESSION SET EVENTS '22830 TRACE NAME CONTEXT FOREVER, LEVEL 192 ';

-- new object type path: SCHEMA_EXPORT/USER

-- CONNECT SYSTEM

CREATE USER "SCOTT" IDENTIFIED BY VALUES 'S:268AB71B15071D81F19C6FC5041FA8F8E49397470FFE05458B8C90D9E7F8;F894844C34402B67'

      DEFAULT TABLESPACE "USERS"

      TEMPORARY TABLESPACE "TEMP"

      PASSWORD EXPIRE

      ACCOUNT LOCK;

-- new object type path: SCHEMA_EXPORT/SYSTEM_GRANT

GRANT UNLIMITED TABLESPACE TO "SCOTT";

-- new object type path: SCHEMA_EXPORT/ROLE_GRANT

GRANT "CONNECT" TO "SCOTT";

GRANT "RESOURCE" TO "SCOTT";

-- new object type path: SCHEMA_EXPORT/DEFAULT_ROLE

ALTER USER "SCOTT" DEFAULT ROLE ALL;

-- new object type path: SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA

-- CONNECT SCOTT

 

BEGIN

sys.dbms_logrep_imp.instantiate_schema(schema_name=>SYS_CONTEXT('USERENV','CURRENT_SCHEMA'), export_db_name=>'LHRDB', inst_scn=>'4225469');

COMMIT;

END;

/

-- new object type path: SCHEMA_EXPORT/TABLE/TABLE

-- CONNECT SYS

CREATE TABLE "SCOTT"."DEPT"

   (    "DEPTNO" NUMBER(2,0),

        "DNAME" VARCHAR2(14 BYTE),

        "LOC" VARCHAR2(13 BYTE)

   ) SEGMENT CREATION IMMEDIATE

  PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255

NOCOMPRESS LOGGING

  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645

  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1

  BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)

  TABLESPACE "USERS" ;

CREATE TABLE "SCOTT"."EMP"

   (    "EMPNO" NUMBER(4,0),

        "ENAME" VARCHAR2(10 BYTE),

        "JOB" VARCHAR2(9 BYTE),

        "MGR" NUMBER(4,0),

        "HIREDATE" DATE,

        "SAL" NUMBER(7,2),

        "COMM" NUMBER(7,2),

        "DEPTNO" NUMBER(2,0)

   ) SEGMENT CREATION IMMEDIATE

  PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255

NOCOMPRESS LOGGING

  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645

  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1

  BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)

  TABLESPACE "USERS" ;

CREATE TABLE "SCOTT"."BONUS"

   (    "ENAME" VARCHAR2(10 BYTE),

        "JOB" VARCHAR2(9 BYTE),

        "SAL" NUMBER,

        "COMM" NUMBER

   ) SEGMENT CREATION DEFERRED

  PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255

NOCOMPRESS LOGGING

  TABLESPACE "USERS" ;

CREATE TABLE "SCOTT"."SALGRADE"

   (    "GRADE" NUMBER,

        "LOSAL" NUMBER,

        "HISAL" NUMBER

   ) SEGMENT CREATION IMMEDIATE

  PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255

NOCOMPRESS LOGGING

  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645

  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1

  BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)

  TABLESPACE "USERS" ;

CREATE TABLE "SCOTT"."TEST"

   (    "DUMMY" VARCHAR2(1 BYTE)

   ) SEGMENT CREATION IMMEDIATE

  PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255

NOCOMPRESS LOGGING

  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645

  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1

  BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)

  TABLESPACE "USERS" ;

-- new object type path: SCHEMA_EXPORT/TABLE/INDEX/INDEX

-- CONNECT SCOTT

CREATE UNIQUE INDEX "SCOTT"."PK_DEPT" ON "SCOTT"."DEPT" ("DEPTNO")

  PCTFREE 10 INITRANS 2 MAXTRANS 255

  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645

  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1

  BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)

  TABLESPACE "USERS" PARALLEL 1 ;

 

  ALTER INDEX "SCOTT"."PK_DEPT" NOPARALLEL;

CREATE UNIQUE INDEX "SCOTT"."PK_EMP" ON "SCOTT"."EMP" ("EMPNO")

  PCTFREE 10 INITRANS 2 MAXTRANS 255

  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645

  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1

  BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)

  TABLESPACE "USERS" PARALLEL 1 ;

 

  ALTER INDEX "SCOTT"."PK_EMP" NOPARALLEL;

-- new object type path: SCHEMA_EXPORT/TABLE/CONSTRAINT/CONSTRAINT

-- CONNECT SYS

ALTER TABLE "SCOTT"."DEPT" ADD CONSTRAINT "PK_DEPT" PRIMARY KEY ("DEPTNO")

  USING INDEX "SCOTT"."PK_DEPT"  ENABLE;

ALTER TABLE "SCOTT"."EMP" ADD CONSTRAINT "PK_EMP" PRIMARY KEY ("EMPNO")

  USING INDEX "SCOTT"."PK_EMP"  ENABLE;

-- new object type path: SCHEMA_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS

DECLARE I_N VARCHAR2(60);

  I_O VARCHAR2(60);

  NV VARCHAR2(1);

  c DBMS_METADATA.T_VAR_COLL;

  df varchar2(21) := 'YYYY-MM-DD:HH24:MI:SS';

stmt varchar2(300) := ' INSERT INTO "SYS"."IMPDP_STATS" (type,version,flags,c1,c2,c3,c5,n1,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11,n12,d1,cl1) VALUES (''I'',6,:1,:2,:3,:4,:5,

:6,:7,:8,:9,:10,:11,:12,:13,NULL,:14,:15,NULL,:16,:17)';

BEGIN

  DELETE FROM "SYS"."IMPDP_STATS";

  i_n := 'PK_DEPT';

  i_o := 'SCOTT';

  EXECUTE IMMEDIATE stmt USING 2,I_N,NV,NV,I_O,4,1,4,1,1,1,0,4,NV,NV,TO_DATE('2016-07-07 22:00:11',df),NV;

 

  DBMS_STATS.IMPORT_INDEX_STATS('"' || i_o || '"','"' || i_n || '"',NULL,'"IMPDP_STATS"',NULL,'"SYS"');

  DELETE FROM "SYS"."IMPDP_STATS";

END;

/

《《《《。。。。。。。。篇幅緣由,有省略,剩下的都是統計信息,生成sqlfile的時候也能夠不用生成。。。。。。。。》》》》

 

 

4.4.4  Datapump的工做原理

通常數據在導入的過程當中會生成3類的臨時表,分別爲IMPORT表、ERR表和ET表,其中只有IMPORT表能夠查詢,ERR表和ET表不能訪問,報ORA-29913錯誤,但能夠執行drop操做。

TABLE_EXISTS_ACTION=REPLACE 這個選項的底層操做是drop purge+create的操做。

 

4.4.5  使用trace來跟蹤

expdp \'/ AS SYSDBA\' directory=DATA_PUMP_DIR schemas=SCOTT dumpfile=test_query_lhr_scott_02.dmp parfile=/tmp/scottfile.par log=test_query_lhr_scott_02.log trace=4a0300

 

更多內容請參考:

一、【MOS】Export/Import DataPump Parameter TRACE (文檔 ID 286496.1):http://blog.itpub.net/26736162/viewspace-2085076/

二、使用隱含Trace參數診斷Oracle Data Pump故障:http://blog.itpub.net/26736162/viewspace-2072331/

 

4.5  如何完全中止expdp

許多人在使用expdp命令時,不當心按了CTLR+C,而後又輸入exit命令(或者網絡中斷等異常現象),致使expdp進程不存在,但oracle數據庫的session仍存在,dmp文件也一直在增加。

處理辦法

一、檢查expdp進程是否還在

ps –ef | grep expdp

(如存在,可用kill -9 process命令殺掉)

二、檢查session是否仍存在

三、把相關session殺掉,如無DBA權限

drop table JOBID purge;

(JOBID即爲DIRECTORY,此例爲LZT_CASS1DATAJOB)

 

四、檢查相關表及dump的session

select * from GV$DATAPUMP_SESSION;

select * From USER_DATAPUMP_JOBS;

DBA_DATAPUMP_JOBS;

dba_datapump_sessions;

結果應該無記錄

 

五、刪除導出的dmp文件。如不刪除,重提expdp命令時,會報dmp文件已存在

 

總結:查看進程、查看session、查看錶GV$DATAPUMP_SESSION和USER_DATAPUMP_JOBS

4.5.1  個人視圖

set line 9999

col owner_name for a10

col job_name for a25

col operation for a10

col job_mode for a10

col state for a15

col job_mode for a10 

col state for a15

col osuser for a10

col "degree|attached|datapump" for a25

col session_info for a20 

SELECT ds.inst_id,

       dj.owner_name,

       dj.job_name,

       dj.operation,

       dj.job_mode,

       dj.state,

       dj.degree || ',' || dj.attached_sessions || ',' ||

       dj.datapump_sessions "degree|attached|datapump",

       ds.session_type,

       s.osuser ,

       (SELECT s.SID || ',' || s.SERIAL# || ',' || p.SPID

          FROM gv$process p

         where s.paddr = p.addr

           AND s.inst_id = p.inst_id) session_info

  FROM DBA_DATAPUMP_JOBS dj --gv$datapump_job 

  full outer join dba_datapump_sessions ds --gv$datapump_session

    on (dj.job_name = ds.job_name and dj.owner_name = ds.owner_name)

  left outer join gv$session s

    on (s.saddr = ds.saddr and ds.inst_id = s.inst_id)

 ORDER BY dj.owner_name, dj.job_name;

相關文章
相關標籤/搜索