DB2 应用

1、DB2 连接: db2 connect  to  数据库实例名  user 用户名 using 密码

 

2、db2level

3、oslevel –r

 

4、快照

1)、数据库快照:db2 get snapshot for database on  数据库实例名

2)、表快照:db2 get snapshot for tables on 数据库实例名

3)、应用快照:db2 get snapshot for  all application

 

4)、缓冲池快照:db2 get snapshot for bufferpools on  数据库实例名  at dbpartitionnum 3

5)、打开和关闭快照:db2 update dbm cfg using monitorSwitch [ON |OFF] 

6)、数据库管理器快照:db2 get snapshot for database manager

7)、表空间和缓冲池快照

db2 get snapshot for tablespaces on 数据库实例名

db2 get snapshot for bufferpools on 数据库实例名

附:缓冲池命中率,如下图所示:



 

 

8)、锁快照:db2 get snapshot for locks on  数据库实例名

9)、动态 SQL 快照

10)、使用 SQL 快照函数

5、 查看所有节点情况

  db2_all " [<+1< ]db2 connect to sccrm user  db2inst1 using db2inst1;db2 get snapshot for all databases"

6、查看所有数据库应用
    db2 list application [show detail]

7、 获取某个应用的快照
db2 get snapshot for locks for application agentid 进程号
8 获取某个应用的详细情况
db2 get snapshot for application agentid 进程号 [global]
得到insert、select情况 、
操作系统进程ID   Process ID of client application

9 杀掉某个进程
   force application(进程号)
   force application all
10 查看表空间使用情况
db2_all tbsinfo -t -w 1 -d sccrm -u db2inst1 -p db2inst1
db2 list tablespaces show detail
db2pb –tablespaces –db sccrm
表空间计算规则:TOTAL_PGS*节点数*页大小/1024/1024
11 如何查看表的大小
select tabname, a.fpages * b.pagesize/1024/1024
from syscat.tables as a, syscat.tablespaces as b
where
      a.tbspaceid=b.tbspaceid
      and a.type='T'
      and a.tabname=‘TABNAME'
      and a.tbspace='TBS_RPT'
fpages代表当前的数据页,查看前请先runstats一下


12 如何压缩表
1.alter table tabname  compress yes
2.reorg table tabname resetdictionary
3.runstats on  table schema.tabname

在syscat.tables中的COMPRESSION字段 可以看出是否使用了压缩
  N:没有设置任何压缩
  R:仅仅设置了数据行压缩
  PCTPAGESSAVED表示使用压缩节省空间页的百分比。
(关闭开启)空值压缩 db2 alter table tablenam (de)activate value compress
(关闭开启)系统默认压缩 db2 alter table tablenam (de)activate compress system default
或者在定义的表格的时候:db2 create table tablenam value compress

13、 建表
CREATE TABLE TABNAME(
                        COLUMN1   TYPE,
                        COLUMN 2  TYPE,
                        COLUMN 3  TYPE)  
COMPRESS YES PARTITIONING KEY(分区键)IN表空间 INDEX IN 索引空间 NOT LOGGED INITIALLY ;
Create table A like B in COMPRESS YES PARTITIONING KEY(分区键)IN表空间 INDEX IN 索引空间 NOT LOGGED INITIALLY ;
   *必须指定分区键和表空间

【实例说明】

创建表

CREATE TABLE BOOKS
( BOOKID INTEGER,
BOOKNAME VARCHAR(100),
ISBN CHAR(10) )

使用like创建表
CREATE TABLE MYBOOKS LIKE BOOKS

制定表空间
db2 create table T1 (c1 int ...) in TS1
db2 create table T2 (c1 float ...) in TS1

删除表
drop table tab_name

添加删除列
db2 => create table test (c1 int)
DB20000I The SQL command completed successfully.
db2 => alter table test add c2 char(8)
DB20000I The SQL command completed successfully.
db2 => alter table test drop c2  
DB20000I The SQL command completed successfully.

15、 清表
   1.alter table tabname activate not logged initially with empty table
   2. delete from tabname [where]
   3. drop table tabname
  *对于大数据量的表,不允许直接delete操作[或者必须加上where条件,把需要删除的数据量减少]

猜你喜欢

转载自wf305.iteye.com/blog/1552000
db2