【ASH】如何导出视图DBA_HIST_ACTIVE_SESS_HISTORY的查询结果数据

本文涉及的产品
云原生数据仓库AnalyticDB MySQL版,基础版 8ACU 100GB 1个月
简介:

ASH如何导出视图DBA_HIST_ACTIVE_SESS_HISTORY的查询结果数据

 

1.1  BLOG文档结构图

wpsF4F7.tmp 

1.2  前言部分

1.2.1  导读和注意事项

各位技术爱好者,看完本文后,你可以掌握如下的技能,也可以学到一些其它你所不知道的知识,~O(∩_∩)O~

① 如何导出ASH数据--利用exp导出基表的数据(重点)

② 12c的expdp参数VIEWS_AS_TABLES选项

③ expdp工具不能导出哪些对象?

Tips

① 本文在itpubhttp://blog.itpub.net/26736162)、博客园(http://www.cnblogs.com/lhrbest)和微信公众号(xiaomaimiaolhr有同步更新

② 文章中用到的所有代码相关软件相关资料及本文的pdf版本都请前往小麦苗的云盘下载小麦苗的云盘地址见:http://blog.itpub.net/26736162/viewspace-1624453/

③ 若网页文章代码格式有错乱,下载pdf格式的文档来阅读

④ 本篇BLOG,代码输出部分一般放在一行一列的表格中。

本文有错误或不完善的地方请大家多多指正,您的批评指正是我写作的最大动力。

 

1.2.2  相关文章链接

12c的dmp文件导入11g中参考:【故障处理】IMP-00010错误 12Cdmp文件导入11G,地址为:http://blog.itpub.net/26736162/viewspace-2128197/

 

1.2.3  本文简介

众所周知,视图只是一个查询数据的窗口,其不存储数据,所以在使用exp等工具导出的时候只能导出其定义,而不能导出视图的查询结果数据。在Oracle 12c中,可以采用expdp中的一个新增参数VIEWS_AS_TABLES来将视图作为表来导出,非常实用,不过对于一些特殊的表仍然不能采用expdp导出,例如SYSSYSTEM下的一些表,AUD$表不能使用expdp来导出。

另外,对于一些安全类很高的系统是不允许随意创建表,也不允许使用PLSQL Developer等客户端的工具,那么若是查询DBA_HIST_ACTIVE_SESS_HISTORY等视图的时候就非常不方便了,这个时候我们可以将该视图的内容导出来,然后导入到我们自己的测试库中就可以随意的进行分析了。那么,如何来导出这些数据的内容呢?本文将详细介绍这些内容

1.3  如何导出ash数据?

根据前边的分析,我们知道视图的查询结果数据不能直接导出,那么我们可以导出这个视图的基表数据:

SELECT D.NAME, D.TYPE, D.REFERENCED_NAME, D.REFERENCED_TYPE

  FROM DBA_DEPENDENCIES D

 WHERE D.NAME IN ('DBA_HIST_ACTIVE_SESS_HISTORY',

                  'DBA_HIST_PLAN_OPERATION_NAME',

                  'DBA_HIST_PLAN_OPTION_NAME',

                  'DBA_HIST_SQLCOMMAND_NAME',

                  'DBA_HIST_TOPLEVELCALL_NAME')

   AND D.TYPE = 'VIEW'

 ORDER BY D.NAME, D.REFERENCED_NAME;

wpsF4F8.tmp 

主要涉及的表是图中方框里的去掉X$表后的7个表,其中最主要的还是WRH$_ACTIVE_SESSION_HISTORY表,该表是一个分区表,导出的时候可以按照时间进行导出。其它表都是很小的表,可以全量导出。

下面尝试使用exp和expdp来导出。

 

1.3.1  expdp导出sys用户下的表报错ORA-39165 ORA-39166

[oracle@orcltest ~]$ more /tmp/expdp_ash_lhr_01.par

query=SYS.WRH$_ACTIVE_SESSION_HISTORY:"WHERE SAMPLE_TIME BETWEEN TO_DATE('2016-12-02 08:30:00', 'YYYY-MM-DD HH24:MI:SS') AND TO_DATE('2016-12-08 23:38:00', 'YYYY-MM-DD HH24:MI:SS')"

[oracle@orcltest ~]$

[oracle@orcltest ~]$ expdp \'/ AS SYSDBA\' directory=DATA_PUMP_DIR tables='SYS.WRH$_ACTIVE_SESSION_HISTORY','SYS.WRM$_SNAPSHOT','SYS.WRH$_EVENT_NAME','SYS.WRH$_SQLCOMMAND_NAME','SYS.WRH$_PLAN_OPERATION_NAME','SYS.WRH$_PLAN_OPTION_NAME','SYS.WRH$_TOPLEVELCALL_NAME' dumpfile=expdp_ash_lhr_01.dmp parfile=/tmp/expdp_ash_lhr_01.par  EXCLUDE=STATISTICS VERSION=11.2.0.1  REUSE_DUMPFILES=Y

 

Export: Release 11.2.0.3.0 - Production on Fri Dec 16 16:49:52 2016

 

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

 

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

With the Partitioning, Automatic Storage Management, OLAP, Data Mining

and Real Application Testing options

Starting "SYS"."SYS_EXPORT_TABLE_03":  "/******** AS SYSDBA" directory=DATA_PUMP_DIR tables=SYS.WRH$_ACTIVE_SESSION_HISTORY,SYS.WRM$_SNAPSHOT,SYS.WRH$_EVENT_NAME,SYS.WRH$_SQLCOMMAND_NAME,SYS.WRH$_PLAN_OPERATION_NAME,SYS.WRH$_PLAN_OPTION_NAME,SYS.WRH$_TOPLEVELCALL_NAME dumpfile=expdp_ash_lhr_01.dmp parfile=/tmp/expdp_ash_lhr_01.par EXCLUDE=STATISTICS VERSION=11.2.0.1 REUSE_DUMPFILES=Y

Estimate in progress using BLOCKS method...

Total estimation using BLOCKS method: 0 KB

ORA-39166: Object SYS.WRH$_ACTIVE_SESSION_HISTORY was not found.

ORA-39166: Object SYS.WRM$_SNAPSHOT was not found.

ORA-39166: Object SYS.WRH$_EVENT_NAME was not found.

ORA-39166: Object SYS.WRH$_SQLCOMMAND_NAME was not found.

ORA-39166: Object SYS.WRH$_PLAN_OPERATION_NAME was not found.

ORA-39166: Object SYS.WRH$_PLAN_OPTION_NAME was not found.

ORA-39166: Object SYS.WRH$_TOPLEVELCALL_NAME was not found.

ORA-31655: no data or metadata objects selected for job

Job "SYS"."SYS_EXPORT_TABLE_03" completed with 8 error(s) at 16:49:53

 

 

查询MOS

DataPump Export (EXPDP) Fails With Error ORA-39165: Schema SYS Was Not Found (文档 ID 553402.1)

该文章给出了如下答案:

1. There is a restriction on dataPump export. It cannot export schemas like SYS, ORDSYS, EXFSYS, MDSYS, DMSYS, CTXSYS, ORDPLUGINS, LBACSYS, XDB, SI_INFORMTN_SCHEMA, DIP, DBSNMP and WMSYS in any mode.  

2. The Utilities Guide indicates the restriction only on full export mode, but the restriction actually applies to all modes. 

wpsF4F9.tmp

而:MOS:Why Can an Object Not Be Exported? Expdp of SYSTEM User's Table Returns ORA-39166 or ORA-31655 (文档 ID 2114233.1)列出来了哪些对象不能导出:

Objects (tables, views, schemas, etc) which fall under either of below conditions are not exported with expdp because they are regarded as system maintained objects.

Object is listed in ku_noexp_view.

This view is a union of ku_noexp_tab and noexp$ tables.

Objects that are listed in this view are not exported.

 

Object is ORACLE_MAINTAINED='Y' in ALL_OBJECTS (and DBA_OBJECTS).----针对12c

在视图sys.Ku_Noexp_View中或DBA_OBJECTSORACLE_MAINTAINED列为Y的对象不能导出。

SELECT * FROM sys.Ku_Noexp_View d WHERE d.name LIKE '%WRH%' ;

SELECT * FROM DBA_OBJECTS d WHERE d.ORACLE_MAINTAINED='Y' AND D.object_name LIKE 'WR%';

 

解决该报错的方法是: 
1. 使用exp 导出 
2.ctas的方法在不受限制的schema下创建表,然后导出该新建的表 
3. use the DBMS_AUDIT_MGMT package of Audit Vault to manage and purge audit data (see Note 731908.1). This allows for the facility to move the AUD$ table out of the SYSTEM tablespace, which can negate the need to export the table. 
注意:This issue also applies to other SYS owned auditing tables such as FGA_LOG$

1.3.2  采用exp导出ASH数据

1.3.2.1  方法1:ctas建表导出有的客户不让建表

CREATE TABLE ASH_TEMP_20161219  NOLOGGING AS

SELECT *

  FROM DBA_HIST_ACTIVE_SESS_HISTORY D

WHERE D.SAMPLE_TIME BETWEEN

       TO_DATE('2016-12-01 02:00:00', 'YYYY-MM-DD HH24:MI:SS') AND

       TO_DATE('2016-12-17 06:00:00', 'YYYY-MM-DD HH24:MI:SS')

;

 

exp   \'/ AS SYSDBA\'  tables=ASH_TEMP_20161219  file=/tmp/exp_ASH_TEMP_20161219.dmp  log=/tmp/ASH_TEMP_20161117.log  buffer=41943040

imp  lhr/lhr  tables=ASH_TEMP_20161219  file=/tmp/ASH_TEMP_20161219.dmp  log=/tmp/imp_ASH_TEMP_20161117.log  buffer=41943040

 

 

 

实验过程:

[oracle@orcltest ~]$ sqlplus / as sysdba

 

SQL*Plus: Release 11.2.0.3.0 Production on Mon Dec 19 09:51:09 2016

 

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

 

 

Connected to:

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

With the Partitioning, Automatic Storage Management, OLAP, Data Mining

and Real Application Testing options

 

SYS@lhrdb> CREATE TABLE ASH_TEMP_20161219  NOLOGGING AS

  2  SELECT *

  3    FROM DBA_HIST_ACTIVE_SESS_HISTORY D

  4   WHERE D.SAMPLE_TIME BETWEEN

  5         TO_DATE('2016-12-01 02:00:00', 'YYYY-MM-DD HH24:MI:SS') AND

  6         TO_DATE('2016-12-17 06:00:00', 'YYYY-MM-DD HH24:MI:SS')

  7  ;

 

Table created.

 

SYS@lhrdb> exit

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

With the Partitioning, Automatic Storage Management, OLAP, Data Mining

and Real Application Testing options

[oracle@orcltest ~]$

[oracle@orcltest ~]$

[oracle@orcltest ~]$ exp   \'/ AS SYSDBA\'  tables=ASH_TEMP_20161219  file=/tmp/ASH_TEMP_20161219.dmp  log=/tmp/ASH_TEMP_20161219.log  buffer=41943040

 

Export: Release 11.2.0.3.0 - Production on Mon Dec 19 09:51: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.3.0 - 64bit Production

With the Partitioning, Automatic Storage Management, OLAP, Data Mining

and Real Application Testing options

Export done in ZHS16GBK character set and AL16UTF16 NCHAR character set

 

About to export specified tables via Conventional Path ...

. . exporting table              ASH_TEMP_20161219        102 rows exported

Export terminated successfully without warnings.

[oracle@orcltest ~]$ imp  lhr/lhr  tables=ASH_TEMP_20161219  file=/tmp/ASH_TEMP_20161219.dmp  log=/tmp/ASH_TEMP_20161117.log  buffer=41943040

 

Import: Release 11.2.0.3.0 - Production on Mon Dec 19 09:52:20 2016

 

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

 

 

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

With the Partitioning, Automatic Storage Management, OLAP, Data Mining

and Real Application Testing options

 

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

 

Warning: the objects were exported by SYS, not by you

 

import done in ZHS16GBK character set and AL16UTF16 NCHAR character set

. importing SYS's objects into LHR

. importing SYS's objects into LHR

. . importing table            "ASH_TEMP_20161219"        102 rows imported

Import terminated successfully without warnings.

[oracle@orcltest ~]$

 

 

1.3.2.2  方法2:导出基表的数据

导出基表数据:

---more /tmp/exp_ash_lhr_01.par

query="WHERE SAMPLE_TIME BETWEEN TO_DATE('2016-12-02 08:30:00', 'YYYY-MM-DD HH24:MI:SS') AND TO_DATE('2016-12-08 23:38:00', 'YYYY-MM-DD HH24:MI:SS')"

 

exp \'/ AS SYSDBA\'  tables='WRH$_ACTIVE_SESSION_HISTORY' file=/tmp/exp_ash_lhr_01.dmp parfile=/tmp/exp_ash_lhr_01.par log=/tmp/exp_ash_lhr_01.log GRANTS=N CONSTRAINTS=N  STATISTICS=NONE

exp \'/ AS SYSDBA\'  tables='WRM$_SNAPSHOT','WRH$_EVENT_NAME','WRH$_SQLCOMMAND_NAME','WRH$_PLAN_OPERATION_NAME','WRH$_PLAN_OPTION_NAME','WRH$_TOPLEVELCALL_NAME' file=/tmp/exp_ash_lhr_02.dmp log=/tmp/exp_ash_lhr_02.log  GRANTS=N  CONSTRAINTS=N  STATISTICS=NONE

 

导入到测试用户:

imp lhr/lhr file=/tmp/exp_ash_lhr_01.dmp tables='WRH$_ACTIVE_SESSION_HISTORY' log=/tmp/imp_ash_lhr_01.log  FROMUSER=SYS TOUSER=LHR

imp lhr/lhr file=/tmp/exp_ash_lhr_02.dmp tables='WRM$_SNAPSHOT','WRH$_EVENT_NAME','WRH$_SQLCOMMAND_NAME','WRH$_PLAN_OPERATION_NAME','WRH$_PLAN_OPTION_NAME','WRH$_TOPLEVELCALL_NAME' log=/tmp/imp_ash_lhr_02.log   FROMUSER=SYS TOUSER=LHR

 

 

DROP TABLE LHR.WRH$_ACTIVE_SESSION_HISTORY PURGE;

DROP TABLE LHR.WRM$_SNAPSHOT PURGE;

DROP TABLE LHR.WRH$_EVENT_NAME PURGE;

DROP TABLE LHR.WRH$_SQLCOMMAND_NAME PURGE;

DROP TABLE LHR.WRH$_PLAN_OPERATION_NAME PURGE;

DROP TABLE LHR.WRH$_PLAN_OPTION_NAME PURGE;

DROP TABLE LHR.WRH$_TOPLEVELCALL_NAME PURGE;

 

 

 

实验:

[oracle@orcltest ~]$ more /tmp/exp_ash_lhr_01.par

query="WHERE SAMPLE_TIME BETWEEN TO_DATE('2016-12-02 08:30:00', 'YYYY-MM-DD HH24:MI:SS') AND TO_DATE('2016-12-08 23:38:00', 'YYYY-MM-DD HH24:MI:SS')"

[oracle@orcltest ~]$ exp \'/ AS SYSDBA\'  tables='WRH$_ACTIVE_SESSION_HISTORY' file=/tmp/exp_ash_lhr_01.dmp parfile=/tmp/exp_ash_lhr_01.par log=/tmp/exp_ash_lhr_01.log GRANTS=N CONSTRAINTS=N  STATISTICS=NONE

 

Export: Release 11.2.0.3.0 - Production on Mon Dec 19 10:25:05 2016

 

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

 

 

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

With the Partitioning, Automatic Storage Management, OLAP, Data Mining

and Real Application Testing options

Export done in ZHS16GBK character set and AL16UTF16 NCHAR character set

Note: grants on tables/views/sequences/roles will not be exported

Note: constraints on tables will not be exported

 

About to export specified tables via Conventional Path ...

. . exporting table    WRH$_ACTIVE_SESSION_HISTORY

. . exporting partition        WRH$_ACTIVE_971836524_0         55 rows exported

. . exporting partition       WRH$_ACTIVE_971836524_35          0 rows exported

. . exporting partition      WRH$_ACTIVE_SES_MXDB_MXSN          0 rows exported

Export terminated successfully without warnings.

[oracle@orcltest ~]$ exp \'/ AS SYSDBA\'  tables='WRM$_SNAPSHOT','WRH$_EVENT_NAME','WRH$_SQLCOMMAND_NAME','WRH$_PLAN_OPERATION_NAME','WRH$_PLAN_OPTION_NAME','WRH$_TOPLEVELCALL_NAME' file=/tmp/exp_ash_lhr_02.dmp log=/tmp/exp_ash_lhr_02.log  GRANTS=N  CONSTRAINTS=N  STATISTICS=NONE

 

Export: Release 11.2.0.3.0 - Production on Mon Dec 19 10:25:12 2016

 

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

 

 

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

With the Partitioning, Automatic Storage Management, OLAP, Data Mining

and Real Application Testing options

Export done in ZHS16GBK character set and AL16UTF16 NCHAR character set

Note: grants on tables/views/sequences/roles will not be exported

Note: constraints on tables will not be exported

 

About to export specified tables via Conventional Path ...

. . exporting table                  WRM$_SNAPSHOT         23 rows exported

. . exporting table                WRH$_EVENT_NAME       1152 rows exported

. . exporting table           WRH$_SQLCOMMAND_NAME        165 rows exported

. . exporting table       WRH$_PLAN_OPERATION_NAME        130 rows exported

. . exporting table          WRH$_PLAN_OPTION_NAME        165 rows exported

. . exporting table         WRH$_TOPLEVELCALL_NAME        151 rows exported

Export terminated successfully without warnings.

 

 

[oracle@orcltest ~]$ imp lhr/lhr file=/tmp/exp_ash_lhr_01.dmp tables='WRH$_ACTIVE_SESSION_HISTORY' log=/tmp/imp_ash_lhr_01.log  FROMUSER=SYS TOUSER=LHR

 

Import: Release 11.2.0.3.0 - Production on Mon Dec 19 10:28:37 2016

 

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

 

 

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

With the Partitioning, Automatic Storage Management, OLAP, Data Mining

and Real Application Testing options

 

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

 

Warning: the objects were exported by SYS, not by you

 

import done in ZHS16GBK character set and AL16UTF16 NCHAR character set

. importing SYS's objects into LHR

. . importing partition "WRH$_ACTIVE_SESSION_HISTORY":"WRH$_ACTIVE_971836524_0"         55 rows imported

. . importing partition "WRH$_ACTIVE_SESSION_HISTORY":"WRH$_ACTIVE_971836524_35"          0 rows imported

. . importing partition "WRH$_ACTIVE_SESSION_HISTORY":"WRH$_ACTIVE_SES_MXDB_MXSN"          0 rows imported

Import terminated successfully without warnings.

[oracle@orcltest ~]$

 

[oracle@orcltest ~]$

[oracle@orcltest ~]$ imp lhr/lhr file=/tmp/exp_ash_lhr_02.dmp tables='WRM$_SNAPSHOT','WRH$_EVENT_NAME','WRH$_SQLCOMMAND_NAME','WRH$_PLAN_OPERATION_NAME','WRH$_PLAN_OPTION_NAME','WRH$_TOPLEVELCALL_NAME' log=/tmp/imp_ash_lhr_02.log   FROMUSER=SYS TOUSER=LHR

 

Import: Release 11.2.0.3.0 - Production on Mon Dec 19 10:27:26 2016

 

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

 

 

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

With the Partitioning, Automatic Storage Management, OLAP, Data Mining

and Real Application Testing options

 

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

 

Warning: the objects were exported by SYS, not by you

 

import done in ZHS16GBK character set and AL16UTF16 NCHAR character set

. importing SYS's objects into LHR

. . importing table                "WRM$_SNAPSHOT"         23 rows imported

. . importing table              "WRH$_EVENT_NAME"       1152 rows imported

. . importing table         "WRH$_SQLCOMMAND_NAME"        165 rows imported

. . importing table     "WRH$_PLAN_OPERATION_NAME"        130 rows imported

. . importing table        "WRH$_PLAN_OPTION_NAME"        165 rows imported

. . importing table       "WRH$_TOPLEVELCALL_NAME"        151 rows imported

Import terminated successfully without warnings.

[oracle@orcltest ~]$

 

接下来就是根据这些基表来创建自己的视图了,不再详述。

 

1.3.3  12c  expdp VIEWS_AS_TABLES选项

expdp VIEWS_AS_TABLES选项可以将视图看做表并将其数据导出。

expdp system/lhr DIRECTORY=data_pump_dir DUMPFILE=expdp_vw.dmp LOGFILE=expdp_vw.log VIEWS_AS_TABLES=lhr.my_view

表数据准备:

create table lhr.my_tab1 (nr number, txt varchar2(10));

insert into lhr.my_tab1 values (1,'Line 1');

insert into lhr.my_tab1 values (2,'Line 2');

 

create table lhr.my_tab2 (nr number, col2 number, col3 varchar2(10));

insert into lhr.my_tab2 values (1,1,'c3_1');

insert into lhr.my_tab2 values (2,2,'c3_2');

commit;

create view lhr.my_view (nr, txt, col3) as

   select t1.nr, t1.txt, t2.col3

     from lhr.my_tab1 t1, lhr.my_tab2 t2

    where t1.nr=t2.nr;

 

 

开始导出:

C:\Users\xiaomaimiao>expdp system/lhr DIRECTORY=data_pump_dir DUMPFILE=expdp_vw.dmp LOGFILE=expdp_vw.log VIEWS_AS_TABLES=lhr.my_view

 

Export: Release 12.1.0.2.0 - Production on 星期五 12月 16 16:31:49 2016

 

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

 

连接到: Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production

With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options

启动 "SYSTEM"."SYS_EXPORT_TABLE_01":  system/******** DIRECTORY=data_pump_dir DUMPFILE=expdp_vw.dmp LOGFILE=expdp_vw.log VIEWS_AS_TABLES=lhr.my_view

正在使用 BLOCKS 方法进行估计...

处理对象类型 TABLE_EXPORT/VIEWS_AS_TABLES/TABLE_DATA

使用 BLOCKS 方法的总估计: 16 KB

处理对象类型 TABLE_EXPORT/VIEWS_AS_TABLES/TABLE

. . 导出了 "LHR"."MY_VIEW"                             5.929 KB       2 

已成功加载/卸载了主表 "SYSTEM"."SYS_EXPORT_TABLE_01"

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

SYSTEM.SYS_EXPORT_TABLE_01 的转储文件集为:

  E:\APP\ORACLE\ADMIN\LHRDB12C\DPDUMP\EXPDP_VW.DMP

作业 "SYSTEM"."SYS_EXPORT_TABLE_01" 已于 星期五 12月 16 16:32:36 2016 elapsed 0 00:00:31 成功完成

 

 

 

查看其DDL语句:

 

C:\Users\xiaomaimiao>impdp system/lhr DIRECTORY=data_pump_dir DUMPFILE=expdp_vw.dmp LOGFILE=impdp_vw.log sqlfile=a.txt

 

Import: Release 12.1.0.2.0 - Production on 星期五 12月 16 16:35:14 2016

 

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

 

连接到: Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production

With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options

已成功加载/卸载了主表 "SYSTEM"."SYS_SQL_FILE_FULL_01"

启动 "SYSTEM"."SYS_SQL_FILE_FULL_01":  system/******** DIRECTORY=data_pump_dir DUMPFILE=expdp_vw.dmp LOGFILE=impdp_vw.log sqlfile=a.txt

处理对象类型 TABLE_EXPORT/VIEWS_AS_TABLES/TABLE

作业 "SYSTEM"."SYS_SQL_FILE_FULL_01" 已于 星期五 12月 16 16:35:26 2016 elapsed 0 00:00:10成功完成

 

 

DDL语句内容:

-- CONNECT SYSTEM

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: TABLE_EXPORT/VIEWS_AS_TABLES/TABLE

CREATE TABLE "LHR"."MY_VIEW"

   ("NR" NUMBER,

"TXT" VARCHAR2(10 BYTE),

"COL3" VARCHAR2(10 BYTE)

   ) SEGMENT CREATION DEFERRED

  PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255

NOCOMPRESS LOGGING

  TABLESPACE "USERS" ;

 

 

进行导入:

C:\Users\xiaomaimiao>sqlplus / as sysdba

 

SQL*Plus: Release 12.1.0.2.0 Production on 星期五 12月 16 16:37:03 2016

 

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

 

 

连接到:

Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production

With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options

 

SQL> create user lhr01 identified by lhr;

 

用户已创建。

 

SQL> grant dba to lhr01;

 

授权成功。

 

SQL> exit

从 Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production

With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options 断开

 

C:\Users\xiaomaimiao>impdp system/lhr DIRECTORY=data_pump_dir DUMPFILE=expdp_vw.dmp LOGFILE=impdp_vw.log remap_schema=lhr:lhr01

 

Import: Release 12.1.0.2.0 - Production on 星期五 12月 16 16:39:49 2016

 

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

 

连接到: Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production

With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options

已成功加载/卸载了主表 "SYSTEM"."SYS_IMPORT_FULL_02"

启动 "SYSTEM"."SYS_IMPORT_FULL_02":  system/******** DIRECTORY=data_pump_dir DUMPFILE=expdp_vw.dmp LOGFILE=impdp_vw.log remap_schema=lhr:lhr01

处理对象类型 TABLE_EXPORT/VIEWS_AS_TABLES/TABLE

处理对象类型 TABLE_EXPORT/VIEWS_AS_TABLES/TABLE_DATA

. . 导入了 "LHR01"."MY_VIEW"                           5.929 KB       2 

作业 "SYSTEM"."SYS_IMPORT_FULL_02" 已于 星期五 12月 16 16:39:57 2016 elapsed 0 00:00:06 成功完成

 

 

 

1.4  小结

--- 方法1ctas建表导出 有的客户不让建表

CREATE TABLE ASH_TEMP_20161117  NOLOGGING AS

SELECT *

  FROM DBA_HIST_ACTIVE_SESS_HISTORY D

WHERE D.SAMPLE_TIME BETWEEN

       TO_DATE('2016-11-10 02:00:00', 'YYYY-MM-DD HH24:MI:SS') AND

       TO_DATE('2016-11-17 06:00:00', 'YYYY-MM-DD HH24:MI:SS')

;

 

exp   \'/ AS SYSDBA\'  tables=ASH_TEMP_20161117  file=/tmp/ASH_TEMP_20161117.dmp  log=/tmp/ASH_TEMP_20161117.log  buffer=41943040

 

 

 

--- 方法2:导出基表的数据

采用exp导出ASH数据的命令:

---more /tmp/exp_ash_lhr_01.par

query="WHERE SAMPLE_TIME BETWEEN TO_DATE('2016-12-02 08:30:00', 'YYYY-MM-DD HH24:MI:SS') AND TO_DATE('2016-12-08 23:38:00', 'YYYY-MM-DD HH24:MI:SS')"

 

exp \'/ AS SYSDBA\'  tables='WRH$_ACTIVE_SESSION_HISTORY' file=/tmp/exp_ash_lhr_01.dmp parfile=/tmp/exp_ash_lhr_01.par log=/tmp/exp_ash_lhr_01.log GRANTS=N CONSTRAINTS=N  STATISTICS=NONE

exp \'/ AS SYSDBA\'  tables='WRM$_SNAPSHOT','WRH$_EVENT_NAME','WRH$_SQLCOMMAND_NAME','WRH$_PLAN_OPERATION_NAME','WRH$_PLAN_OPTION_NAME','WRH$_TOPLEVELCALL_NAME' file=/tmp/exp_ash_lhr_02.dmp log=/tmp/exp_ash_lhr_02.log  GRANTS=N  CONSTRAINTS=N  STATISTICS=NONE

 

imp lhr/lhr file=/tmp/exp_ash_lhr_01.dmp tables='WRH$_ACTIVE_SESSION_HISTORY' log=/tmp/imp_ash_lhr_01.log  FROMUSER=SYS TOUSER=LHR

imp lhr/lhr file=/tmp/exp_ash_lhr_02.dmp tables='WRM$_SNAPSHOT','WRH$_EVENT_NAME','WRH$_SQLCOMMAND_NAME','WRH$_PLAN_OPERATION_NAME','WRH$_PLAN_OPTION_NAME','WRH$_TOPLEVELCALL_NAME' log=/tmp/imp_ash_lhr_02.log   FROMUSER=SYS TOUSER=LHR

 

 

DROP TABLE LHR.WRH$_ACTIVE_SESSION_HISTORY PURGE;

DROP TABLE LHR.WRM$_SNAPSHOT PURGE;

DROP TABLE LHR.WRH$_EVENT_NAME PURGE;

DROP TABLE LHR.WRH$_SQLCOMMAND_NAME PURGE;

DROP TABLE LHR.WRH$_PLAN_OPERATION_NAME PURGE;

DROP TABLE LHR.WRH$_PLAN_OPTION_NAME PURGE;

DROP TABLE LHR.WRH$_TOPLEVELCALL_NAME PURGE;

 





     本文转自lhrbest 51CTO博客,原文链接:http://blog.51cto.com/lhrbest/1884099,如需转载请自行联系原作者



相关实践学习
AnalyticDB MySQL海量数据秒级分析体验
快速上手AnalyticDB MySQL,玩转SQL开发等功能!本教程介绍如何在AnalyticDB MySQL中,一键加载内置数据集,并基于自动生成的查询脚本,运行复杂查询语句,秒级生成查询结果。
阿里云云原生数据仓库AnalyticDB MySQL版 使用教程
云原生数据仓库AnalyticDB MySQL版是一种支持高并发低延时查询的新一代云原生数据仓库,高度兼容MySQL协议以及SQL:92、SQL:99、SQL:2003标准,可以对海量数据进行即时的多维分析透视和业务探索,快速构建企业云上数据仓库。 了解产品 https://www.aliyun.com/product/ApsaraDB/ads
相关文章
|
监控 关系型数据库 PostgreSQL
PostgreSQL 12: 新增 pg_stat_progress_create_index 视图监控索引创建进度
PostgreSQL 12 版本之前,对PostgreSQL大表创建索引时是一个比较痛苦的过程,创建索引过程中无法得知索引创建进度,PostgreSQL 12 在运维监控功能方面得到增强,新增 pg_stat_progress_create_index 视图可以监控索引的创建进度,本文简单演示。
2242 0
|
SQL 关系型数据库 开发工具
|
SQL Perl Java
11g v$active_session_history的新增列
很多知识我都还停留在10g,今天同事在ASH中直接就找到了SQL语句消耗的PGA,才发现,11gR2的ASH多了如此多的列1.标示这条ASH记录是否被刷入了磁盘  IS_AWR_SAMPLE                 dba_hist_active_sess_history中就没有这一列2.
1366 0
|
SQL
根据sql_id 查询历史SQL TEXT :dba_hist_sqltext
select * from dba_hist_sqltext where sql_id in ('gdduv7gpwu2k4','6ta2r7v563nbv','5jmanw0t1dpsa','16zfwqb2ma4xw','0a63j7qqrp6wk') ...
3208 0
|
SQL Oracle 关系型数据库
【ASH】如何导出视图DBA_HIST_ACTIVE_SESS_HISTORY的查询结果数据
【ASH】如何导出视图DBA_HIST_ACTIVE_SESS_HISTORY的查询结果数据   1.1  BLOG文档结构图   1.
1211 0