DB2系统级命令及实例级命令

 系统级命令:

 1、dasauto

在$DB2DIR/das/adm目录下,设置DAS是否自启动状态。dasauto [-h|-?] -on|-off。
如果在inittab文件中不禁止db2fmcd进程,上面设置无效,因为dbfmcd进程会启动db2fmd,db2fmd在一定周期内启动DAS。

 2、dascrt

创建DAS,DAS是为控制中心和配置助手服务,在$DB2DIR/instance目录下,dascrt -u dasusr1
在window平台,可以使用db2admin create命令创建

3、dasdrop

删除DAS,在$DB2DIR/instance目录下
在window平台,可以使用db2admin drop命令删除

4、dasmigr

如果数据库移植,可以用该命令移植DAS与它关联,如果是同版本数据库移植,还需要dasupdt命令更新DAS。在$DB2DIR/instance目录下

5、dasupdt

更新DAS。在$DB2DIR/instance目录下

6、db2_deinstall

命令在安装软件下,卸载DB2产品或某个组件,卸载组件:db2_deinstall -F feature_name,全部卸载:db2_deinstall -a

7、db2_install

命令在安装软件下,安装DB2产品

8、db2audit

db2audit.cfg和db2audit.log文件都在sqllib/security目录下,是非文本文件。如果是缺省配置,通过日志可以看到访问数据库的IP及用户。
db2audit describe #查看审计配置
db2audit extract file audit.rpt #根据审计日志生成可读的审计报告
db2audit prune all #清除所有审计日志
db2audit stop #关闭审计功能
db2audit start #启动审计功能

9、db2batch

基准测试工具,批处理计算每个sql文的成本。
db2batch -d testdb -a db2inst1/123456 -f bt.sql -r ret.rpt
bt.sql文件内容:
create table tbbatch(c1 int);
insert into tbbatch values(2);
update tbbatch set c1=8 where c1=2;
delete from tbbatch;
drop table tbbatch;
ret.rpt文件内容:
Statement number: 1
create table tbbatch(c1 int)
Elapsed Time is: 0.091 seconds
Statement number: 2
insert into tbbatch values(2)
Elapsed Time is: 0.034 seconds
……..

10、db2cat

输出系统字典信息
db2cat -s shen -d testdb -n tblareacode -p table -o cat.rpt #输出testdb库shen用户的tblareacode表格字典数据

11、db2cfexp

数据库连接配置导出工具,文件内容包括:注册变量、DBM配置参数、NODE配置、DB配置
命令:db2cfexp cfg.prf backup

12、db2cfimp

数据库连接配置导入工具

13、db2ckbkp

检查数据库备份映像的完整性。
db2ckbkp -a testdb.0.db2inst1.NODE0000.CATN0000.20071023164120.001 >chk.rpt

14、db2dart - Database analysis and reporting tool

检查数据库结构的正确性。
db2dart sample

15、db2diag - db2diag.log analysis tool

db2日志诊断文件分析工具。
db2diag -g level=Severe

16、db2drdat - DRDA trace

跟踪DRDA通信。
db2drdat on #首先打开trace,也可以指定trace buffer大小
db2drdat off -t=abc.dmp[如果不指定缺省是db2drdat.dmp] #关闭trace,将trace buffer内容写入abc.dmp

17、db2empfa - Enable multipage file allocation(MPFA)

使SMS表空间的文件空间扩展时,扩展一个extent而不是一个page。创建数据库时,缺省MPFA enable,不可以修改为disable。如果注册变量DB2_NO_MPFA_FOR_NEW_DB=YES,创建数据库时,就是MPFA disable。

18、db2expln - SQL and XQuery Explain

生成sql文执行计划。-u后面跟用户名和密码,-t输出到console
db2expln -d testdb -u shen shen -q “select * from tblAreaCode” -t
db2expln -d testdb -u shen shen -q “select * from tblAreaCode” -o my.exp

19、db2flsn - Find log sequence number

根据LSN(可以通过db2pd查看LSN)找出对应的log文件。
db2flsn 000000BF0030 #在含有SQLOGCTL.LFH文件的目录下运行,如:/home/db2inst1/db2inst1/NODE0000/SQL00001
$ cd /home/db2inst1/db2inst1/NODE0000/SQL00001
$ db2flsn 0000281C0000
Given LSN is contained in log page 1025 in log file S0000142.LOG

20、db2fm - DB2 fault monitor

管理FM。
db2fm -f on #使FM enable,如果disable,则无法启动db2fmd服务进程(db2fm -U命令失效)
db2fm -U #启动db2fmd服务进程

21、db2gcf - Control DB2 instance

控制实例(分区数据库的实例),启动、停止数据库实例
db2gcf -u -p 0 -i db2inst1 #启动分区实例
db2gcf -s -p 0 -i db2inst1 #查看分区实例状态
db2gcf -d -p 0 -i db2inst1 #关闭分区实例

22、db2iauto - Auto-start instance

设置实例自启动

23、db2level - Show DB2 service level

查看当前数据库实例的版本及补丁号、位数(32bit or 64bit)

24、db2look - DB2 Statistics and DDL Extraction Tool

生成数据库所有对象的DDL语句、权限DCL、DB和DBM配置参数和数据库注册参数。
1)生成shen用户创建的所有对象DDL
db2look -d testdb -u shen -e -o shen.sql
2)生成shen用户创建的属于abc(schema)的对象DDL
db2look -d testdb -u shen -z abc -e -o shen.sql
3)生成shen用户创建的所有对象DDL,并且包括对象的统计信息(使用update语句修改字典表)
db2look -d testdb -u shen -m abc -e -o shen.sql
4)生成tbtest表格的ddl
db2look -d testdb -u shen -t tbtest -e -o shen.sql
5)生成DB、DBM的配置参数修改命令
db2look -d testdb -u shen -f -o shen.sql

25、db2mtrk - Memory tracker

跟踪实例、数据库、代理消耗的内存。
1)检查它们的水印值
$db2mtrk -i -d -p -w -v
Tracking Memory on: 2007/11/21 at 09:48:51
Memory for instance
Database Monitor Heap has watermark of 180224 bytes
Other Memory has watermark of 2818048 bytes
FCMBP Heap has watermark of 42303488 bytes
Total: 45301760 bytes
Memory for database: testdb
Backup/Restore/Util Heap has watermark of 16384 bytes
Package Cache has watermark of 131072 bytes
Catalog Cache Heap has watermark of 65536 bytes
Buffer Pool Heap has watermark of 16728064 bytes
Buffer Pool Heap has watermark of 4325376 bytes
Buffer Pool Heap has watermark of 655360 bytes
Buffer Pool Heap has watermark of 393216 bytes
Buffer Pool Heap has watermark of 262144 bytes
Buffer Pool Heap has watermark of 196608 bytes
Shared Sort Heap has watermark of 0 bytes
Lock Manager Heap has watermark of 21102592 bytes
Database Heap has watermark of 3964928 bytes
Other Memory has watermark of 16384 bytes
Application Control Heap has watermark of 98304 bytes
Application Group Shared Heap has watermark of 18644992 bytes
Total: 66600960 bytes
Memory for agent 13852
Application Heap has watermark of 65536 bytes
Total: 65536 bytes
2)检查它们的最大值
$db2mtrk -i -d -p -m -v
Tracking Memory on: 2007/11/21 at 09:48:42
Memory for instance
Database Monitor Heap has max size of 376832 bytes
Other Memory has max size of 19922944 bytes
FCMBP Heap has max size of 43335680 bytes
Total: 63635456 bytes
Memory for database: testdb
Backup/Restore/Util Heap has max size of 249200640 bytes
Package Cache has max size of 2089811968 bytes
Catalog Cache Heap has max size of 2089811968 bytes
Buffer Pool Heap has max size of 2089811968 bytes
Buffer Pool Heap has max size of 2089811968 bytes
Buffer Pool Heap has max size of 2089811968 bytes
Buffer Pool Heap has max size of 2089811968 bytes
Buffer Pool Heap has max size of 2089811968 bytes
Buffer Pool Heap has max size of 2089811968 bytes
Shared Sort Heap has max size of 100220928 bytes
Lock Manager Heap has max size of 21102592 bytes
Database Heap has max size of 11567104 bytes
Other Memory has max size of 12533760 bytes
Application Control Heap has max size of 344064 bytes
Application Group Shared Heap has max size of 37437440 bytes
Total: 17150902272 bytes
Memory for agent 13852
Application Heap has max size of 1277952 bytes
Total: 1277952 bytes

26、db2pd - Monitor and troubleshoot DB2 database

监控数据库。
$db2pd -inst -alldbs|more
返回下列信息:数据库版本、位数、补丁号;操作系统版本、cpu数目、物理内存;DBM参数值
$db2pd -db sample|more
返回下列信息(只有数据库被激活才可以返回数据):数据库连接信息;事务信息;缓存池信息(不同pagesize的);日志文件(含LSN信息);锁locks;表空间;容器;DB参数值

27、db2rfpen - Reset rollforward pending state

重置处于rollforward pending的数据库状态。

28、db2systray

在window上右下角启动db2托盘。

29、db2trc - Trace

启动和关闭数据库trace功能
1)跟踪db2
$ db2trc db2 on -f db2.trc
$ db2trc db2 off
$ db2trc fmt db2.trc db2.txt
2)跟踪das
$ db2trc das on -f das.trc
$ db2trc das off
$ db2trc fmt das.trc das.txt

30、db2untag - Release container tag

释放不用的容器。
$ db2untag -f /home/db2inst1/db2inst1/NODE0000/SQL00001/userdata01




实例级命令:

1. db2icrt

Description(描述):
Used to create a instance.(用于创建一个DB2实例,DB2实例是用于执行DB2命令和函数所处的上下文。
可以把实例看做管理对数据库文件的访问权的服务或守护进程。DB2中一台服务器可以有多个实例,每个实例相互独立,
但同一时刻只能有一个实例在运行。)
Systax(语法):
db2icrt instance_name
linux need to provide user id for create function and storage procedure.(Linux 中必须提供用于创建函数和存储过程的用户标识。)
db2icrt -u fenced_user_ID instance_name
Examples(例子):
db2icrt NEW

2. db2idrop

Description(描述):
Drop a db2 instance(删除一个DB2实例)。
Before drop a instance, you should disconnect all the database connection and stop current db2 instance.
Systax(语法):
db2idrop -f intance_name
Examples(例子):
db2idrop -f NEW

3. db2start

Description(描述):
Start the current db2 instance.(启动当前的DB2实例。)
Systax(语法):
db2start
Examples(例子):
db2start

4. db2stop

Description(描述):
Stop the current db2 instance.(停止当前的DB2实例。)
Systax(语法):
db2stop
Examples(例子):
db2stop

5. db2 get instance

Description(描述):
Get the current db2 instance, the value of environment db2instance.(获得当前所运行的DB2实例名称,环境变量db2instance的值。)
Systax(语法):
db2 get instance
Examples(例子):
db2 get instance

6. set db2instance

Description(描述):
Set the current db2 instance.(设置环境变量db2instance的值。)
Systax(语法):
Windows:         set db2instance=instance_name;
Unix C Shell:    setenv db2instance instance_name;
Unix Korn Shell: export db2instance=instance_name;
Examples(例子):
set db2instance=NEW

7. db2 get dbm cfg

Description(描述):
Each db2 instance has a configuration file.(每个DB2实例有一个数据库管理配置文件,这个文件用于保存与认证,监管级别,诊断级别,
以及贯穿实例的内存和进程资源有关的参数。当更新这个文件后需要重新启动实例。)
Systax(语法):
db2 get dbm cfg
Examples(例子):
db2 get dbm cfg

8. db2 update dbm cfg

Description(描述):

Systax(语法):
db2 update dbm cfg using PARAMETER_NAME PARAMETER_VALUE
Examples(例子):
db2 update dbm cfg using DIAGLEVEL 4
db2stop
db2start

9. db2imigr

Description(描述):
When you install a new version of DB2 UDB, you need to migrate instance.
Systax(语法):
db2imigr instance_name
Examples(例子):
db2imigr NEW

10. db2iupdt

Description(描述):
When you install a new version of DB2 UDB, you need to update instance.
Systax(语法):
db2iupdt instance_name
Examples(例子):
db2iupdt NEW

11. db2ilist

Description(描述):
List all the db2 instance in the server.(列出服务器上的所有的db2实例。)
Systax(语法):
db2ilist
Examples(例子):
db2ilist

12. db2 attach to

Description(描述):
Connect a db2 instance in the server from remote computer.(远程连接db2实例。)
Systax(语法):
ATTACH [TO node-name] [USER username [{USING password[NEW new-password CONFIRM confirm-password] |CHANGE PASSWORD}]]
Examples(例子):
db2 attach to NEW

13. db2 list applications

Description(描述):
List all the connection to the currenct db2 instance.(列出所有与当前db2实例的连接。)
Systax(语法):
db2 list applications [show detail]
Examples(例子):
db2 list applications [show detail]

14. db2 force application

Description(描述):
Stop the connection to the currenct db2 instance.(断开与当前db2实例的连接。)
Systax(语法):
FORCE APPLICATION {ALL | ( application-handle [ {,application-handle} ... ] )}[MODE ASYNC]
Examples(例子):
db2 db2 force application (6, 5)
db2 force application all


  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值