创建使用program对无效索引进行重建
来源:互联网 发布:oa网络地板 编辑:程序博客网 时间:2024/06/06 17:54
--创建使用program对无效索引进行重建
- shell脚本
- 匿名pl/sql
- 创建procedure
--模拟将索引不可用SYS@PROD2> alter table scott.emp move;Table altered.SYS@PROD2> alter table scott.dept move;Table altered.SYS@PROD2> select 'alter index '||owner||'."'||index_name||'" rebuild;' from dba_indexes where OWNER='SCOTT' and status='UNUSABLE';'ALTERINDEX'||OWNER||'."'||INDEX_NAME||'"REBUILD;'------------------------------------------------------------------------------------alter index SCOTT."PK_DEPT" rebuild;alter index SCOTT."PK_EMP" rebuild;
1.通过shell脚本实现[oracle@ocm1 ~]$ vi index_re.sh --编写脚本[oracle@ocm1 ~]$ cat index_re.sh #!/bin/bashexport ORACLE_BASE=/u01/app/oracleexport ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1export PATH=$ORACLE_HOME/bin:$PATHexport ORACLE_SID=PROD2sqlplus / as sysdba <<EOFspool /tmp/i.sql repselect 'alter index '||owner||'."'||index_name||'" rebuild;' from dba_indexes where OWNER='SCOTT' and status='UNUSABLE';spool offho sed '/^alter index /p' -n /tmp/i.sql > /tmp/i1.sqlstart /tmp/i1.sqlEOF[oracle@ocm1 ~]$ chmod +x index_re.sh --给予执行权限[oracle@ocm1 ~]$ ./index_re.sh SQL*Plus: Release 11.2.0.3.0 Production on Fri Jan 6 15:58:20 2017Copyright (c) 1982, 2011, Oracle. All rights reserved.Connected to:Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - ProductionWith the Partitioning, OLAP, Data Mining and Real Application Testing optionsSYS@PROD2> SYS@PROD2> 'ALTERINDEX'||OWNER||'."'||INDEX_NAME||'"REBUILD;'------------------------------------------------------------------------------------alter index SCOTT."PK_DEPT" rebuild;alter index SCOTT."PK_EMP" rebuild;SYS@PROD2> SYS@PROD2> SYS@PROD2> Index altered.Index altered.SYS@PROD2> Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - ProductionWith the Partitioning, OLAP, Data Mining and Real Application Testing options[oracle@ocm1 ~]$ sqlplus / as sysdbaSQL*Plus: Release 11.2.0.3.0 Production on Fri Jan 6 15:58:30 2017Copyright (c) 1982, 2011, Oracle. All rights reserved.Connected to:Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - ProductionWith the Partitioning, OLAP, Data Mining and Real Application Testing options--验证索引确实被重建SYS@PROD2> select 'alter index '||owner||'."'||index_name||'" rebuild;' from dba_indexes where OWNER='SCOTT' and status='UNUSABLE';no rows selected
2.编写匿名sqlSYS@PROD2> alter table scott.dept move;alTable altered.SYS@PROD2> alter table scott.emp move;Table altered.SYS@PROD2> begin 2 for i in (select index_name from user_indexes where status='UNUSABLE') loop 3 execute immediate 'alter index "'||i.index_name||'" rebuild'; 4 end loop; 5 end; 6 /PL/SQL procedure successfully completed.SYS@PROD2> save index_plsql.sqlCreated file index_plsql.sqlSYS@PROD2> conn scott/tigerConnected.SCOTT@PROD2> start index_plsql.sqlPL/SQL procedure successfully completed.SCOTT@PROD2> select index_name,status from user_indexes;INDEX_NAME STATUS------------------------------ --------PK_EMP VALIDPK_DEPT VALID
3.创建procedureSCOTT@PROD2> create or replace procedure index_rebuild 2 is 3 begin 4 for i in (select index_name from user_indexes where status='UNUSABLE') loop 5 execute immediate 'alter index "'||i.index_name||'" rebuild'; 6 end loop; 7 end; 8 /Procedure created.SCOTT@PROD2> save index_procudure.sqlCreated file index_procudure.sqlSCOTT@PROD2> alter table emp move;Table altered.SCOTT@PROD2> alter table dept move;Table altered.SCOTT@PROD2> select index_name,status from user_indexes;INDEX_NAME STATUS------------------------------ --------PK_EMP UNUSABLEPK_DEPT UNUSABLESCOTT@PROD2> exec index_rebuild;PL/SQL procedure successfully completed.SCOTT@PROD2> select index_name,status from user_indexes;INDEX_NAME STATUS------------------------------ --------PK_EMP VALIDPK_DEPT VALID
0 0
- 创建使用program对无效索引进行重建
- Sql server 日记 (自动对数据库中的索引进行重建)
- 如何进行批量索引重建?
- 使用游标重建索引
- 使用Lucene对预处理后的文档进行创建索引(可运行)
- online创建索引和重建索引
- 使用Mysql对URL进行索引
- 怎么对ArcSDE数据库的要素类进行批量重建空间索引
- MySQL 创建索引、重建索引、查询索引、删除索引
- 使用INDEX_STATS重建索引判断
- 创建Core,并对索引进行CRUD操作
- sh使用-n对参数进行判断无效的问题
- Oracle 创建索引、重建索引、删除索引的语法
- Oracle 创建索引、重建索引、删除索引的语法
- 重建索引对复制分发的影响
- oracle 索引失效、创建及重建
- Oracle创建/重建和删除索引
- Oracle创建、重建和删除索引
- JSPatch 成长之路
- 关于UI小心得
- JVM判断代码是否是热点代码方式
- Debug自定义的AbstractProcesson
- java 实现文件内容的加密和解密
- 创建使用program对无效索引进行重建
- 【Unity3D入门教程】Unity3D界面介绍及游戏对象基本操作
- iOS 输入框字数限制
- 简单Socket通信
- 简单说明Service服务,使用Service
- input系统一 loop线程的创建与运行
- 将图片转换成Base64
- IJKPlayer使用
- hydra安装及使用