Scipts:生成重建索引的SQL脚本dba_rebuild_indexes.sql
来源:互联网 发布:apple数据恢复 编辑:程序博客网 时间:2024/06/05 17:10
-- +----------------------------------------------------------------------------+
-- | Jeffrey M. Hunter |
-- | jhunter@idevelopment.info |
-- | www.idevelopment.info |
-- |----------------------------------------------------------------------------|
-- | Copyright (c) 1998-2012 Jeffrey M. Hunter. All rights reserved. |
-- |----------------------------------------------------------------------------|
-- | DATABASE : Oracle |
-- | FILE : dba_rebuild_indexes.sql |
-- | CLASS : Database Administration |
-- | PURPOSE : This script generates another script that will include all of |
-- | the ALTER INDEX REBUILD .... commands needed to rebuild a |
-- | tablespaces indexes. This script will prompt the user for the |
-- | tablespace name. This script must be run be a user with the DBA |
-- | role under Oracle7. |
-- | NOTE : As with any code, ensure to test this script in a development |
-- | environment before attempting to run it in production. |
-- +----------------------------------------------------------------------------+
SET TERMOUT OFF;
COLUMN current_instance NEW_VALUE current_instance NOPRINT;
SELECT rpad(instance_name, 17) current_instance FROM v$instance;
SET TERMOUT ON;
PROMPT
PROMPT +------------------------------------------------------------------------+
PROMPT | Report : Rebuild Index Build Script |
PROMPT | Instance : ¤t_instance |
PROMPT +------------------------------------------------------------------------+
PROMPT
ACCEPT TS_NAME CHAR PROMPT 'Enter the index tablespace name : '
PROMPT
PROMPT Thanks... Creating rebuild index script for tablespace: &TS_NAME
SET ECHO OFF
SET FEEDBACK OFF
SET HEADING OFF
SET LINESIZE 180
SET PAGESIZE 0
SET TERMOUT ON
SET TIMING OFF
SET TRIMOUT ON
SET TRIMSPOOL ON
SET VERIFY OFF
CLEAR COLUMNS
CLEAR BREAKS
CLEAR COMPUTES
SET TERMOUT OFF
spool rebuild_&TS_NAME._indexes.sql
SELECT 'REM FILE : rebuild_&TS_NAME._indexes.sql' FROM dual;
SELECT ' ' FROM dual;
SELECT 'REM' FROM dual;
SELECT 'REM ***** ALTER INDEX REBUILD commands for tablespace: &TS_NAME' FROM dual;
SELECT 'REM' FROM dual;
SELECT ' ' FROM dual;
SELECT
'REM +------------------------------------------------------------------------+' || chr(10) ||
'REM | INDEX NAME : ' || owner || '.' || segment_name
|| lpad('|', 58 - (length(owner) + length(segment_name)) )
|| chr(10) ||
'REM | BYTES : ' || bytes
|| lpad ('|', 59-(length(bytes)) ) || chr(10) ||
'REM | EXTENTS : ' || extents
|| lpad ('|', 59-(length(extents)) ) || chr(10) ||
'REM +------------------------------------------------------------------------+' || chr(10) ||
'ALTER INDEX ' || owner || '.' || segment_name || chr(10) ||
' REBUILD ONLINE' || chr(10) ||
' TABLESPACE ' || tablespace_name || chr(10) ||
' STORAGE ( ' || chr(10) ||
' INITIAL ' || initial_extent || chr(10) ||
' NEXT ' || next_extent || chr(10) ||
' MINEXTENTS ' || min_extents || chr(10) ||
' MAXEXTENTS ' || max_extents || chr(10) ||
' PCTINCREASE ' || pct_increase || chr(10) ||
');' || chr(10) || chr(10)
FROM dba_segments
WHERE segment_type = 'INDEX'
AND owner NOT IN ('SYS')
AND tablespace_name = UPPER('&TS_NAME')
ORDER BY owner, bytes DESC
/
SPOOL OFF
SET TERMOUT ON
PROMPT
PROMPT Done... Built the script rebuild_&TS_NAME._indexes.sql
PROMPT
-- | Jeffrey M. Hunter |
-- | jhunter@idevelopment.info |
-- | www.idevelopment.info |
-- |----------------------------------------------------------------------------|
-- | Copyright (c) 1998-2012 Jeffrey M. Hunter. All rights reserved. |
-- |----------------------------------------------------------------------------|
-- | DATABASE : Oracle |
-- | FILE : dba_rebuild_indexes.sql |
-- | CLASS : Database Administration |
-- | PURPOSE : This script generates another script that will include all of |
-- | the ALTER INDEX REBUILD .... commands needed to rebuild a |
-- | tablespaces indexes. This script will prompt the user for the |
-- | tablespace name. This script must be run be a user with the DBA |
-- | role under Oracle7. |
-- | NOTE : As with any code, ensure to test this script in a development |
-- | environment before attempting to run it in production. |
-- +----------------------------------------------------------------------------+
SET TERMOUT OFF;
COLUMN current_instance NEW_VALUE current_instance NOPRINT;
SELECT rpad(instance_name, 17) current_instance FROM v$instance;
SET TERMOUT ON;
PROMPT
PROMPT +------------------------------------------------------------------------+
PROMPT | Report : Rebuild Index Build Script |
PROMPT | Instance : ¤t_instance |
PROMPT +------------------------------------------------------------------------+
PROMPT
ACCEPT TS_NAME CHAR PROMPT 'Enter the index tablespace name : '
PROMPT
PROMPT Thanks... Creating rebuild index script for tablespace: &TS_NAME
SET ECHO OFF
SET FEEDBACK OFF
SET HEADING OFF
SET LINESIZE 180
SET PAGESIZE 0
SET TERMOUT ON
SET TIMING OFF
SET TRIMOUT ON
SET TRIMSPOOL ON
SET VERIFY OFF
CLEAR COLUMNS
CLEAR BREAKS
CLEAR COMPUTES
SET TERMOUT OFF
spool rebuild_&TS_NAME._indexes.sql
SELECT 'REM FILE : rebuild_&TS_NAME._indexes.sql' FROM dual;
SELECT ' ' FROM dual;
SELECT 'REM' FROM dual;
SELECT 'REM ***** ALTER INDEX REBUILD commands for tablespace: &TS_NAME' FROM dual;
SELECT 'REM' FROM dual;
SELECT ' ' FROM dual;
SELECT
'REM +------------------------------------------------------------------------+' || chr(10) ||
'REM | INDEX NAME : ' || owner || '.' || segment_name
|| lpad('|', 58 - (length(owner) + length(segment_name)) )
|| chr(10) ||
'REM | BYTES : ' || bytes
|| lpad ('|', 59-(length(bytes)) ) || chr(10) ||
'REM | EXTENTS : ' || extents
|| lpad ('|', 59-(length(extents)) ) || chr(10) ||
'REM +------------------------------------------------------------------------+' || chr(10) ||
'ALTER INDEX ' || owner || '.' || segment_name || chr(10) ||
' REBUILD ONLINE' || chr(10) ||
' TABLESPACE ' || tablespace_name || chr(10) ||
' STORAGE ( ' || chr(10) ||
' INITIAL ' || initial_extent || chr(10) ||
' NEXT ' || next_extent || chr(10) ||
' MINEXTENTS ' || min_extents || chr(10) ||
' MAXEXTENTS ' || max_extents || chr(10) ||
' PCTINCREASE ' || pct_increase || chr(10) ||
');' || chr(10) || chr(10)
FROM dba_segments
WHERE segment_type = 'INDEX'
AND owner NOT IN ('SYS')
AND tablespace_name = UPPER('&TS_NAME')
ORDER BY owner, bytes DESC
/
SPOOL OFF
SET TERMOUT ON
PROMPT
PROMPT Done... Built the script rebuild_&TS_NAME._indexes.sql
PROMPT
0 0
- Scipts:生成重建索引的SQL脚本dba_rebuild_indexes.sql
- Scripts:重建索引的脚本(看懂脚本再用)rebuild_indx.sql
- SQL Server2005的索引重建
- SQL索引重建
- SQL SERVER 重建索引
- 索引重建SQL语句
- sql重建索引
- SQL 重建索引
- SQL SEVER数据库重建索引的方法
- sql server生成索引创建脚本
- SQL Server自动重建索引
- T-SQL重建所有数据库的所有表的索引
- 生成省市的SQL脚本
- powerdesigner生成SQL脚本的
- 监控索引常用的sql脚本
- 重建索引提高SQL Server性能
- SQL Server 重建索引 Rebuild Index
- 重建索引提高SQL Server性能
- (转载)Python 列表(list)操作
- std::vector介绍
- Oracle 多表关联查询后修改
- Hadoop在Windows环境下的部署
- 使用exceed登录远程登录liunx主机的设置
- Scipts:生成重建索引的SQL脚本dba_rebuild_indexes.sql
- 平衡树1
- JSP中文编码问题
- Android 判断网络是否连接
- Android开发中onClick事件的几种实现,分析,对比
- 栈的应用:解析算术表达式
- 判断日期结束日期不能小于开始日期
- Zend Framework 2 时区设置警告问题的解决
- android 下的一段视屏播放的逻辑