免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12下一页
最近访问板块 发新帖
查看: 9142 | 回复: 13
打印 上一主题 下一主题

查询database和table占用空间的脚本 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2003-12-03 16:30 |只看该作者 |倒序浏览
其实很简单,适合新手。欢迎大家提意见哦。


  1. #!/usr/bin/sh

  2. if [ $# -ne 1 ]
  3. then
  4.   echo "  Usage: dbsize.sh DBNAME "
  5.   exit
  6. fi

  7. DBNAME=$1; export DBNAME
  8. TMPFILE=/tmp/dbsize.tmp
  9. RESULT=dbsize.out
  10. export TMPFILE RESULT

  11. dbaccess << !
  12. database sysmaster;
  13. unload to '$TMPFILE' delimiter "|"
  14. select  dbsname,
  15.         tabname,
  16.         count(*) num_of_extents,
  17.         sum( pe_size ) total_size
  18. from systabnames, sysptnext
  19. where partnum = pe_partnum and dbsname="$DBNAME"
  20. group by 1, 2
  21. order by 3 desc, 4 desc;
  22. !

  23. awk -F '|' ' \
  24. BEGIN {
  25.   size=0;
  26. }
  27. {
  28.   size = size + $4
  29. }
  30. END {
  31.   printf (" The Database Size of %s is %d pages. \n\n", ENVIRON["DBNAME"], size )
  32. }
  33. ' $TMPFILE >; $RESULT

  34. cat $TMPFILE >;>; $RESULT
  35. view $RESULT
  36. rm -f $TMPFILE

复制代码

论坛徽章:
0
2 [报告]
发表于 2003-12-03 18:36 |只看该作者

查询database和table占用空间的脚本

shell写不错,

顶一下

论坛徽章:
0
3 [报告]
发表于 2003-12-03 20:17 |只看该作者

查询database和table占用空间的脚本

不错,不错,收下来。

顺便顶一下。

论坛徽章:
0
4 [报告]
发表于 2003-12-03 22:24 |只看该作者

查询database和table占用空间的脚本

顶一下。

论坛徽章:
0
5 [报告]
发表于 2003-12-04 08:57 |只看该作者

查询database和table占用空间的脚本

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

论坛徽章:
0
6 [报告]
发表于 2003-12-04 09:55 |只看该作者

查询database和table占用空间的脚本

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

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

论坛徽章:
0
7 [报告]
发表于 2003-12-04 14:00 |只看该作者

查询database和table占用空间的脚本

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

论坛徽章:
0
8 [报告]
发表于 2003-12-04 14:04 |只看该作者

查询database和table占用空间的脚本

我在执行时报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老兄看看是什么问题啊?

论坛徽章:
0
9 [报告]
发表于 2003-12-04 14:57 |只看该作者

查询database和table占用空间的脚本

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

论坛徽章:
0
10 [报告]
发表于 2003-12-04 15:11 |只看该作者

查询database和table占用空间的脚本

试过了,我在/usr/bin创建了dbsize.sh,用的是db2,name is DEV
/usr/bin dbsize.sh DEV
/usr/bin/dbsize.sh[14]: dbaccess:  not found.
还差点什么?
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP