首页 > 学技术 > 技术网文 > Informix > 正文

[精华] 查询database和table占用空间的脚本


来源 chinaunix.net 酷勤网整理

其实很简单,适合新手。欢迎大家提意见哦。 :o 


#!/usr/bin/sh

if [ $# -ne 1 ]
then
  echo "  Usage: dbsize.sh DBNAME "
  exit
fi

DBNAME=$1; export DBNAME
TMPFILE=/tmp/dbsize.tmp
RESULT=dbsize.out
export TMPFILE RESULT

dbaccess << !
database sysmaster;
unload to '$TMPFILE' delimiter "|"
select  dbsname,
tabname,
count(*) num_of_extents,
sum( pe_size ) total_size
from systabnames, sysptnext
where partnum = pe_partnum and dbsname="$DBNAME"
group by 1, 2
order by 3 desc, 4 desc;
!

awk -F '|' ' \
BEGIN {
  size=0; 
}
{
  size = size + $4
}
END {
  printf (" The Database Size of %s is %d pages. \n\n", ENVIRON["DBNAME"], size )
}
' $TMPFILE >; $RESULT

cat $TMPFILE >;>; $RESULT
view $RESULT
rm -f $TMPFILE





 czw1413_cn 回复于:2003-12-03 18:36:54

shell写不错,

顶一下


 lmtok 回复于:2003-12-03 20:17:16

不错,不错,收下来。

顺便顶一下。


 horse 回复于:2003-12-03 22:24:11

顶一下。


 gzdaily_sap 回复于:2003-12-04 08:57:14

如何使用该程序?
使用的时候需要修改吗?


 cruelsun 回复于:2003-12-04 09:55:58

将代码保存为文本文件,文件名称建议为dbsize.sh,
执行 chmod +rx dbsize.sh 赋可执行权限。
要求执行的用户具有连接数据库权限,并设置了INFORMIXDIR INFORMIXSERVER等informix环境变量。

基本上不需要修改即可使用,当然,你也可以修改它使它更完善。 :)


 onlywxw 回复于:2003-12-04 14:00:33

执行时只要写上:dbsize.sh databasename就可以了是吧?


 onlywxw 回复于:2003-12-04 14:04:45

我在执行时报201错误:
-201    A syntax error has occurred.

This general error message indicates mistakes in the form of an SQL
statement. Look for missing or extra punctuation (such as missing or
extra commas, omission of parentheses around a subquery, and so on),
keywords misspelled (such as VALEUS for VALUES), keywords misused (such
as SET in an INSERT statement or INTO in a subquery), keywords out of
sequence (such as a condition of "value IS NOT" instead of "NOT value
IS"), or a reserved word used as an identifier.

Database servers that provide full NIST compliance do not reserve any
words; queries that work with these database servers might fail and
return error -201 when they are used with earlier versions of Informix
database servers.

The cause of this error might be an attempt to use round-robin syntax with
CREATE INDEX or ALTER FRAGMENT INIT on an index. You cannot use round-robin
indexes.

请cruelsun老兄看看是什么问题啊?


 gzdaily_sap 回复于:2003-12-04 14:57:48

什么是“INFORMIXDIR INFORMIXSERVER等informix环境变量”
能具体一点吗?
root用户行吗?


 gzdaily_sap 回复于:2003-12-04 15:11:02

试过了,我在/usr/bin创建了dbsize.sh,用的是db2,name is DEV
/usr/bin :)dbsize.sh DEV
/usr/bin/dbsize.sh[14]: dbaccess:  not found.
还差点什么?


 nkliyong 回复于:2003-12-05 16:47:50

环境变量没设全,PATH=$PATH:$INFORMIXDIR/bin没有就找不着dbaccess


 cruelsun 回复于:2003-12-05 20:36:11

root不一定可以,具体看你的数据库权限,
既然有root权限,执行 su - informix
切换到informix用户执行好了。


 villey 回复于:2006-03-17 17:20:55

这个shell还是不错的。




原文链接:http://bbs.chinaunix.net/viewthread.php?tid=215422
转载请注明作者名及原文出处



收藏本页到: