`

db db2 dba

阅读更多

db2 doc

IBM DB2 数据库 Linux 版、UNIX 版和 Windows 版信息中心

http://www.ibm.com/software/data/db2/udb/sysreqs.html

IBM DB2 Database for Linux, UNIX, and Windows Information Center

http://publib.boulder.ibm.com/infocenter/db2luw/v9/index.jsp

http://publib.boulder.ibm.com/infocenter/db2luw/v9r7/index.jsp

http://www.ibm.com/software/data/db2/udb/support/manualsv9.html

http://www.ibm.com/software/data/db2/udb/support/manualsNLVv9.html

快速启动您的 Linux 应用: 使用 DB2 和 DB2 控制中心

http://www.ibm.com/developerworks/cn/linux/linux-speed-start/l-ss-db2cc/index.html

DB2 移植经验交流视频 下载视频资料,分享华为工程师的 DB2 移植经验

http://www.ibm.com/developerworks/cn/data/downloads/db2migr/

简述数据库管理员的任务。

(1)保证数据的完整性;
(2)保证数据的正确性;
(3)保证数据的安全性;
(4)对数据库进行有效的控制。

db2 setup

DB2 for Linux UNIX and Windows Information Management software System Requirements

http://www-01.ibm.com/software/data/db2/linux-unix-windows/sysreqs.html

DB2 9.1 Installation Requirements

Here you will find installation, system, disk and memory requirements for DB2 Clients and Servers and DB2 Connect. Included are specific requirements for AIX, HP-UX, Linux, Solaris Operating Environment, Windows and the Development Kit for Java level for DB2 products.

db2 setup for redhat linux

http://publib.boulder.ibm.com/infocenter/db2luw/v9/index.jsp?topic=/com.ibm.db2.udb.uprun.doc/doc/r0025127.htm

 

 

安装 DB2

install db2v8 on linux

http://hnroger.itpub.net/post/116/477985

[root@linuxb local]# groupadd db2grp1

[root@linuxb local]# groupadd db2fgrp1

[root@linuxb local]# groupadd dasadm1

[root@linuxb local]# useradd db2inst1 -g db2grp1

[root@linuxb local]# useradd db2fenc1 -g db2fgrp1

[root@linuxb local]# useradd dasusr1 -g dasadm1

[root@linuxb local]# passwd db2inst1

[root@linuxb local]# passwd db2fenc1

[root@linuxb local]# passwd dasusr1

http://he.fi/bchunk /

AS4下cue,bin文件转换为iso后“虚拟光驱

http://blog.csdn.net/qiek/archive/2005/10/10/498833.aspx

从http://he.fi/bchunk/下载bchunk,这是一个把cue,bin文件转换为iso的工具。
我用的是bchunk-1.2.0-0.i386.rpm
直接安装 rpm -hiv bchunk-1.2.0-0.i386.rpm
然后就可以直接执行bchunk file.bin file.cue file
就会得到一个file.iso
mkdir /mnt/cd1
mount file.iso /mnt/cd1 -o loop
OK,现在/mnt/cd1下就是光盘镜像的内容。

[root@linuxb db2inst1]# rpm -ivh bchunk-1.2.0-0.i386.rpm

[root@linuxb db2]# bchunk IBM.DB2.Enterprise.Edition.v8.2.Linux.bin

IBM.DB2.Enterprise.Edition.v8.2.Linux.cue db2v82

[root@linuxb db2]# mount -t iso9660 db2v8201.iso /mnt/cdrom -o loop

[root@linuxb root]# sysctl -w kernel.msgmni=2048

[root@linuxb root]# sysctl -w kernel.shmmax=1073741824

[root@linuxb root]# sysctl -w fs.file-max=32768

[root@linuxb root]# sysctl -w kernel.sem="512 32000 32 1024"

[root@linuxb root]# sysctl -w kernel.threads-max=20480

[root@linuxb root]#

 

DB2 同步

用AWK实现DB2 数据库 Schema的同步

http://database.ctocio.com.cn/153/9076653.shtml

 

DB2性能调优

http://reeboo.iteye.com/blog/265447

一次性能调优的实战

http://reeboo.iteye.com/blog/265451

db2数据库性能调整的相关命令

http://reeboo.iteye.com/blog/265455

 

 

 

DB2性能调优 / DB2执行计划_explain / DB2快照_snapshot

DB2_Universal_Database_Visual_Explain_Tutoria.rar

http://reeboo.iteye.com/blog/265447

性能是数据库应用的永恒话题,也是衡量一个项目成功与否的重要指标。但是,想让系统达到最优性能从来就不是一件简单的任务,需要涉及很多方面的知识。为了帮助大家更好地完成性能调优任务,我们特地将与 DB2 性能调优相关的资源组成一个专题,供大家参考。经验法则

对于很多人来说,特别是对于 DB2 新手来说,性能调优似乎是一个无从着手的任务。下面的文章阐述了一些经过专家实践得出的经验之谈,可以为您的优化过程提供参考。但要提醒大家的是,性能调优没有一成不变的法则,结合实际环境具体问题具体分析才可能达到最佳效果。

调优 DB2 UDB v8.1 及其数据库的最佳实践

10 佳性能技巧

让查询时间减半

在 DB2 Universal Database 中提高 INSERT 性能的技巧

OLTP 应用程序的 DB2 调优技巧

调优 DB2 Universal Database EEE 的快速参考

优化设计

未雨绸缪胜于亡羊补牢,在设计阶段就对 DB2 应用程序和数据库所需的资源进行合理的估计会为以后打下良好的基础。下面的文章阐述了在设计阶段需要考虑的与性能相关的因素。

DB2 数据库设计:取得最佳性能的准则

初始调优和设计方面的考虑

优化 SQL

SQL 是用于存取数据的根本手段。高效的 SQL 语句能够成倍的提高应用程序的效力。下面的文章告诉你如何能够写出高效的 SQL 语句以及充分发挥 DB2 优化器的作用,从而生成最优的存取路径。

高性能 SQL: 通过 DB2 TPC-C 基准实现探索 SQL

DB2基础: 编码 DB2 SQL 以获得最佳性能

调优 IBM DB2 UDB SQL 存取路径

利用散列连接从 DB2 通用数据库获得最佳性能

当我们认为优化器没有正常工作时

关于 DB2 通用数据库中索引覆盖的基本事实

使用实例化的查询表加速 DB2 UDB EEE 中的查询

DB2 V8 中的多维群集

使用 SELECTIVITY 子句影响优化器

优化应用程序

在开发应用程序的时候,不同的实现方式不同会给性能带来不同的影响。下面的文章就一些流行的应用程序接口的性能问题进行了探讨。

在使用 SQLJ 和 JDBC 时获取最优的 DB2 性能

考虑将 SQLJ 用于 DB2 V8 Java 应用程序

Web 开发人员:为最佳性能而进行优化?

使用 Java 在 DB2 UDB EEE 上的高性能插入

ADO.NET 的数据存取性能

用 C# Builder 开发 DB2 Web 应用程序的 5 项性能法则

DB2 Content Manager Web 应用程序: 性能调优和调试方法

性能调优工具

俗话说,手巧不如家什妙。一个好的性能调优工具可以在一定程度上帮助用户完成繁琐的性能调优工作。DB2 中自带了一些工具,可以帮助用户对系统进行调优,此外,IBM 还提供了名为 DB2 Performance Expert 的工具,可以完成更加全面细致的调优工作。

用 DB2 Performance Expert 简化性能管理和调优,第 1 部分

用 DB2 Performance Expert 简化性能管理和调优,第 2 部分

使用语句事件监视器调优 DB2 通用数据库

性能测试工具

很多软件供应商都提供了进行系统性能测试的工具,下面的文章推荐了一个基于 Java 的开放源码的测试工具。

测试您的 DB2 数据库:用 JMeter 测量性能

其他相关因素

数据库的优化涉及到很多方面的因素,下面的文章虽然不是直接描写如何进行系统优化的,但所包含的内容对用户完成 DB2 系统调优任务会有很大帮助。

洞察 DB2 Universal Database:SQL 语句的生命周期

DB2 基础:表空间和缓冲池

DB2 通用数据库进程全接触

一次性能调优的实战

http://reeboo.iteye.com/blog/265451

项目情况:是一个大型公司的内部办公系统,该系统有两个和一般企业应用不太一样的特点:一是用户量非常多,人员数达到2W左右,另一个是采用分级管理的形式,各个分公司数据分开管理。

我们的定位:我们是作为业务平台的提供商参与这个项目的,我们提供底层的开发平台,系统集成商在此基础上进行二次开发。

在项目从开发到部署的过程中遇到了很多的问题,也反映出很多问题。

一、怎么回事,跑得比猫还慢
项 目开发完毕后部署在Ibm aix 小型机上,32G内存,16个cpu。应用服务器采用的是weblogic9.2,数据库是oracle10.0.2。上线后发现系统运行的非常缓慢,甚 至比开发环境下的tomcat还要慢。于是开始排查原因,最开始是对SQL进行监控,优先考虑是数据库访问性能产生瓶颈。通过监控,发现很多业务需要执行 大量的SQL语句,查看客户编写的相关代码,发现在查询数据时循环执行了大量SQL。主要原因在于他们在代码中循环调用了我们相关API,一个最典型的例 子是通过用户ID查找用户NAME,他们在业务表格里没有保存用户name,而是在查询的时候通过用户ID查找用户name填充到页面,几乎每一个查询都 是n+1。
 
另外由于平台使用了hibernate,使得oo编程得非常爽快,导致开发人员完全忽略了相应的数据库操作所带来的压力。很多业务逻辑直接通过PO叠加完成,把一些可以通过很少SQL完成的逻辑全部分散放置到PO里,导致了大量PO的交互和SQL语句。

开 始优化SQL,优化的同时增加大量业务缓存。但优化完毕后运行缓慢的现象依旧存在,性能有了一定的提升但是不是非常明显。继续优化,其中考虑过多频繁访问 的数据使用内存数据库的方式。但是优化过后在tomcat上效果明显,部署到生产环境就问题依旧。于是考虑weblogic的配置问题,作为开发平台提供 商,我们只是提供系统开发相关方面的支持,对于应用服务器和数据库服务器只是做基本的配置系统可运行即可。但是在这个问题上系统集成商咬定是我们平台的问 题不放,并且存在一个很严重的问题:他们使用的是盗版的weblogic,这样根本就没有相应的技术支持。

问题的解决:最后是找了一 个BEA曾经的开发人员,问题实际非常的简单,现场部署的weblogic默认是运行在32位机器上,与64位机器存在一定的不兼容。通过替换相应的 jar包,问题得到了解决,主要是IO方面。替换完毕后,速度提升了进30% 。该开发人员说,如果没有lisence,根本就不会得到这些替换的jar包。

二、内存耗尽了
访问速度的问题解决了,系统的使用量很快上来,马上遇到新的问题:内存耗尽了。严重到几乎每天都要out of memory一次。这种问题在客户现场频繁出现。

本 地测试,tomcat,sun jdk 通过Jprofiler监测内存使用情况。在并发访问门户的情况下,内存确实存在暴涨的情况,100并发,内存使用立刻上升了150m左右,继续并发 100,再增长150m。但是很快在抵达高峰时会有一次gc发生,内存使用稳定在200m,内存里大量char[]数组对象。疲劳测试,内存使用曲线并没 有出现逐渐上升泄露的情况。换weblogic和jrocket测试,gc发生的更加频繁,内存使用稳定。
 
但是现场依旧频繁当机,内存 根本释放不了,一直逐渐增长,典型的内存泄露。对系统缓存、单态对象包括spring管理的对象、IO流进行了统一排查,依旧没有找到内存泄露的原因。使 用IBM 工具分析heapdump文件,结果还是大量的char[]数组对象占据内存,查找应用,找不到相关业务对象引用。
 
问题解 决:问题解决是一篇偶尔搜到的oracle论坛的帖子,这里http://forums.oracle.com/forums /message.jspa?messageID=1040570 。原因在于oracle10的数据库驱动对statement最后执行的结果集有着引用,并且不会释放,目的在于通过内存而换取更好的性能。数据库连接采 用的是weblogic的连接池,关于connection有个相关的statement cache设定,设定一个connection能够被缓存的statement个数,最大是1024,而现场就被设定为了1024!connection pool的connection个数被设置为了500 。真是个恐怖的设置。在将1024改为10后,内存使用量轰然倒地,稳定在1g左右。这个设置是在前面系统访问速度存在问题时由系统集成商的开发人员设置 上去的,他们将所有和优化相关的参数全部开到了最大。这个问题要是用户购买的是正版的weblogic和oracle的话,相信也会很快得到解决。

三、线程阻塞
内 存泄露的问题解决后,线程阻塞的问题浮出水面。系统集成商报告是线程死锁,通过分析工具其实是线程阻塞,主要问题在于系统用到了 synchronized关键字,对工作流相关API全部使用了synchronized,原因在这里:http: //ronghao.iteye.com/blog/205731 。分析发现一个工作项提交的操作在连接数据库时被挂起了20分钟!造成了大量线程的排队阻塞。被挂起的原因有很多种。我们采用的方法是将接口拆分和设置事 务timeout时间。但是这显然不是一个好方法。最后是去掉所有的synchronized关键字,将同步的问题交由数据库解决,问题解决。

db2数据库性能调整的相关命令

http://reeboo.iteye.com/blog/265455

 

IBM DB2数据库性能调整命令:
查看执行计划:
db2expln:
db2expln -d dbname -c pkgOwner -p pkgNmae -o expln.out
dynexpln:
dynexpln -d eos -q "select * from eosmenu" -g -t
dynexpln -d eos -f query.sql -o out.txt

更新统计信息:
runstats:
db2 runstats on table songxn.eosmenu and indexs songxn.ix1,songxn.ix2 allow read access
db2 runstats on table songxn.eosmenu with distribution and detailed index all

调整优化等级:
(0,1,2,3,5,7,9):
更改DFT_QUERYOPT(db cfg), 默认为5
SQL:set current query optimization = 3
索引:

建立索引:
create unique index ind1 on vicky.staff ( dept, lastname )
create unique index ind2 on vicky.emplyee ( empno ) include ( lastname, salary)
include中的字段不列入排序范围

丛集索引:
记录与索引的顺序一致
cretae index ind3 on vicky.staff ( dept ) CLUSTER

SCAN MODE:
Index Scan,Full Index Scan(Index only Access),Relation Scan

查询索引:
select indname from syscat.indexes where tabname='customer'

索引建议器:
db2advis -d dbname -i query.sql | -s "sql stmt" -o advis.out

在数据页中预留空间:
alter table vicky.staff PCTFREE 30(预留30%)
load from staff.ixf of ixf modified by pagefreespace=30 replace into vicky.staff
缓冲池与IO
默认为IBMDEFAULTBP

新建缓冲池:
db2 create bufferpool bpname size 1000 pagesize 4k
alter tablespace tbname bufferpool bpname
当脏页超过CHNGPGS_THRESH(%,db cfg)时,缓冲池将被清空并写回

 

<<DB2调优案例、问题总结和技巧>>
缓冲池是操作系统共享内存集中的一部分。
在32位数据库环境中,DB2具有数据库共享内存大小的限制,
AIX 上是1.75 GB / Sun Solaris 3.35GB / HP-UX 0.75 GB / Linux 1.75 GB / Windows 2GB或3GB(若boot.ini 中启用了3GB开关),

因此需要平衡缓冲池和其他共享内存缓冲区的配置。
64为环境中则无需考虑此问题。

延展缓冲池:
ESTORE_SEG_SZ& NUM_ESTORE_SEGS(db cfg)
db2 alter bufferpool ibmdefaultbp [ not ] extended storage

I/O SERVER:
NUM_IOSERVERS(db cfg):一般为磁盘数+2

数据重整:
REORGCHK:
db2 reorgchk update statistics on table all 该语句也用来对所有表做RUNSTATS
db2 reorgchk current statistics on table vicky.staff

table statistics:
CARD:记录笔数
OV(ERFLOW)overflow的记录数
NP(AGES):含有记录的页数
FP(AGES):表格占用的总页数
TSIZE(Bytes):表格大小

index statistics:
LEAF:leaf page数
ELEAF:空叶数
NDEL:被删除的RID数
LVLS:索引层级数
ISIZE:索引平均长度
KEYS:不同的索引值的个数

表格重整:
db2 reorg table vicky.staff index ind1 use tempspace2 indexscan

索引重整:
db2 reorg indexes all for table vicky.staff _options_
options:allow read|write|no access, cleanup only pages|all(不重建索引结构,只回收空索引页)

联机表格重整(V8+):
db2 reorg table vicky.staff index vicky.ind2 inplace allow write access
db2 reorg table vicky.staff index vicky.ind2 inplace pause|resume
db2 list history reorg all for dbname
MQT
MQT:
建立MQT:
CREATE TABLE vicky.mqt1 AS
(  SELECT name, location, salary
FROM vicky.staff, vicky.org
WHERE staff.dept=org.deptnumb AND salary>20000
)  DATA INITIALLY DEFERRED REFRESH DEFERRED|IMMEDIATE
ENABLE|DISABLE QUERY OPTIMIZATION
REFRESH TABLE vicky.mqt1

利用MQT:
RUNSTATS ON TABLE vicky.mqt1
UPDATE DB CFG FOR sample USING DFT_REFRESH_AGE ANY

并行处理

设置并行处理:
UPDATE DBM CFG USING INTRA_PARALLEL YES
UPDATE DB CFG FOR EOS USING DFT_DEGREE ANY

并行处理上限:
应用级:
SET RUNTIME DEGREE FOR ( 25 ) TO 4
SET RUNTIME DEGREE FOR ALL TO 6
实例级:
UPDATE DBM CFG USING MAX_QUERYDEGREE 6


MDC表:
CREATE TABLE vicky.sales
( YearAndMonth CHAR(4),
Region CHAR(20),
Product CHAR(2),
Sales BIGINT
) ORGANIZE BY DIMENSIONS ( YearAndMonth, Region )
CREATE TABLE vicky.table1
( col1 CHAR(10),
col2 CHAR(10),
col3 CHAR(10),
col4 INTEGER,
col5 DECIMAL(10,2),
) ORGANIZE BY DIMENSIONS ( col1, ( col2, col3 ),col4 )

 

查看db2连接状况

db2 list application

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

H:\ibm_soft\ibm_tivoli\DB2_Enterprise_Server_Edition9.1\C7427NA_DB2_ESE_9_1_0_0_LNXX86_1.iso
H:\ibm_soft\ibm_tivoli\DB2_National_Language_Pack_v9.1\C752TNA_DB2_NLPACK_9_1_0_0_LNXX86_1.iso
==============================================================================================================
/root/db2ese.rsp
/opt/ibm/db2/V9.1
==============================================================================================================

DB2数据字典

http://ace-life.iteye.com/blog/1135426

每个数据库都有它自己的系统目录表和视图。它们存储关于数据对象的元数据。

你可以像使用普通的数据库表一样查询这些表。有三种模式用来识别系统目录表:
SYSIBM: 基本表, 对 DB2使用进行最优化
SYSCAT: 基于SYSIBM表的视图, 对平常轻负荷使用进行优化
SYSSTAT: 数据库分析

 

 db2 describe table SYSCAT.tables

 db2 "select bpname,npage from SYSCAT.bufferpolls"
 db2 connect to remall
 db2 "select bpname,npage from SYSCAT.bufferpolls"
 db2 describe table SYSCAT.bufferpools
 db2 "select BPNAME,NPAGES,PAGESIZE from SYSCAT.bufferpools"

IBM在数据库领域十件大事

http://www.db2china.net/club/viewthread.php?tid=1315

  1970: 这是数据库历史上划时代的一年,IBM 公司的研究员 E.F.Codd 发表了业界第一篇关于关系数据库理论的论文“A Relational Model of Data for Large Shared Data Banks”,首次提出了关系模型的概念。这篇论文是计算机科学史上最重要的论文之一,也奠定了 Codd 博士“关系数据库之父”的地位。
  1974: IBM 的研究员 Don Chamberlin 和 Ray Boyce 通过 System R 项目的实践,发表了论文“SEQUEL:A Structured English Query Language”。论文中提出的 SEQUEL 语言是一套比关系微积分与关系代数更适合最终用户使用的非程序化查询语言,我们现在所熟知的 SQL 语言就是基于它发展起来的。
  1983: 千呼万唤始出来,IBM 在这一年发布了DATABASE 2(DB2 )for MVS(内部代号为“Eagle”),一个长盛不衰的品牌就此出现了。
  1993: IBM 发布了DB2 for OS/2 V1(DB2 for OS/2 可以被简写为DB2/2)和DB2 for RS/6000 V1(DB2 for RS/6000 可以被简写为DB2/6000),这是 DB2 第一次在Intel 和Unix 平台上出现。
  1995: IBM 发布了 DB2 Common Server V2,这是第一个能够在多个平台上运行的对象—关系型数据库产品,并能够对 Web 提供充分支持。DataJoiner for AIX 也诞生在这一年,该产品赋予了 DB2 对异构数据库的支持能力。
  1996: IBM将DB2更名为 DB2 通用数据库(DB2 Universal Database),这是第一个能够对多媒体和 Web 进行支持的关系型数据库管理系统。该系统具有很好的伸缩性,可以从桌面系统扩展到大型企业,适应单处理器、 SMP 和 MPP 计算环境,并可以运行在所有主流操作系统 和硬件平台上。DB2 V5 是以前的两个产品的合并:DB2 Common Server V 2.1.2 和 DB2 并行版 1.2。
  1998: IBM 发布了 DB2 OLAP Server,这是一个基于 DB2 的完整的 OLAP 解决方案。这个产品是和 Arbor Software(Hyperion的前身)合作开发的。
  2000: IBM 启动了数据库管理工具业务,起初着重于为主机上的 IMS 和 DB2 提供高效管理工具,最终这项业务扩展到 UNIX、Linux 和 Windows 平台。Informix 数据库产品也在支持之列。
  2001: IBM 以 10 亿美金收购了 Informix 的数据库业务,这次收购扩大了 IBM 的分布式数据库业务。
  2003 (to May 15): IBM 将数据管理产品统一更名为信息管理产品。
  2008: IBM将发布基于XML 的下一代数据库,以开创数据库技术的新纪元。

 

AIX DB2 数据库快照分析过程 transfer.rar

http://dl.iteye.com/topics/download/8992d238-25fd-3ca7-8649-e044768b1b63

$ oslevel -r
6100-04

// 分析数据快照文件dynsql_201206201.out , 如何抓数据库快照(略)

$ perl transfer.pl dynsql_201206201.out

#Transfer snapshot.txt to stmt.txt
use strict;
use IO::File;
use Time::Local;
#Open the snapshot.txt
unless (open(FILE1,$ARGV[0])){
die ("Please enter the snapshot.txt\n");
}
my $date;
my $line;
my @array;
my $NumberExecutions;
my $NumberCompilations;
my $WorstPreparation;
my $BestPreparation;
my $TotalExecutionTime;
my $InternalRowsDeleted;
my $InternalRowsInserted;
my $InternalRowsupdated;
my $StatementText;
my $Statementsorts;
my $Statementsortoverflows;
my $Totalsorttime;
my $Rowsread;
my $AverageRowRead;
my $Rowswritten;
my $AverageRowSelect;
my $BPDLR;
my $BPDPR;
my $BPILR;
my $BPIPR;
my $BPTDLR;
my $BPTDPR;
my $BPTILR;
my $BPTIPR;
my $BPRatio;
my $flag = 0;
my $position;
my $AverageTime;
my $TUsrTm;
my $TSysTm;


#Show start time.
$date=localtime(time);
print "Start from ".$date;

#Write the tag to the txt.
open (OUTFILE, ">>transfer.txt");
print OUTFILE (" NumEx;NumComp;WorstP;BestP;IntRDel;IntRIns;RowsRead;IntRUpd;RowsWri;Sorts;SortOflo;TSortTm;BPDLR;BPDPR;BPTDLR;BPTDPR;BPILR;BPIPR;BPTILR;BPTIPR;TELapTm;TUsrTm;TSysTm;AvgElap;AverageRowRead;AverageRowSelect;BPRatio;Text;\n");

#Close the file handle.
close(OUTFILE);
print("\nBegin to transfer,please wait!\n");

#Read the data from snapshot.txt.
while($line = <FILE1>)
{
	if($line=~/Number\sof\sexecutions/){
		$NumberExecutions=$line;
		$position=index($NumberExecutions,"=");
		$NumberExecutions=substr($NumberExecutions,$position+1,);	
		if($NumberExecutions=~/\s0.*\s/){
			$flag=1;
			$NumberExecutions="";
			next;
		}else{	
			
			$flag=2;
			#print $NumberExecutions;
		}
		$NumberExecutions=~s/\s//g;
	}
	if($line=~/Number\sof\scompilations/ && $flag==2){
		$NumberCompilations=$line;
		$position=index($NumberCompilations,"=");
		$NumberCompilations=substr($NumberCompilations,$position+1,);
		$NumberCompilations=~s/\s//g;
		#print $NumberCompilations;
	}	
	if($line=~/Worst\spreparation\stime/ && $flag==2){
		$WorstPreparation=$line;
		$position=index($WorstPreparation,"=");
		$WorstPreparation=substr($WorstPreparation,$position+1,);
		$WorstPreparation=~s/\s//g;
		#print $WorstPreparation;
	}
	if($line=~/Best\spreparation\stime/ && $flag==2){
		$BestPreparation=$line;
		$position=index($BestPreparation,"=");
		$BestPreparation=substr($BestPreparation,$position+1,);
		$BestPreparation=~s/\s//g;
		#print $BestPreparation;
	}
	if($line=~/Internal\srows\sdelete/ && $flag==2){
		$InternalRowsDeleted=$line;
		$position=index($InternalRowsDeleted,"=");
		$InternalRowsDeleted=substr($InternalRowsDeleted,$position+1,);
		$InternalRowsDeleted=~s/\s//g;
		#print $InternalRowsDeleted;
	}
	if($line=~/Internal\srows\supdated/ && $flag==2){
		$InternalRowsupdated=$line;
		$position=index($InternalRowsupdated,"=");
		$InternalRowsupdated=substr($InternalRowsupdated,$position+1,);
		$InternalRowsupdated=~s/\s//g;
		#print $InternalRowsupdated;
	}
	if($line=~/Internal\srows\sinserted/ && $flag==2){
		$InternalRowsInserted=$line;
		$position=index($InternalRowsInserted,"=");
		$InternalRowsInserted=substr($InternalRowsInserted,$position+1,);
		$InternalRowsInserted=~s/\s//g;
		#print $InternalRowsInserted;
	}
	if($line=~/Statement\ssorts/ && $flag==2){
		$Statementsorts=$line;
		$position=index($Statementsorts,"=");
		$Statementsorts=substr($Statementsorts,$position+1,);
		$Statementsorts=~s/\s//g;
		#print $Statementsorts;
	}
	if($line=~/Statement\ssort\soverflows/ && $flag==2){
		$Statementsortoverflows=$line;
		$position=index($Statementsortoverflows,"=");
		$Statementsortoverflows=substr($Statementsortoverflows,$position+1,);
		$Statementsortoverflows=~s/\s//g;
		#print $Statementsortoverflows;
	}
	if($line=~/Total\ssort\stime/ && $flag==2){
		$Totalsorttime=$line;
		$position=index($Totalsorttime,"=");
		$Totalsorttime=substr($Totalsorttime,$position+1,);
		$Totalsorttime=~s/\s//g;
		#print $Totalsorttime;
	}
	if($line=~/Total\sexecution\stime/ && $flag==2){
		$TotalExecutionTime=$line;	
		$position=index($TotalExecutionTime,"=");
		$TotalExecutionTime=substr($TotalExecutionTime,$position+1,);
		$TotalExecutionTime=~s/\s//g;
		#print $TotalExecutionTime;
	}
	if($line=~/Rows\sread/ && $flag==2){
		$Rowsread=$line;	
		$position=index($Rowsread,"=");
		$Rowsread=substr($Rowsread,$position+1,);
		$Rowsread=~s/\s//g;
		#print $Rowsread;
	}
	if($line=~/Rows\swritten/ && $flag==2){
		$Rowswritten=$line;	
		$position=index($Rowswritten,"=");
		$Rowswritten=substr($Rowswritten,$position+1,);
		$Rowswritten=~s/\s//g;
		#print $Rowswritten;
	}
	if($line=~/Buffer\spool\sdata\slogical\sreads/ && $flag==2){
		$BPDLR=$line;	
		$position=index($BPDLR,"=");
		$BPDLR=substr($BPDLR,$position+1,);
		$BPDLR=~s/\s//g;
		#print $BPDLR;
	}
	if($line=~/Buffer\spool\stemporary\sdata\slogical\sreads/ && $flag==2){
		$BPTDLR=$line;	
		$position=index($BPTDLR,"=");
		$BPTDLR=substr($BPTDLR,$position+1,);
		$BPTDLR=~s/\s//g;
		#print $BPTDLR;
	}
	if($line=~/Buffer\spool\sdata\sphysical\sreads/ && $flag==2){
		$BPDPR=$line;	
		$position=index($BPDPR,"=");
		$BPDPR=substr($BPDPR,$position+1,);
		$BPDPR=~s/\s//g;
		#print $BPDPR;
	}
	if($line=~/Buffer\spool\stemporary\sdata\sphysical\sreads/ && $flag==2){
		$BPTDPR=$line;	
		$position=index($BPTDPR,"=");
		$BPTDPR=substr($BPTDPR,$position+1,);
		$BPTDPR=~s/\s//g;
		#print $BPTDPR;
	}
	if($line=~/Buffer\spool\sindex\slogical\sreads/ && $flag==2){
		$BPILR=$line;	
		$position=index($BPILR,"=");
		$BPILR=substr($BPILR,$position+1,);
		$BPILR=~s/\s//g;
		#print $BPILR;
	}
	if($line=~/Buffer\spool\stemporary\sindex\slogical\sreads/ && $flag==2){
		$BPTILR=$line;	
		$position=index($BPTILR,"=");
		$BPTILR=substr($BPTILR,$position+1,);
		$BPTILR=~s/\s//g;
		#print $BPTILR;
	}
	if($line=~/Buffer\spool\sindex\sphysical\sreads/ && $flag==2){
		$BPIPR=$line;	
		$position=index($BPIPR,"=");
		$BPIPR=substr($BPIPR,$position+1,);
		$BPIPR=~s/\s//g;
		#print $BPIPR;
	}
	if($line=~/Buffer\spool\stemporary\sindex\sphysical\sreads/ && $flag==2){
		$BPTIPR=$line;	
		$position=index($BPTIPR,"=");
		$BPTIPR=substr($BPTIPR,$position+1,);
		$BPTIPR=~s/\s//g;
		#print $BPTIPR;
	}
        if($line=~/Total\suser\scpu\stime/ && $flag==2){
		$TUsrTm=$line;	
		$position=index($TUsrTm,"=");
		$TUsrTm=substr($TUsrTm,$position+1,);
		$TUsrTm=~s/\s//g;
		#print $TUsrTm;
	}
        if($line=~/Total\ssystem\scpu\stime/ && $flag==2){
		$TSysTm=$line;	
		$position=index($TSysTm,"=");
		$TSysTm=substr($TSysTm,$position+1,);
		$TSysTm=~s/\s//g;
		#print $TSysTm;
	}	
	if($line=~/Statement\stext/ && $flag==2){
		$StatementText=$line;
		$position=index($StatementText,"=");
		$StatementText=substr($StatementText,$position+1,);
		#print $StatementText;
	}
	else{
		next;
	}
	if($flag==2){
	$AverageTime=sprintf("%.15f", ($TotalExecutionTime)/($NumberExecutions));
	$AverageRowRead=sprintf("%.5f", ($Rowsread)/($NumberExecutions));
		if($Rowsread==" 0"||$Rowswritten==" 0"){
			$AverageRowSelect=0;
		}else{
			$AverageRowSelect=sprintf("%.5f", ($Rowswritten)/($Rowsread));
		}
		if(($BPDLR+$BPILR)==0||($BPIPR+$BPDPR)==0){
			$BPRatio=100;
		}else{
			$BPRatio = (1-($BPIPR+$BPDPR)/($BPDLR+$BPILR))*100;
		}
	open (OUTFILE, ">>transfer.txt");
	print OUTFILE ($NumberExecutions.";".$NumberCompilations.";".$WorstPreparation.";".$BestPreparation.";".$InternalRowsDeleted.";".$InternalRowsInserted.";".$Rowsread.";".$InternalRowsupdated.";".$Rowswritten.";".$Statementsorts.";".$Statementsortoverflows.";".$Totalsorttime.";".$BPDLR.";".$BPDPR.";".$BPTDLR.";".$BPTDPR.";".$BPILR.";".$BPIPR.";".$BPTILR.";".$BPTIPR.";".$TotalExecutionTime.";".$TUsrTm.";".$TSysTm.";".$AverageTime.";".$AverageRowRead.";".$AverageRowSelect.";".$BPRatio.";".$StatementText);

	$StatementText="";
	$TotalExecutionTime="";
	$NumberExecutions="";
	$Statementsorts="";
	$Statementsortoverflows="";
	$Totalsorttime="";
	$TUsrTm="";
	$TSysTm="";
	}
}

#Show end time.
$date=localtime(time);
print "End at ".$date;

#Close the file handle.
close(OUTFILE);
close(FILE1)

 

$ ls -l  dynsql_201206201.txt

// 用excel 排序 dynsql_201206201.txt 即可得出数据库中消耗最大的sql

 

end

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics