索引是提高数据库查询性能的有力武器。没有索引,就好比图书馆没有图书标签一样,找一本书自己想要的书比登天还难。然而索引在使用的过程中,尤其是在批量的DML的情形下会产生相应的碎片,以及B树高度会发生相应变化,因此可以对这些变化较大的索引进行重构以提高性能。N久以前Oracle建议我们定期重建那些高度为4,已删除的索引条目至少占有现有索引条目总数的20%的这些表上的索引。但Oracle现在强烈建议不要定期重建索引。具体可以参考文章:Oracle 重建索引的必要性 http://www.linuxidc.com/Linux/2014-04/100237.htm 。尽管如此重建索引还是有必要的,只是不建议定期。本文给出了重建索引的脚本供大家参考。
相关阅读:由Oracle索引来理解ArcSDE索引 http://www.linuxidc.com/Linux/2012-10/72184.htmOracle索引技术之如何建立最佳索引 http://www.linuxidc.com/Linux/2012-09/70996.htmOracle索引列NULL值引发执行计划该表的测试示例 http://www.linuxidc.com/Linux/2012-09/69938.htmOracle索引 主键影响查询速度 http://www.linuxidc.com/Linux/2011-12/48588.htmOracle索引扫描 http://www.linuxidc.com/Linux/2012-03/56644.htm 1、重建索引shell脚本robin@SZDB:~/dba_scripts/custom/bin> more rebuild_unbalanced_indices.sh
# +-------------------------------------------------------+
# + Rebulid unblanced indices |
# + Author : Leshami |
# + Parameter : No |
# + Blog : http://www.linuxidc.com |
# +-------------------------------------------------------+#!/bin/bash
# --------------------
# Define variable
# --------------------if [ -f ~/.bash_profile ]; then
. ~/.bash_profile
fiDT=`date +%Y%m%d`; export DT
RETENTION=1
LOG_DIR=/tmp
LOG=${LOG_DIR}/rebuild_unbalanced_indices_${DT}.log
DBA=Leshami@12306.cn# ------------------------------------
# Loop all instance in current server
# -------------------------------------
echo "Current date and time is : `/bin/date`">>${LOG}for db in `ps -ef | grep pmon | grep -v grep |grep -v asm |awk "{print $8}"|cut -c 10-`
do
echo "$db"
export ORACLE_SID=$db
echo "Current DB is $db" >>${LOG}
echo "===============================================">>${LOG}
$ORACLE_HOME/bin/sqlplus -S /nolog @/users/robin/dba_scripts/custom/sql/rebuild_unbalanced_indices.sql>>${LOG}
done;echo "End of rebuilding index for all instance at : `/bin/date`">>${LOG}
# -------------------------------------
# Check log file
# -------------------------------------
status=`grep "ORA-" ${LOG}`
if [ -z $status ];then
mail -s "Succeeded rebuilding indices on `hostname` !!!" ${DBA} <${LOG}
else
mail -s "Failed rebuilding indices on `hostname` !!!" ${DBA} <${LOG}
fi# ------------------------------------------------
# Removing files older than $RETENTION parameter
# ------------------------------------------------find ${LOG_DIR} -name "rebuild_unb*" -mtime +$RETENTION -exec rm {} ;exit
更多详情见请继续阅读下一页的精彩内容: http://www.linuxidc.com/Linux/2014-04/100536p2.htm
Linux 5 下安装MySQL 5.6(RPM方式)使用IF NOT EXISTS创建数据表相关资讯 Oracle重建索引 Oracle脚本
- Oracle 脚本创建ASM实例 (04/05/2015 18:29:49)
- Oracle新建表空间的shell脚本实例 (10/10/2014 17:25:23)
- Greenplum同步到Oracle脚本 (06/07/2014 21:24:05)
| - Oracle删除表空间的shell脚本实例 (10/10/2014 17:27:09)
- Oracle 新建用户shell脚本实例 (10/10/2014 17:23:43)
- Oracle 重建索引的必要性 (04/16/2014 04:22:36)
|
本文评论 查看全部评论 (0)