Script to Report Extents and Contiguous Free Space (Doc ID 162994.1)
Script to Report Extents and Contiguous Free Space (Doc ID 162994.1)
***Checked for relevance on 15-Jun-2012***
The information in this article applies to: Oracle 8.1.7 to 11.2.0.3
PURPOSE
-------
Once the database is up and running, it is always good practice to monitor the
growth of the system.
SCOPE & APPLICATION
-------------------
If you can anticipate how much more space a particular
database object will need, then you can plan where to acquire the additional
space.These 3 scripts will give the DBA a chance to plan for additional disk space if
it is currently not available on the system.
DISCLAIMER
----------
This script is provided for educational purposes only. It is NOT supported by
Oracle World Wide Technical Support. The script has been tested and appears
to work as intended. However, you should always test any script before
relying on it.
SCRIPTS
-------
----------- cut ---------------------- cut -------------- cut --------------
=============================
SCRIPT 1 : EXTENT_CHECK.sql
=============================
- SQL to determine all database objects that have acquired at least a certain
number of extents. The ORACLE_SID and the number of extents to check out are
passed in from the command line.
rem OUTPUT FILENAME
rem
rem extent_check_ORACLE_SID.lis
rem
rem PARAMETERS
rem
rem 1 ORACLE_SID SID of the current database
rem 2 WARN_EXTENTS Warning level for maximum extents
rem
rem USAGE
rem
rem sqlplus dba_user/password @check_extents.sql ORACLE_SID 20
rem
define ORACLE_SID=&1 /* ORACLE_SID passed in from command line */
define WARN_EXTENTS=&2 /* Number of extents passed in from command line*/
set termout off
set newpage 0
set pagesize 65
set linesize 80
set feed off
set verify off
set wrap off
ttitle -
skip 2 -
left _sysdate -
right format 9,999 'Page: ' sql.pno -
skip 2 -
center 'Check Extent for ' ORACLE_SID -
skip 1 -
center 'Extents over: ' WARN_EXTENTS -
skip 2
break on owner
column sys_date new_value _sysdate noprint
column owner format a12 heading "OWNER"
column segment_name format a25 trunc heading "SEGMENT|NAME"
column segment_type format a10 trunc heading "SEGMENT|TYPE"
column kbytes format 9,999,999 heading "KBYTES"
column extents format 9,999,999 heading "EXTENTS"
column max_extents format 99999 heading "MAX|EXTENTS"
select to_char(sysdate,'Dy DD-Mon-YY HH:MI PM') SYS_DATE,
ds.owner , ds.segment_name , ds.segment_type ,
ds.bytes/1024 kbytes , ds.extents, ds.max_extents
from sys.dba_segments ds
where ds.extents > &&WARN_EXTENTS
order by ds.extents desc , ds.owner
spool extent_check_&ORACLE_SID..lis
/
spool off
undefine ORACLE_SID
undefine WARN_EXTENTS
exit
----------- cut ---------------------- cut -------------- cut --------------
EXEMPLE
-------
A sample output for ORACLE_SID S6F at extents of 5 or more:
Fri 21-Jun-01 12:23 PM Page:
1
Check Extent S6F
Extents over: 5
SEGMENT SEGMENT MAXIMUM
OWNER NAME TYPE KBYTES EXTENTS EXTENTS
------------ ------------------------- ---------- ---------- ---------- -------
SYS C_OBJ# CLUSTER 652 9 99
I_COL1 INDEX 232 7 99
VIEW$ TABLE 150 6 99
----------- cut ---------------------- cut -------------- cut --------------
==================================
SCRIPT 2 : CONTIG_FREE_SPACE.sql
==================================
- PL/SQL script to determine how much contiguous
free space is available for each tablespace in the database. Oracle will
acquire space by searching first for exact fit, then next best fit, and lastly
coalesce if possible.
create table SPACE_TEMP (
TABLESPACE_NAME CHAR(30),
CONTIGUOUS_BYTES NUMBER)
/
declare
cursor query is select *
from dba_free_space
order by tablespace_name, block_id;
this_row query%rowtype;
previous_row query%rowtype;
total number;
begin
open query;
fetch query into this_row;
previous_row := this_row;
total := previous_row.bytes;
loop
fetch query into this_row;
exit when query%notfound;
if this_row.block_id = previous_row.block_id + previous_row.blocks then
total := total + previous_row.bytes;
insert into SPACE_TEMP (tablespace_name)
values (previous_row.tablespace_name);
else
insert into SPACE_TEMP values (previous_row.tablespace_name,
total);
total := this_row.bytes;
end if;
previous_row := this_row;
end loop;
insert into SPACE_TEMP values (previous_row.tablespace_name,
total);
end;
/
set pagesize 60
set newpage 0
set echo off
ttitle center 'Contiguous Extents Report' -
skip 1 center new_today skip 3
break on "TABLESPACE NAME" skip page duplicate
spool contig_free_space.lis
rem
column "CONTIGUOUS BYTES" format 999,999,999
column "COUNT" format 999
column "TOTAL BYTES" format 999,999,999
column "TODAY" noprint new_value new_today format a1
rem
select TABLESPACE_NAME "TABLESPACE NAME",
CONTIGUOUS_BYTES "CONTIGUOUS BYTES",
count(*) "COUNT",
CONTIGUOUS_BYTES*count(*) "TOTAL BYTES",
to_char(sysdate,'FMMonth DD, YYYY') "TODAY"
from SPACE_TEMP
where CONTIGUOUS_BYTES is not null
group by TABLESPACE_NAME, CONTIGUOUS_BYTES
order by TABLESPACE_NAME, CONTIGUOUS_BYTES desc
/
spool off
drop table SPACE_TEMP
/
exit
/
----------- cut ---------------------- cut -------------- cut --------------
A sample output:
Contiguous Extents Report
May 28, 2001
TABLESPACE NAME CONTIGUOUS BYTES COUNT TOTAL BYTES
------------------------------ ---------------- ----- ------------
TEMP 3,584,000 1 3,584,000
TEMP 1,781,760 1 1,781,760
TEMP 1,740,800 1 1,740,800
TEMP 1,536,000 1 1,536,000
TEMP 1,126,400 2 2,252,800
TEMP 716,800 1 716,800
TEMP 512,000 1 512,000
Combining the contiguous extents in the tablespace yields eight large
virtual extents, two of which are the same size (1,126,400 bytes).
If many rows are returned with small contiguous bytes and count of 1, then the
tablespace may be fragmented. Currently, the tools to remedy fragmentation
are IMP/EXP (import and export) utilities. You may also drop segments that
lie between free extents, create a dummy object that will require a segment
of just the right size to cause the separate segments to be coalesced, and
then drop the dummy object.
----------- cut ---------------------- cut -------------- cut --------------
================================
SCRIPT 3 : GET_NEXT_EXT_SIZE.c
================================
- C program to calculate the size of the next extent
based on pctincrease and next extent size for the object.
/**************************************************************************
The program requires 3 arguments:
arg1 pctincrease of the object
arg2 number of the extent you wish to calculate the size of
arg3 size of the next extent storage parameter
For example:
get_next_ext_size 20 3 10000
This will return the size of extent# 4 for an object that has a
percent increase of 20% and next extent size of 10,000 bytes.
**************************************************************************/
#include
|
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/17252115/viewspace-1340452/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 聊聊dba_temp_free_space的allocated_space和free_space
- Oracle 最新PSU (Doc ID 2118136.2)Oracle
- expdp/impdp變慢 (Doc ID 2469587.1)
- Reading and Understanding Systemstate Dumps (Doc ID 423153.1)
- RMAN -- Frequently Asked Question (FAQ) (Doc ID 469777.1)
- Oracle 下載最新psu (Doc ID 2118136.2)Oracle
- 關於Oracle dba_free_space 檢視的研究Oracle
- ORA-15041 IN A DISKGROUP ALTHOUGH FREE_MB REPORTS SUFFICIENT SPACE
- PRCT-1011 : Failed to run "oifcfg" (Doc ID 1380183.1)AI
- How to Collect Diagnostics for Database Hanging Issues (Doc ID 452358.1)Database
- [轉帖]Release Schedule of Current Database Releases (Doc ID 742060.1)Database
- 【CURSOR】How to Monitor and tune Open and Cached Cursors (Doc ID 1430255.1)
- Physical Standby Switchover_status Showing Not Allowed. (Doc ID 1392763.1)
- oracle11g: Scheduler Maintenance Tasks or Autotasks (Doc ID 756734.1)OracleAINaN
- 【DBA】Relinking Oracle Home 常見問題 (Doc ID 2048232.1)Oracle
- How To Replicate Data from Oracle to Postgres Using GoldenGate (Doc ID 1544137.1OracleGo
- 11g-Reduce Transportable Tablespace Downtime using XTTS (Doc ID 1389592.1)TTS
- Can GoldenGate Replicate An Oracle Table That Contains Only CLOB Column(s)? (Doc ID 971833.1)GoOracleAI
- 12c DG新特性 - Active Data Guard Far Sync (Doc ID 2179719.1)
- 【GRID】Grid Infrastructure 啟動的五大問題 (Doc ID 1526147.1)ASTStruct
- 【DATAGUARD】Data Guard 12C 新特性:Far Sync Standby (Doc ID 2179719.1)
- ORA-04063: package body SYS.DBMS_REGISTRY_SYS has errors (Doc ID 2165402.1)PackageError
- Space Launch Report:2021年全球軌道發射達144次 133次成功創新紀錄
- Zabbix報告無交換記憶體主機“Lack of free swap space”問題解決記憶體
- 【ASM】ORA-27504 ORA-27300 ORA-27303 while starting ASM (Doc ID 2281441.1)ASMWhile
- 【RAC】Oracle 12c以及以上版本的diagsnap是什麼? (Doc ID 2469643.1)Oracle
- [20221015]mmon_slave sql_id=c9umxngkc3byq Automatic Report Flush.sqlSQL
- 請說說`<script>`、`<script async>`和`<script defer>`的區別
- Script
- Space Launch Report:2019年中國火箭入軌發射已達31次 或再登頂全球第一
- sqlserver docSQLServer
- [20201218]快速替代查詢dba_extents.txt
- Hilbert Space
- Shell Script
- shell script
- free命令
- Jest-Vue-ReportVue
- Find and Fix the Mismatch Between DBA_SEGMENTS and DBA_EXTENTS ViewsView
- Extract rows from a CORRUPT table creating ROWID from DBA_EXTENTS