0% found this document useful (0 votes)
19 views

Utl Space Size Contiguous

The document contains SQL queries to analyze free space in Oracle tablespaces. It reviews free space by tablespace, identifies tablespaces lacking contiguous free space for table extensions, and details free extents and segment information by tablespace.

Uploaded by

isabel
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views

Utl Space Size Contiguous

The document contains SQL queries to analyze free space in Oracle tablespaces. It reviews free space by tablespace, identifies tablespaces lacking contiguous free space for table extensions, and details free extents and segment information by tablespace.

Uploaded by

isabel
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

1 /*

2 analizar el tamaño de los bloques libres. Por ejemplo cuando da el error ORA-1653:
unable to extend table y el tablespace tiene espacio libre
3 (bastante, nos ha dado con una ocupación del 21%)
4 pero la extensión que necesita la tabla no la tiene de forma contigua
5 */
6 /*------------------------------------*/
7 /* revision de espacio por tablespace */
8 /*------------------------------------*/
9 SET PAGESIZE 140 LINESIZE 200
10 COLUMN used_pct FORMAT A11
11
12 SELECT tablespace_name,
13 size_mb,
14 free_mb,
15 max_size_mb,
16 max_free_mb,
17 TRUNC((max_free_mb/max_size_mb) * 100) AS free_pct,
18 RPAD(' '|| RPAD('X',ROUND((max_size_mb-max_free_mb)/max_size_mb*10,0), 'X'),11,
'-') AS used_pct
19 FROM (
20 SELECT a.tablespace_name,
21 b.size_mb,
22 a.free_mb,
23 b.max_size_mb,
24 a.free_mb + (b.max_size_mb - b.size_mb) AS max_free_mb
25 FROM (SELECT tablespace_name,
26 TRUNC(SUM(bytes)/1024/1024) AS free_mb
27 FROM dba_free_space
28 GROUP BY tablespace_name) a,
29 (SELECT tablespace_name,
30 TRUNC(SUM(bytes)/1024/1024) AS size_mb,
31 TRUNC(SUM(GREATEST(bytes,maxbytes))/1024/1024) AS max_size_mb
32 FROM dba_data_files
33 GROUP BY tablespace_name) b
34 WHERE a.tablespace_name = b.tablespace_name
35 )
36 ORDER BY tablespace_name;
37 /*------------------------------------------------------------------------------------
---------------------------------------*/
38 /*-->>> objetivo: detectar el tablespace que no tiene libre el espacio contiguo para
la siguiente extension de un segmento */
39 /*------------------------------------------------------------------------------------
---------------------------------------*/
40 with a
41 as
42 (
43 SELECT tablespace_name,file_id,block_id,bytes,blocks,LEVEL,CONNECT_BY_ROOT block_id as
root,
44 count(*) over(partition by tablespace_name, file_id, CONNECT_BY_ROOT block_id) as
EXTENTS,
45 sum(bytes) over(partition by tablespace_name, file_id, CONNECT_BY_ROOT block_id) as
CONTIGUOUS_BYTES
46 FROM dba_free_space
47 CONNECT BY PRIOR (block_id+blocks) = block_id
48 and PRIOR tablespace_name = tablespace_name
49 and PRIOR file_id = file_id
50 )
51 select tablespace_name, max(next_extent), count(*)
52 from dba_segments s
53 group by tablespace_name
54 having max(next_extent) >
55 ( select max(CONTIGUOUS_BYTES)
56 from a
57 where (tablespace_name, file_id, block_id) in
58 (select tablespace_name, file_id, block_id from a
59 group by tablespace_name, file_id, block_id
60 having count(*)=1
61 ) and a.tablespace_name = s.tablespace_name
62 )
63 order by 1,2;
64
65 /*--------------------------------------------------------------------*/
66 /* revision de todos los espacios contiguos por tablespace */
67 /*--------------------------------------------------------------------*/
68 with a
69 as
70 (
71 SELECT tablespace_name,file_id,block_id,bytes,blocks,LEVEL,CONNECT_BY_ROOT block_id as
root,
72 count(*) over(partition by tablespace_name, file_id, CONNECT_BY_ROOT block_id) as
EXTENTS,
73 sum(bytes) over(partition by tablespace_name, file_id, CONNECT_BY_ROOT block_id) as
CONTIGUOUS_BYTES
74 FROM dba_free_space
75 CONNECT BY PRIOR (block_id+blocks) = block_id
76 and PRIOR tablespace_name = tablespace_name
77 and PRIOR file_id = file_id
78 )
79 select TABLESPACE_NAME "TABLESPACE NAME",
80 CONTIGUOUS_BYTES "CONTIGUOUS BYTES"
81 from a
82 where (tablespace_name, file_id, block_id) in
83 (select tablespace_name, file_id, block_id from
84 a
85 group by tablespace_name, file_id, block_id
86 having count(*)=1
87 )
88 order by 1,2 desc;
89 /*-----------------------------------------------------------------------*/
90 /* similar al anterior pero agrupo por el tamaño de los huecos contiguos */
91 /*-----------------------------------------------------------------------*/
92 with a
93 as
94 (
95 SELECT tablespace_name,file_id,block_id,bytes,blocks,LEVEL,CONNECT_BY_ROOT block_id as
root,
96 count(*) over(partition by tablespace_name, file_id, CONNECT_BY_ROOT block_id) as
EXTENTS,
97 sum(bytes) over(partition by tablespace_name, file_id, CONNECT_BY_ROOT block_id) as
CONTIGUOUS_BYTES
98 FROM dba_free_space
99 CONNECT BY PRIOR (block_id+blocks) = block_id
100 and PRIOR tablespace_name = tablespace_name
101 and PRIOR file_id = file_id
102 )
103 select tablespace_name,count(*) "# OF EXTENTS",CONTIGUOUS_BYTES "TAMAÑO_BLOQUES"
104 from a
105 where (tablespace_name, file_id, block_id) in
106 (select tablespace_name, file_id, block_id from a
107 group by tablespace_name, file_id, block_id
108 having count(*)=1
109 )
110 group by tablespace_name,CONTIGUOUS_BYTES
111 ORDER BY TABLESPACE_NAME, 3 DESC;
112
113 --------------------------------------------------------------------------------------
---------------
114 ------- detalle de los segmentos
115 select tablespace_name, owner, segment_name, next_extent
116 from dba_segments
117
118 select tablespace_name, max(next_extent), count(*)
119 from dba_segments
120 group by tablespace_name
121 order by 1,2;
122
123

You might also like