db2top监控最慢sql语句
db2常用sql语句

授权
grant dbadm on database to user bb
24.
列出所有的系统表
list tables for system
25.
查看表结构
db2 describe select * from user.tables
27.
导出单个表结构到一个文件
db2look -d masa -e -u MASAMK -a -t PSC_MODE_SCORE_200503 -o aa.out
CONFIG PARTITIONING_DBPARTNUMS(0,1,2,3)
装载语句:(消息文件)
load client FROM /export/masaetl/work/data/org_data/cond.avl \
of DEL MODIFIED BY COLDEL0x09 MESSAGES /export/masaetl/111 \
db2 force application ID1,ID2,,,Idn MODE ASYNC
(db2 list application for db o_yd show detail)
16.
备份数据库
db2 force application all
db2 backup db o_yd to d:
10.
连接数据库
db2 connect to o_yd user db2 using pwd
11.
读数据库管理程序配置
db2 get dbm cfg
12.
写数据库管理程序配置
db2 update dbm cfg using 参数名 参数值
db2常用SQL语句详解

常用SQL语句详解到今天为止,人们对关系数据库做了大量的研究,并开发出关系数据语言,为操作关系数据库提供了方便的用户接口。
关系数据语言目前有几十种,具有增加、删除、修改、查询、数据定义与控制等完整的数据库操作功能。
通常把它们分为两类:关系代数类和关系演算类。
在这些语言中,结构化查询语言SQL以其强大的数据库操作功能、口语化、易学易用等特点,受到广泛的应用,成为数据库应用程序开发的一柄利剑。
在数据库应用程序开发过程中,巧妙地使用SQL语句,可以简化编程,起到事半功倍的效果,本书中有些实例也大量使用了SQL语句。
它由两部分组成,数据定义语言(DDL)和数据操作语言(DML)。
(1) 数据定义语言(DDL)数据定义语言用来定义数据库的各级模式。
常用关键字有:Create(建立数据表)、Alter(更改数据表)、Drop(删除数据表)。
建立数据表CREATE TABLE table_name(column1 DATATYPE [NOT NULL] [NOT NULL PRIMARY KEY],column2 DATATYPE [NOT NULL],...)说明:上面的DATATYPE 指的是字段的类型,NUT NULL 指是否为空,PRIMARY KEY 指本表的主键。
建立索引CREATE INDEX index_name ON table_name (column_name)说明:为数据表格的某个字段建立索引以增加查询时的速度。
更改数据表ALTER TABLE table_name ADD COLUMN column_name DATATYPE说明:增加一个字段。
ALTER TABLE table_name ADD PRIMARY KEY (column_name)说明:将某个字段设为主键。
ALTER TABLE table_name DROP PRIMARY KEY (column_name)说明:将某个字段的主键定义取消。
DB2数据库-性能测试监控

建议:根据表的大小设置不同规格(4k、8k、16k、32k)的表空间,将表空间设置为自动增长的方式。
锁配置信息查看
Db2 get db cfg |grep–ilock
获取LOCKTIMEOUT这项指标的值,若为-1表示锁永远不会超时。
当前的应用系统主要分为两类:联机事务处理(OLTP)和联机分析处理(OLAP)。OLTP主要执行日常的事务处理,比如银行存取款、商场购物等,它的主要特点是对响应时间要求高,数据量一般较小,并发多,面向应用。OLAP主要指数据仓库、决策分析类系统,主要特点是数据量大,对实时性要求不高,面向主题。
针对这两种典型的系统,DB2提供了很好的支持。对于OLTP系统和数据量较小的OLAP系统,可以采用单分区架构。
数据库排序溢出总次数
SQL_Current
数据库当前执行的SQL语句
Tb_scan
数据库全表扫描的情况
Num_SQ_execut
执行次数较多的SQL
Package_Cache_Ratio
包缓存命中率
LOCK_SQL
造成数据库锁的SQL
Hight_CPU_TIME_SQL
最消耗系统资源的SQL
四
根据DB2监控指标中列出的指标名称,按测试指南指标、其他常用指标逐一给出详细的监控方法。
Db2wdong
DB2的看门狗,是db2sysc的父进程。如果db2sysc集成非正常终止,它将清除所占用的资源。
Db2vend
在主进程之外的围栏进程,所有db29.5的第三方代码都在这个进程中运行。
Db2fmp
围栏进程,在防火墙外运行用户的存储程序和用户定义函数代码。此进程代替了db2老版本中的db2udf和db2dari进程。
常用的SQL语句

Company
Area
汉能A
北京
汉能B
禹城
汉能C 汉能D
四川 江苏
执行结果
Update
Update 语句用于修改表中的数据。
语法: UPDATE 表名称 SET 列名称 = 新值 WHERE 列名称 = 某值 例如: 将表A中的Area列的是川更新为四川
Id Company
Area
1 汉能A
北京
2 汉能B 3 汉能C
显示一条记录。
Id Company
Area Production
ቤተ መጻሕፍቲ ባይዱIntFlag
1 汉能A
北京 200W
1
表:A
2 汉能C
禹城 250W
1
3 汉能C
禹城 300W
0
SELECT * FROM A WHERE (company=‘汉能A’ OR company=‘汉能C') AND IntFlag=‘1'
✓CREATE INDEX 语法 在表上创建一个简单的索引。允许使用重复的值: CREATE INDEX 索引名称 ON 表名(列名)
例如对表A中的列A_a创建可重复的索引 create index index_name on A (A_a)
✓ CREATE UNIQUE INDEX 语法 在表上创建一个唯一的索引。唯一的索引意味着两个行不能拥有相同 的索引值。索引名称 ON CREATE UNIQUE INDEX 表名(列名,列名)
用于创建数据库中的表
CREATE TABLE 创建表语法 CREATE TABLE 表名称 ( 列名称1 数据类型, 列名称2 数据类型, 列名称3 数据类型, .... )
db2top

DB2TOP(1) User Manuals DB2TOP(1)NAMEdb2top − DB2 performance monitorSYNOPSISdb2top [−d dbname] [−n nodename] [−u username] [−p passÂ-word] [−V schema] [−i interval] [−P<partition> ] [−boption] [−a] [−B] [−k] [−R] [−x] [−f file</HH:MM:SS><+offset> ] [−D delimiter] [−C<option>] [−m duration] [−ooutfile]db2top [−H host ] [−N port ] [−h]DESCRIPTIONdb2top is a monitor for DB2 UDB specifically designed for DPF environments. It provides a unified, ’single system view’ of a multi−partition DB2 database that can be used to quickly identify either partition−specific or global problems in the system.The user interface is character−based and built using the curses library and is similar in nature to many UNIX moniÂ- toring utilities.db2top uses the DB2 snapshot monitoring APIs to retrieve data. It uses both global as well as partition−specific monitoring information to provide aggregation as well as quick drill−down capabilities.It can be run interactively or in batch mode. Main feaÂ- tures can be selected by an interactive command or by specifying the option in the personal or system−wide conÂ- figuration file. See below .db2toprc for more information.COMMAND OPTIONS−n specifies the node to attach to.−d specifies the database to monitor.−u specifies the DB2 username used to access the database.−p specifies the DB2 password.−V specifies the default schema used in explains.−i specifies the delay between screen updates.−k specifies whether to display actual or delta values.−R Reset snapshot at startup.−P <number>. Snapshot issued on current or partition numÂ-ber.−x specifies whether to display additionnal counters on session snd appl creens (might run slower on session).−b tells db2top to run in background mode.−a specifies only active queries will be displayed.−B enable bold for active objects.−C Runs db2top in snapshot collector mode, raw snapshot data is saved in <db2snap−Machine>.bin> by default (unless −f is specified).−f <file> </HH:MM:SS> <+offset>. Run db2top in replay mode when snapshot data has been previously collected in <file>. offset will jump to a certain point in time in the file. It can be expressed in seconds (+10s), minutes (+10m) or hours (+10h). /HH:MM:SS will skip entries until the specified point in time.−m Will limit duration of db2top in minutes for −b and −C.−o <outfile>. Outfile for −b option.−D <delimiter>. Separator for −b option.−h short help. When using the −b option, db2top will display information in CSV format. db2top can be run in background mode in combination with reading snapshot data from collection file, in this case, use the −f <file> option. Valid sub− options for −b and −C are :d : databasel : sessionst : tablespacesb : bufferpoolsT : TablesD : Dynamic SQLs : StatementsU : Locksu : UtilitiesF : Federationm : Memory poolsWhen using the −X switch with the −b option, the output will be displayed in XML format. When using the −L switch with the −b option, in session mode (sub−option l), all queries will be written to ’ALL.sql’. When using the −A switch with the −b option, db2top will produce a top twenty performance report. When using the −s <sample> switch with the −b option, db2top will only display n samÂ-ples and exit.Interactive commandsd Goto database screen.l Goto sessions screen.a Goto application details for agent (or restrict on agent on statement screen). db2top will prompt for the agent−id.G Toggle between all partitions and current partitions.P Select db partition on which to issue snapshot.t Goto tablespaces screen.T Goto tables screen.b Goto bufferpools screen.D Goto the dynamic SQL screen.m Display memory pools.s Goto the statements screen.U Goto the locks screen.p Goto the partitions screen.u Goto the utilities screen.A Goto the HADR screen.F Goto the federation screen.B Goto the bottleneck analysis screen.H Goto the history screen (experimental).f Freeze screen.W Watch mode for agent_id, os_user, db_user, applicaÂ-^HÂ-tion or netname. Statements returned by the sessionsnapshot (option l) will be written to agent.sql, os_user−agent.sql, db_user−agent.sql, application−agent.sql or netname−agent.sql. The Dump DB Structfield will create scripts in the current directory torecreate the database. When issued from the dynamicSQL screen (option D), statements will be written to db2adv.sql in a format compatible with db2advis./ Enter expression to filter data. \Expression mustconform to regular expression. Each function (screen)can be filtered differently. regexp check is applyiedto the whole row.<|> Move to left or right of screen.z|Z Sort on ascending or descending order.c This option allows to change the order of the columnsdisplayed on the screen. The syntax is in the form:1,2,3,... where 1,2,3 correspond respectively to the1st, 2nd and 3rd columns displayed. These are thecolumn numbers to use when specifying a sort criteÂ-ria.S Run native DB2 snapshot.L Allows to display the complete query text from the SQL screen. Regular DB2 explain can then be run usinge or X.R Reset snapshot data.i Toggle idle sessions on/off.I Reset refresh interval.k Toggle actual vs delta values.g Toggle graph on/off.X Toggle extended mode on/off.C Toggle snapshot data collector on/off.V Set default explains schema.O Display session setup.w Write session settings to .db2toprc.q Quit db2top.Interactive commands(applications screen only)r Return to previous function.R Toggle automatic refresh.g Toggle graph on/off.X Toggle extended mode on/off.d Display agents.Snapshot data collectordb2top can be run in replay mode, which means it can be run against a saved copy of the raw binary snapshot data. In order to do so, db2top must be run first in data colÂ- lector mode, either in batch mode by running db2top from the command line with the [−C] switch, or by activatÂ- ing/deactivating data collection from an interactive sesÂ- sion by pressing C. This will create a file <db2snap−Machine> in the current directory. Afterwards, db2top can be ran against <db2snap−Machine> by using the [−f <db2snap−Machine> arguments. db2top does not need to attach to DB2 in replay mode, which makes convenient to do remote monitoring. It is possible to limit the content of the stream file (and it’s size) by specifying any of the suboptions dltbTDsUF.Network data collector(EXPERIMENTAL)db2top can be run in client/server mode. This means that one instance of db2top can issue DB2 snapshots in data collection mode and send the output stream via the network to other instances of db2top. To enable this, db2top needs to be started in collection mode with −C and −N (network). Eventually, the −D will set db2top to daemon mode; in this case, messages are sent to syslog(3). Then, other instances of db2top will connect to the server using the −H [host] and −N <port> switchs.Network commands−−stop, −−restart,−−ping.FILESdb2toprc.db2toprc is a configuration file used to setup parameters at initialization time. db2top will search for the location of .db2toprc using the environement variable $DB2TOPRC. If the variable is not set, db2top will then search for .db2toprc in the current directory and finally in the home directory.ENVIRONMENTDB2TOPRCsee above.DB2DBDFTIf non null and nothing has been specified on the command line or in .db2toprc, db2top will honor the DB2DBDFT registry variable content as the default database.EDITORif EDITOR is set, results of explain or native snapshots will be displayed using this command, otherwise, it will default to vi(1).db2toprc structureSectionsThe various sections of $DB2TOPRC are described here after.cpu=commandThis entry allows the user to specify a comÂ- mand which result will be displayed on the 2nd line at the right of the screen, for example:cpu=vmstat 2 2 | tail −1 | awk’{printf("%d(usr+sys)",$14+$15);}’will display ’Cpu=2(usr+sys)’ on the right ofthe screen.io=commandThis entry allows the user to specify a comÂ-mand which result will be displayed on the 2ndline at the left of the screen, for example:io=vmstat 2 2 | tail −1 | awk’{printf("%d(bi+bo)",$10+$11);}’will display ’Disk=76(bi+bo)’ on the right ofthe screen.Both commands are run in a background process andthe fields on the screen are updated asynÂ-chronously.shell alias=commandThe shell entry allows to specify a userdefined command, for example:shell M=topwill spawn top from a db2top session whenentering M. It will return to the currentscreen upon exit.function alias=commandThe function entry allows to specify a userdefined command, for example:function N=netstatwill create a new function called N that willdisplay repeteadly the output of netstat.Sample.db2toprc file## db2top configuration file# On unix, should be located in $HOME/.db2toprc# File generated by db2top−1.0h#node= # [−n] nodenamedatabase=sample # [−d] databasenameuser= # [−u] database userpassword= # [−p] user password (crypted )schema= # [−V] default schema for exp lainsinterval=2 # [−i] sampling intervalactive=OFF # [−a] display active session s only (on/off)reset=OFF # [−R] Reset snapshot at star tup (on/off)delta=ON # [−k] Toggle display of delt a/cumulative values (on/off)graphic=ON # True if terminal suppo rts semi graphical characterscolors=ON # True if terminal suppo rts colorsgraph=ON # display graph on sessi ons list (on/off)port= # Port for network colle ctionstreamsize=size # Max collection size pe r hour (eg. 1024 or 1K : K, M or G)# Command to get cpu usage information from OScpu=vmstat 2 2 | tail −1 | awk ’{printf("%d(usr+sys)0,$14+$15 );}’# Command to get IO usage information from OSio=vmstat 2 2 | tail −1 | awk ’{printf("%d(bi+bo)0,$10+$11);}’# Ordering of information in sessions screensessions=0,1,18,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,19,20 ,21,22,23tables=0,1,2,4,3,5,6,7tablespaces=0,1,18,2,3,4,5,6,7,8bufferpools=0,1,18,2,3,4,5,6,7,8,9,10dynsql=0,1,18,2,3,4,5,6,7,8,9statements=0,1locks=0,1utilities=0federation=0,2,4# User defined commandsshell P=topfunction N=date && netstat −t tcpThe columns order screenAfter pressing c, a screen will be shown specifying theorder of the columns displayed on screen. The left partof the sceen displays the default order and column numberswhereas the right part displays the current ordering. Tochange the order of the columns, enter in the text fieldat the bottom of the screen the new column order : enterthe relative column positions as displayed on the leftseperated by comma. Not all columns need to be specified.This column ordering can be saved in $DB2TOPRC for subseÂ-quent db2top sessions by pressing w. It is possibile todefine the default sort order for this function by usingthe sort=num<a|d> syntax, where num is the column numberand <a|d> means ascending or descending.Example : tablespaces=0,1,18,2,3,4,5,6,7,8,sort=22aValid keywords for column ordering in db2toprc.sessions=tablespaces=tables=bufferpools=dynsql=statements=locks=utilities=federation=BUGSOccasionally strange information may appear when the snapÂ-shot API returns unexpected very large values. db2top willtry to display * instead of these values.COPYRIGHT Licensed Materials − Property of IBM Copyright IBM Corp. 2005 All Rights Reserved. US Government Users Restricted Rights Use, duplication or disclosure restricted by GSA ADP Schedule Contract wi th IBM Corp.IBM/DB2 JANUARY 2005 DB2TOP(1)Nov 10, 06 22:48Page 7/7db2top Printed by db2inst2。
Linux系统重启db2数据库命令实例详解

Linux系统重启db2数据库命令实例详解Linux系统中db2数据库的启动关闭可以通过命令来实现。
下面由店铺为大家整理了Linux系统重启db2数据库命令实例详解,希望对大家有帮助!Linux系统重启db2数据库命令实例详解DB2重启数据库实例时,有时停止实例会失败,此时需要先确认没有应用链接数据库,然后再关闭数据库实例,并重新启动。
1.查看是否有活动的链接命令:db2 list applications for db db_name发现有两个活动链接,此时需要将链接进行关闭。
2.关闭连接命令:db2 force application all3.再执行一次步骤1中的命令,查看链接是否全部关闭。
4.执行停止实例命令命令:db2stop注意:命令中没有空格5.执行实例启动命令命令:db2start6.如果此时,发现连接不了数据库,莫慌,需要激活目标数据库首先查看是否有活跃的数据库命令:db2 list active databases如果没有,需要对目标数据库进行激活设置命令:db2 activate database db_name然后再次使用上一条命令,就可查看到当前已有活跃的数据库了,此时可进行连接并执行数据库操作。
在停止数据库实例失败时,也有一种直接迅速的方法可以停止实例,不过不建议使用,最好还是按照上述的步骤进行。
快速方法执行命令:db2stop forceLinux系统db2数据库常用命令启动数据库:启动db2服务:db2start激活数据库实例:db2 activate database <db_name>查看激活状态的数据库:db2 list active databases关闭数据库:失效数据库实例:db2 deactivate database <db_name>关闭数据库服务:db2stop查看数据库:db2 list db directory查看数据库应用:db2 list applications查看数据库应用和进程号:db2 list applications show detail查看数据库表空间:db2pd -db <db_name> -tablespace查看数据库配置:db2 get db cfg for <db_name>连接数据库:db2 connect to <db_name>db2 connect to <db_name> user[user_name] using [password]断开数据库连接:db2 connect reset/db2 terminate创建数据库:db2 create db <db_name>删除数据库:db2 drop database <db_name> (如果不能删除,尝试断开激活的连接或者重启db2)列出系统表:db2 list tables for system列出所有用户表:db2 list tables列出所有表:db2 list tables for all列出特定用户表:db2 list tables for schema [user]复制一张表:db2 create table t1 like t2显示表结构:db2 describe table tablename查询表:db2 "select * from table tablename where ..."执行SQL脚本:db2 -tvf scripts.sql查看错误代码信息:db2 ? 10054停止激活的连接:db2 force application all;\db2 forceapplication all;\db2 force application all;\db2stop查看死锁: db2 get snapshot for locks on <db_name>db2 "select agent_id,tabname,lock_mode from table(snap_get_lock('<db_name>')) as aa"杀掉进程: db2 force application(NUM)监控DB2消耗多的SQL语句:eg:(DB_NAME=CMSDB)db2top -d CMSDB -----查看消耗资源按照提示按l,出现Application Handle,找到资源消耗大的Application Handle(stat) 记下app handle。
db2日常运维常用CLP命令和SQL语句

=============================================================== ===========================================================系统命令=========================================================================================================== ========================也就是直接在db2环境变量下直接敲就可以的,这些命令都可以再产品目录下找到●db2le vel 查看数据库版本●db2ilis t 查看实例●d b2icr t -aSERVE R -sese -p db2c_bnd8inst -ubnd8f enc b nd8in st 创建实例●d b2idr op xx inst删除实例●db2s tart启动数据库实例(数据库跟随实例启动,不能单独关闭和启动数据库)●db2st op 关闭数据库实例●d b2sto p for ce 强制停止●d b2iau to -o n tes tinst系统启动实例自动启动●db2iauto -off test inst系统启动实例不自动启动●db2samp l 创建例库●db2tbst十六进制状态码可以显示表空间状态●db2mo ve db nameexpor t 备份数据●db2move dbna me im port恢复数据●db2ck bkp -h BTA DB.0.btain st.NO DE0000.CAT N0000.20120206132720.001查看数据库备份。
db2数据库面试题

db2数据库面试题一、概述DB2数据库是IBM公司开发的一种关系型数据库管理系统。
在DB2数据库的面试过程中,常常会遇到各种各样的问题。
本文将为您总结一些常见的DB2数据库面试题,帮助您更好地准备面试,并提供详细的解答。
本文将从DB2数据库的基本知识、SQL查询、性能调优等方面展开讨论。
二、基本知识1. 什么是DB2数据库?DB2数据库是IBM开发的一种关系型数据库管理系统,它提供了完整的数据库管理和数据操作功能,并支持SQL查询语言。
2. DB2数据库的特点是什么?DB2数据库具有以下特点:- 跨平台性:DB2可以在不同的操作系统和平台上运行,如Windows、Unix、Linux等。
- 具备高可用性:DB2支持数据备份、恢复和高可用性机制,确保数据的安全性和可靠性。
- 扩展能力强:DB2可以支持大规模的数据和用户,并提供有效的扩展机制。
- 性能优越:DB2采用了先进的查询优化技术,能够提供高效的数据检索和处理能力。
- 安全性强:DB2提供了完善的权限管理和安全机制,保证数据的机密性和完整性。
3. DB2数据库的体系结构是什么样的?DB2数据库的体系结构包括以下几个层次:- 应用层:应用程序通过数据库连接器与DB2数据库进行通信。
- SQL层:处理SQL查询,包括查询优化、执行计划生成等。
- 缓冲池管理器(Buffer Pool Manager):管理数据缓存和页面置换。
- 存储管理器(Storage Manager):管理数据的存储和检索。
- 锁管理器(Lock Manager):管理并发访问和资源锁定。
- 日志管理器(Log Manager):管理事务日志的生成和恢复。
4. DB2数据库的对象包括哪些?DB2数据库的主要对象包括表(Table)、视图(View)、索引(Index)、触发器(Trigger)、存储过程(Stored Procedure)等。
三、SQL查询1. 如何创建一个表?在DB2数据库中,可以使用CREATE TABLE语句来创建一个表,语法如下:CREATE TABLE table_name (column1 datatype1 constraint,column2 datatype2 constraint,...);其中,table_name为表名,column1、column2为列名,datatype1、datatype2为列的数据类型,constraint为列的约束条件(如主键、外键等)。