oracle 索引重建脚本,Oracle 重建索引脚本

本文探讨了数据库索引在性能优化中的重要性,指出虽然索引重建曾被推荐,但现在Oracle建议避免定期重建。分享了一个用于检测和重建不平衡索引的自动化脚本,该脚本循环遍历所有实例,根据特定条件重建索引,并通过邮件报告结果。同时,文章提醒清理旧日志文件以保持系统整洁。
摘要由CSDN通过智能技术生成

索引是提高数据库查询性能的有力武器。没有索引,就好比图书馆没有图书标签一样,找一本书自己想要的书比登天还难。然而索引在使用的过程中,尤其是在批量的DML的情形下会产生相应的碎片,以及B树高度会发生相应变化,因此可以对这些变化较大的索引进行重构以提高性能。N久以前Oracle建议我们定期重建那些高度为4,已删除的索引条目至少占有现有索引条目总数的20%的这些表上的索引。但Oracle现在强烈建议不要定期重建索引。具体可以参考文章:Oracle 重建索引的必要性 http://www.linuxidc.com/Linux/2014-04/100237.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

fi

DT=`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}

else

mail -s "Failed rebuilding indices on `hostname`  !!!" ${DBA}

fi

# ------------------------------------------------

# Removing files older than $RETENTION parameter

# ------------------------------------------------

find ${LOG_DIR} -name "rebuild_unb*" -mtime +$RETENTION -exec rm {} \;

exit

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值