18 de mar. de 2008

Scripts em Tablespaces

Segue abaixo script para verificação de tamanho de tablespace

select tablespace_name,
sum_bytes_alloc "ALOCADO (MB)",
sum_bytes_livre "LIVRE (MB)",

decode(trunc((sum_bytes_livre/sum_bytes_alloc)*100),'','SEM ESPACO LIVRE',
trunc((sum_bytes_livre/sum_bytes_alloc)*100)) "PCT LIVRE"
from
(select tablespace_name ,
trunc(sum(bytes)/1024/1024) as sum_bytes_alloc
from dba_data_files
group by tablespace_name) XX,
(select tablespace_name Y ,
trunc(sum(bytes)/1024/1024) as sum_bytes_livre
from dba_free_space
group by tablespace_name) XY
where XX.tablespace_name = XY.Y (+);


Abaixo um script para mostrar a alocação de espaço livre por datafile classificado por file system.

set linesize 120
set pagesize 200
break on tablespace_name
col file_name for a62
col tablespace_name for a30
select a.tablespace_name,
a.file_name,

trunc(a.bytes/1024/1024) "Alocados (Mb)",
trunc(sum(b.bytes)/1024/1024) "Livres (Mb)"
from dba_data_files a, dba_free_space b
where a.file_id = b.file_id
and a.tablespace_name not in ('TOOLS','USERS','SYSTEM','RBS','RBSBIG','INDX','UNDOTBS','XDB','DRSYS','EXAMPLE')
group by a.file_name, a.tablespace_name, a.bytes
order by tablespace_name, substr (file_name,1,17);


Os scripts acima são muito uteis quando você necessita de uma verificação rapida ou um ambiente que você não possui o acesso ao Enterprise Manager. Um exemplo bem pratico é você estar no servidor de produção em um ambiente UNIX ou Linux, onde não possui ambiente gráfico.