利用utl_file来读取文件.
以前写过用external table来加载trace文件,详情参考下面链接.
http://www.cnblogs.com/princessd8251/p/3779145.html
今天要做到是用UTL_FILE包来读取一个directory下面的文件,比如我们的trace文件.
先定义get_trace_file 函数.
-- create directory and varchar2 array
col value new_value user_dump_directory;
select value from v$parameter where name = 'user_dump_dest';
create or replace directory user_dump_dir as '&user_dump_directory';
create or replace type varchar2_array as table of varchar2(4000);
/ -- create get_trace_file1 function
create or replace function get_trace_file1(s_id number default userenv('sid'))
return varchar2_array
pipelined
as
v_handle utl_file.file_type;
v_filename varchar2(2000);
v_line varchar2(4000);
begin
-- get exact file_name
-- below code can be repaced by a query against v$diag_info if you are on Oracle 11G.
select i.value||'_ora_'||p.spid||decode(t.value,null,'','_'||t.value)||'.trc' into v_filename
from v$process p, v$session s,
(select value from v$parameter where name = 'instance_name') i,
(select value from v$parameter where name = 'tracefile_identifier') t
where p.addr = s.paddr and s.sid = s_id;
v_handle := utl_file.fopen('USER_DUMP_DIR', v_filename, 'R', 32767);
loop
begin
utl_file.get_line(v_handle, v_line);
exception when no_data_found then
exit;
end;
pipe row(v_line);
end loop;
utl_file.fclose(v_handle);
return;
end;
/ -- create get_trace_file2 function
create or replace function get_trace_file2(file_name in varchar2)
return varchar2_array
pipelined
as
v_handle utl_file.file_type;
v_line varchar2(20000);
begin
v_handle := utl_file.fopen('USER_DUMP_DIR', file_name, 'R', 32767);
loop
begin
utl_file.get_line(v_handle, v_line);
exception
when no_data_found then
exit;
end;
pipe row(v_line);
end loop;
utl_file.fclose(v_handle);
return;
end;
/ -- create get_trace_file3 function
create or replace function get_trace_file3(dir_name in varchar2, file_name in varchar2)
return varchar2_array
pipelined
as
v_handle utl_file.file_type;
v_line varchar2(20000);
begin
v_handle := utl_file.fopen(dir_name, file_name, 'R', 32767);
loop
begin
utl_file.get_line(v_handle, v_line);
exception
when no_data_found then
exit;
end;
pipe row(v_line);
end loop;
utl_file.fclose(v_handle);
return;
end;
/
然后开启10046,并执行一个查询. alter session set events '10046 trace name context forever, level 8';
select count(*) from t1;
alter session set events '10046 trace name context off';
用函数get_trace_file1去查看内容.
select * from table(get_trace_file1); Dump file c:\oracle\admin\ukja10\udump\ukja10_ora_2820.trc
Thu Mar 19 15:10:10 2009
ORACLE V10.2.0.1.0 - Production vsnsta=0
vsnsql=14 vsnxtr=3
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
Windows XP Version V5.1 Service Pack 2
CPU : 2 - type 586
Process Affinity : 0x00000000
Memory (Avail/Total): Ph:1481M/3070M, Ph+PgF:3140M/4960M, VA:1359M/2047M
Instance name: ukja10 Redo thread mounted by this instance: 1 Oracle process number: 16 Windows thread id: 2820, image: ORACLE.EXE (SHAD) *** ACTION NAME:() 2009-03-19 15:10:10.109
*** MODULE NAME:(SQL*Plus) 2009-03-19 15:10:10.109
*** SERVICE NAME:(UKJA10) 2009-03-19 15:10:10.109
*** SESSION ID:(157.1205) 2009-03-19 15:10:10.109
=====================
PARSING IN CURSOR #1 len=68 dep=0 uid=61 oct=42 lid=61 tim=172367882897 hv=740818757 ad='27e12b14'
alter session set events '10046 trace name context forever, level 8'
END OF STMT
...
Now I sort the buffer busy waits event by class# like this.
col class# format a10
col elapsed format 99.99 with t as (
select /*+ materialize */
column_value as line,
instr(column_value, 'ela=') ei,
instr(column_value, 'file#=') fi,
instr(column_value, 'block#=') bi,
instr(column_value, 'class#=') ci,
instr(column_value, 'obj#=') oi,
instr(column_value, 'tim=') ti
from table(get_trace_file2('trc_1.trc'))
--from table(get_trace_file2('trc_2.trc'))
where
instr(column_value, 'WAIT #2: nam=''buffer busy waits''') > 0
--instr(column_value, 'WAIT #11: nam=''buffer busy waits''') > 0
)
select
class#
, count(1) as cnt
, sum(elapsed)/1000000 as elapsed
from
(
select
substr(line, ei+4, fi-ei-4) as elapsed,
substr(line, fi+6, bi-fi-6) as file#,
substr(line, bi+7, ci-bi-7) as block#,
substr(line, ci+7, oi-ci-7) as class#,
substr(line, oi+5, ti-oi-5) as obj#,
substr(line, ti+4) as tim
from
t
) x
group by
class#
order by
2 desc, 3 desc;
What I’m actually doing is:
- trc_1.trc file contains the 10046 trace result with 40K extent size in ASSM.
- trc_2.trc file contains the 10046 trace result with 10M extent size in ASSM.
- 10 concurrent sessions insert into the table with 10046 trace enabled.
- I’d like to analyze how extent size affects the pattern of buffer contention.
Here is the result.
--when extent size is 40K
CLASS# CNT ELAPSED
---------- ---------- -------
8 285 1.40
1 215 4.64
4 42 .01
9 2 .00
19 1 .00
33 1 .00 -- when extent size is 10M
CLASS# CNT ELAPSED
---------- ---------- -------
8 1456 3.01
1 420 1.54
4 5 .00
35 2 .00
77 1 .00
See the diffference. With big extent size, we have major buffer contention on 1st level bitmap block(8). With (too) smaller extent size, the major contention is on data block(1).
利用utl_file来读取文件.的更多相关文章
- html5中利用FileReader来读取文件。
利用FileReader来读取文件的能够来实现即时预览的效果,这个也是在html5中才有的功能. <!DOCTYPE html> <html lang="en"& ...
- Mysql 漏洞利用(越权读取文件,实战怎么从低权限拿到root密码)[转]
cnrstar (Be My Personal Best!) | 2014-05-20 21:58 众所周知,Mysql的用户在没有File权限情况下是无法通过Load_file读文件或者通过into ...
- oracle读写文件--利用utl_file包对磁盘文件的读写操作
oracle读写文件--利用utl_file包对磁盘文件的读写操作 摘要: 用户提出一个需求,即ORACLE中的一个表存储了照片信息,字段类型为BLOB,要求能导出成文件形式. 本想写个C#程序来做, ...
- Java利用内存映射文件实现按行读取文件
我们知道内存映射文件读取是各种读取方式中速度最快的,但是内存映射文件读取的API里没有提供按行读取的方法,需要自己实现.下面就是我利用内存映射文件实现按行读取文件的方法,如有错误之处请指出,或者有更好 ...
- .net上传文件,利用npoi读取文件信息到datatable里
整理代码,.net上传文件,利用npoi读取文件到datatable里,使用了FileUpload控件,代码如下: protected void Button1_Click(object sender ...
- Java读取文件加锁代码Demo(利用Java的NIO)
本博文部分转载于:http://blog.csdn.net/wangbaochu/article/details/48546717 Java 提供了文件锁FileLock类,利用这个类可以控制不同程序 ...
- 利用PushbackReader读取文件中某个字符串之前的内容
package File; import java.io.FileReader; import java.io.IOException; import java.io.PushbackReader; ...
- C++ 利用 libxl 将 Excel 文件转化为 Xml 文件
在游戏开发工作中,策划和运营一般会用Excel来编写配置文件,但是程序读取配置,最方便的还是xml文件.所以最好约定一个格式,然后在二者之间做一个转化. 本文利用libxl来读取Excel文件,利用 ...
- Android从assets目录下读取文件相关
有一个需求是app的帮助文档是word格式,ios可以直接用webview加载word显示,Android不行.而美工不配合转换成图片,前端没时间把word写成html 没办法,自己搞. 步骤: 1. ...
随机推荐
- PHP 常用到的一些小程序
1.计算两个时间的相差几天 $startdate=strtotime(“2009-12-09”); $enddate=strtotime(“2009-12-05”); 上面的php时间日期函数strt ...
- Js获取当前日期时间及其它格式化操作
Js获取当前日期时间及其它操作 var myDate = new Date();myDate.getYear(); //获取当前年份(2位)myDate.getFullYear(); ...
- 外部dtd
引用外部dtd的语法:<!DOCTYPE 根元素 SYSTEM “DTD文档路径”> PUBLIC:公用 SYSTEM:私有 一个xml文件: 引入一个dtd文件(注意文件的后缀是dtd)
- Apache Spark源码走读之12 -- Hive on Spark运行环境搭建
欢迎转载,转载请注明出处,徽沪一郎. 楔子 Hive是基于Hadoop的开源数据仓库工具,提供了类似于SQL的HiveQL语言,使得上层的数据分析人员不用知道太多MapReduce的知识就能对存储于H ...
- 【转载】存储scale-up和scalce-out架构
转自:存储scale-up和scalce-out架构 存储scale-up和scalce-out架构 Scale-up,即纵向扩展架构.从下面的拓扑图我们可见,纵向扩展是利用现有的存储系统,通过不断增 ...
- Ubuntu 14.04 安装 VirtualBox
参考: ubuntu14.04,安装VirtualBox 5.0(虚拟机软件)! 由于Vagrant工具的需要,安装了一下VirtualBox. 使用参考链接的法一居然在软件中心里面报错,我想可能是没 ...
- the basic index concept
Computer Science An Overview _J. Glenn Brookshear _11th Edition Over the years numerous variations o ...
- spring mvc配置文件dispatcher-servlet.xml详解
Spring的配置文档<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="ht ...
- linux 查看系统状态方法
Linux下如何查看系统启动时间和运行时间 1.uptime命令输出:16:11:40 up 59 days, 4:21, 2 users, load average: 0.00, 0.01, 0.0 ...
- 算导Ch34. NP Complete
1.图灵停机问题:无论在多长时间内都无法被任何一台计算机解决 问题描述:问题为H,H的输入数据为P(P是一段程序(程序也是一串字符串数据)),判定P在输入w下是否能够最终停止 H(P(w))=0 若P ...