免费注册 查看新帖 |

Chinaunix

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

索引重建实用程序 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2003-03-16 15:15 |只看该作者 |倒序浏览
一次一个删除和重建数据库中的所有索引.
重建索引可以汇总磁盘,提高响应速度.必须在系统中无用户时运行.可以做成自动执行.
示例:
# idexextr
# This script creates 1 script whith 3 types of statements.
#        1. to drop all indexes on a database
#        2. to create all indexes on a database
#        3. audit trail statements
# The general idea is to make a dbaccess script to drop and
# re-create indexes one at a time. Simultaneously,a database.adt # file is  populated so that somebody monitoring can actually tell
# how far the script has progressed in execution.
# The database must be provided as an argument
usage="Usage : $0 DATABASE"
if [ $# -le 0 ]
          then echo
          $usage
          exit 1
fi
TEMPFILE=junk.$$
# echo working...
dbschema -d $1 >; $TEMPFILE
if [ $? != 0]
then
       echo Error occurred in schema extracion of $1
       exit 1
fi
# echo Schema extracted...
cat $TEMPFILE | sed "/{ /d" | sed "/} /d" \
                        | sed -f /usr/ron/bin/idxextr.f1 >; $1.cre
cat $1.cre | \
                 sed 's/\(.*}\)\(.*)\( on .*\)/\1 !echo \2 `date`>;>;  $1.adt;/' >; $1.msg
sed "1,4d" $TEMPFILE | sed -n "/create.* index/p" | \
                  sed "s/create.* index/drop index/" | sed "s/ on.*/;/" | \
                  sed "s/\ (.* index \)\(.*\);/{\2|} &/" >; $1.drp
cat $1.cre $1.drp $1.msg | sort -r | sed "s/.*\!echo/!echo/" >; $1.sql
#echo Script in $1.isql
rm $TEMPFILE $1.cre $1.drp $1.msg $i.adt
-----------------------------------------------------------------------------------
# idxextr.f1 : sed command file used by idxextr.
# Last 3 lines to make all 'create index' statement into a single line
#       (Ver. 6 spreads it across 2 lines if the stmt is long)
# Tabs Note : only the last line contains exactly 1 tab before
# the "}"
1,4d
/^create table/,/^ *);/d
/grant/d
/revoke/d
/update/,/;/d
/^ *$/d
s/\(.* index \)\(*.\) on/{\2} &/
/,${N
s/\n//
     }
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP