电脑技术学习

Informix中查询database和table的占用空间

dn001

Informix数据库中查询database和table占用空间的实例脚本:

#!/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. nn", ENVIRON["DBNAME"], size )
}
' $TMPFILE >$RESULT

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