码迷,mamicode.com
首页 > 其他好文 > 详细

表空间管理工具

时间:2014-12-30 16:49:23      阅读:255      评论:0      收藏:0      [点我收藏+]

标签:

1. 查看表空间状态

1)使用一条命令即可查看表空间的状态信息,格式化输出 db2 list tablespaces show detail

db2 list tablespaces show detail | while read line  ; do w1=$(echo "$line" | cut -d" " -f1); if [ "$w1" ==  "Tablespace" ];then tabid=$(echo "$line" | cut -d‘=‘ -f2);fi; if [ "$w1" ==  "Name" ];then   name=$(echo "$line" | cut -d‘=‘ -f2); fi; if [ "$w1" ==  "Type" ];then  type=$(echo "$line" | cut -d‘=‘ -f2);type1=$(echo "$type" | awk ‘{print $1}‘); if [ "$type1" == "System" ];then Ttype=‘SMS‘;  else Ttype=‘DMS‘; fi;  fi; if [ "$w1" == "Contents" ];then contents=$(echo "$line" | cut -d‘=‘ -f2); fi; if  [ "$w1" ==  "State" ];then state=$(echo "$line" | cut -d‘=‘ -f2);fi; if [ "$w1" == "Total" ];then   total=$(echo "$line" | cut -d‘=‘ -f2);fi;if [ "$w1" == "Used" ]; then used=$(echo "$line" | cut -d‘=‘ -f2); fi;  if [ "$w1" ==  "Free" ]; then free=$(echo "$line" | cut -d‘=‘ -f2); fi; if [ "$w1" == "Page" ];then page=$(echo "$line" | cut -d‘=‘ -f2); printf "%-25s%-5s%-5s%-5s%-10s%-20s%-20s%-30s\n"  $name $tabid $page $Ttype $state $total $used; fi  done


我们有时候需要查看表空间状态,方式有很多,db2pd, db2 list, 当表空间较多的情况下,往往信息太多,导致不是很方便的查看信息。对于db2pd 方便之处在于不用连接数据库,即可以查询表空间信息,并且对表空间信息进行了较全的输出;db2 list,可以以表空间为单位输出对应表空间的信息;但是这两种方式对于表空间较多的数据库来说用起来很不方便。
查看表空间状态
db2 list tablespaces show detail | while read line  ; do w1=$(echo "$line" | cut -d" " -f1); if [ "$w1" ==  "Tablespace" ];then tabid=$(echo "$line" | cut -d‘=‘ -f2); fi; if [ "$w1" ==  "Name" ];then   name=$(echo "$line" | cut -d‘=‘ -f2);fi; if [ "$w1" ==  "Type" ];then  type=$(echo "$line" | cut -d‘=‘ -f2);type1=$(echo "$type" | awk ‘{print $1}‘); if [ "$type1" == "System" ];then Ttype=‘SMS‘;  else Ttype=‘DMS‘; fi; fi; if  [ "$w1" ==  "State" ];then state=$(echo "$line" | cut -d‘=‘ -f2); printf "%-25s%-10s%-10s%10s\n"  $name $tabid $Ttype $state; fi; done

===DISPLAY:
SYSCATSPACE              0         DMS           0x0000
TEMPSPACE1               1         SMS           0x0000
USERSPACE1               2         DMS           0x0000
SYSTOOLSPACE             3         DMS           0x0000
SYSTOOLSTMPSPACE         4         SMS           0x0000


2)通过视图查看表空间信息
db2 "select  substr(TBSP_NAME,1,20) as TBSPNAME,
TBSP_TYPE,
substr(TBSP_STATE,1,10) as TBSPSTATE ,
substr(TBSP_TOTAL_PAGES,1,10) as TOTAL_PAGES,
substr(TBSP_USABLE_PAGES,1,10) as USABLE_PAGES,
substr(TBSP_USED_PAGES,1,5) as USED_PAGES,
substr(TBSP_FREE_PAGES,1,5) as FREE_PAGES,
substr(TBSP_MAX_SIZE,1,5) as MAX_SIZE,
substr(TBSP_USING_AUTO_STORAGE,1,2) as AUTOStr,
substr(TBSP_AUTO_RESIZE_ENABLED,1,2)  as AUTORes from SYSIBMADM.TBSP_UTILIZATION"


2. 表空间自动扩展设置

1)查看表空间是否为自动扩展
db2 "select substr(TBSP_NAME,1,30) as DMS_tablespace_without_autoresize, TBSP_USING_AUTO_STORAGE, TBSP_AUTO_RESIZE_ENABLED from SYSIBMADM.TBSP_UTILIZATION where TBSP_TYPE=‘DMS‘ and TBSP_AUTO_RESIZE_ENABLED=0"

2)生成修改表空间为自动扩展

db2 -x "select ‘ALTER TABLESPACE ‘|| TBSP_NAME ||‘ AUTORESIZE YES;‘  from SYSIBMADM.TBSP_UTILIZATION where TBSP_TYPE=‘DMS‘ and TBSP_AUTO_RESIZE_ENABLED=0"

step 1: 
db2 -x "select ‘ALTER TABLESPACE ‘|| TBSP_NAME ||‘ AUTORESIZE YES;‘  from SYSIBMADM.TBSP_UTILIZATION where TBSP_TYPE=‘DMS‘ and TBSP_AUTO_RESIZE_ENABLED=0"  | tee changeTBSauto.sql 
step 2: 
db2 -tvf changeTBSauto.sql

表空间管理工具

标签:

原文地址:http://www.cnblogs.com/DBA-Ivan/p/4193731.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!