Método de clasificación y análisis de espacio de tablas y fragmentación de tablas de ORACLE

tasa de fragmentación del espacio de tabla

idle> select a.tablespace_name,sqrt(max(a.blocks)/sum(a.blocks))*(100/sqrt(sqrt(count(a.blocks)))) FSFI
from dba_free_space a,dba_tablespaces b
where a.tablespace_name=b.tablespace_name
and b.contents not in ('TEMPORARY','UNDO')
group by a.tablespace_name 
order by 2;

TABLESPACE_NAME                      FSFI
------------------------------ ----------
EAM                            2.57604251
ALM                            20.1734462
SYSAUX                         22.2842767
SYSTEM                         23.7809729
USERS                           53.439579
RECCAT                                100
ARCH                                  100

7 rows selected.

idle> 

Cuanto menor es el número, más fragmentado está el espacio de la tabla, cuando es inferior al 30%, significa que el grado de fragmentación es considerable.

Mostrar tiempo de inactividad consecutivo por tablespace

Para citar un pasaje oficial:

La situación ideal es tener una gran extensión libre en su tablespace. Cuantas más extensiones de espacio libre haya en el tablespace, más probable es que se encuentre con problemas de fragmentación. El tamaño de las extensiones libres también es muy importante. Si tiene muchas extensiones pequeñas (demasiado pequeñas para cualquier tamaño de extensión siguiente) pero el total de bytes de espacio libre es grande, es posible que desee considerar las opciones de desfragmentación.

En el guión, el espacio continuo se cuenta y el espacio continuo se suma.Cuando el espacio libre total en la tabla es grande, pero hay muchos bloques pequeños, significa que la fragmentación es más grave.

========
Script : tfstsfgm
========
SET ECHO off 
REM NAME:TFSTSFRM.SQL 
REM USAGE:"@path/tfstsfgm" 
REM ------------------------------------------------------------------------ 
REM REQUIREMENTS: 
REM    SELECT ON DBA_FREE_SPACE 
REM ------------------------------------------------------------------------ 
REM PURPOSE: 
REM    The following is a script that will determine how many extents 
REM    of contiguous free space you have in Oracle as well as the  
REM total amount of free space you have in each tablespace. From  
REM    these results you can detect how fragmented your tablespace is.  
REM   
REM    The ideal situation is to have one large free extent in your  
REM    tablespace. The more extents of free space there are in the  
REM    tablespace, the more likely you  will run into fragmentation  
REM    problems. The size of the free extents is also  very important.  
REM    If you have a lot of small extents (too small for any next   
REM    extent size) but the total bytes of free space is large, then  
REM    you may want to consider defragmentation options.  
REM ------------------------------------------------------------------------ 
REM DISCLAIMER: 
REM    This script is provided for educational purposes only. It is NOT  
REM    supported by Oracle World Wide Technical Support. 
REM    The script has been tested and appears to work as intended. 
REM    You should always run new scripts on a test instance initially. 
REM ------------------------------------------------------------------------ 
REM Main text of script follows: 

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 + this_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 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"   
from SPACE_TEMP   
where CONTIGUOUS_BYTES is not null   
order by TABLESPACE_NAME, CONTIGUOUS_BYTES desc;   

select tablespace_name, count(*) "# OF EXTENTS",   
         sum(contiguous_bytes) "TOTAL BYTES"    
from space_temp   
group by tablespace_name;   

spool off   

drop table SPACE_TEMP   
/  

Método de clasificación de nivel de espacio de tabla

Para el espacio de tabla administrado por ASSM, generalmente se ordena automáticamente mediante el proceso smon, siempre que el valor pctincrease del espacio de tabla no sea 0, puede cambiar el parámetro de almacenamiento predeterminado pctincrease del espacio de tabla a distinto de 0, generalmente establecido a 1. Por ejemplo, modifique el atributo pctincrease del tablespace temporal: alter tablespace temp default storage(pctincrease 1); De esta manera, la desfragmentación a nivel del tablespace se puede organizar automáticamente.

Para espacios de tabla administrados por diccionario, puede usar el siguiente comando para organizarlos:
sql> alter tablespace <nombre de espacio de tabla> collesce;

Métodos de desfragmentación a nivel de tabla

1. Se prefiere el encogimiento


SQL> alter table t1 enable row movement; --打开行移动
表已更改。 

SQL> alter table t1 shrink space cascade; --压缩表及相关数据段并下调HWM

SQL> alter table t1 shrink space compact; --只压缩不下调HWM

SQL> alter table t1 shrink space ; --下调HWM

SQL> alter table t1 disable row movement; --关闭行移动

Solo se puede realizar en ASSM y tablespaces administrados localmente. Una vez que se completan, no se requiere la reconstrucción del índice, pero es mejor volver a recopilar la información estadística. El script se incluye en la parte anterior de este blog. ^_^

2. Importación y exportación

Después de exportar con exp/imp, vuelva a importar para reconstruir, volver a crear índices y recopilar estadísticas.

3. Tecnología CATS

  1. crear tabla newtable como select * from old_table
  2. soltar tabla_antigua
  3. cambiar el nombre de la tabla newtable a old_table
  4. Reconstruir índices, recopilar estadísticas.

4.mover espacio de tabla

sql> alter table <表名> move tablespace <表空间名>
重建索引,收集统计信息。

5. Redefinición en línea

Esto es un poco más complicado que los anteriores, y los errores de Oracle deben tenerse en cuenta durante la implementación, que se presentarán más adelante.

Supongo que te gusta

Origin blog.csdn.net/x6_9x/article/details/50596589
Recomendado
Clasificación