Come faccio a sapere se un tavolo in Oracle è frammentato?
-
27-10-2019 - |
Domanda
Ho un tavolo che sembra occupare più spazio di quanto non sia necessario. Mi è stato consigliato di copiare i dati in una nuova tabella e rinominare la nuova tabella e la vecchia tabella per scambiarli. Come posso confermare se una tabella corrente è effettivamente frammentata? Come posso stimare o calcolare la nuova dimensione della tabella fresca contenente gli stessi dati?
Soluzione
Se le tue statistiche sono aggiornate, ciò dovrebbe dare un'indicazione decente se le tabelle hanno molti più blocchi di quanto il volume dei dati delle righe suggerisca.
select table_name, round((num_rows * avg_row_len) /(8*1024)), blocks
from user_tables where ....
Questo spazio verrebbe utilizzato per inserti futuri, quindi non è necessariamente un problema. Se hai fatto un grande archivio o elimina i dati, esso Maggio Vale la pena rivendicare lo spazio (soprattutto se fai molte scansioni a tavola completa). [Nota: ho assunto blocchi da 8k, che sono il valore predefinito.
Se esegui un creazione/drop/rinomina, perderai indici, vincoli, sovvenzioni (più commenti della tabella se li usi).
Stai meglio a controllare il tablespace corrente (guarda in user_segments) e fai un ALTER TABLE tablename MOVE current_tablespace;
Dovrai ricostruire anche gli indici. Scegli li da user_indexes e fai un ALTER INDEX ... REBUILD;
Altri suggerimenti
- Prova a eseguire questo script usando svrmgrl connesso come dba
set serveroutput on
DECLARE
libcac NUMBER (6, 2);
rowcac NUMBER (6, 2);
bufcac NUMBER (6, 2);
redlog NUMBER (6, 2);
spsize NUMBER;
blkbuf NUMBER;
logbuf NUMBER;
BEGIN
SELECT VALUE
INTO redlog
FROM v$sysstat
WHERE name = 'redo log space requests';
SELECT 100 * (SUM (pins) - SUM (reloads)) / SUM (pins)
INTO libcac
FROM v$librarycache;
SELECT 100 * (SUM (gets) - SUM (getmisses)) / SUM (gets)
INTO rowcac
FROM v$rowcache;
SELECT 100 * (cur.VALUE con.VALUE - phys.VALUE)/(cur.VALUE con.VALUE)
into bufcac
from v$sysstat cur,v$sysstat con,v$sysstat phys,
v$statname ncu,v$statname nco,v$statname nph
where cur.statistic# = ncu.statistic# and
ncu.name = 'db block gets' and
con.statistic# = nco.statistic# and
nco.name = 'consistent gets' and
phys.statistic# = nph.statistic# and
nph.name = 'physical reads';
select VALUE
into spsize
from v$parameter
where name = 'shared_pool_size';
select VALUE
into blkbuf
from v$parameter
where name = 'db_block_buffers';
select VALUE
into logbuf
from v$parameter
where name = 'log_buffer';
DBMS_OUTPUT.put_line('> SGA CACHE STATISTICS');
DBMS_OUTPUT.put_line('> ********************');
DBMS_OUTPUT.put_line('> SQL Cache Hit rate = '||libcac);
DBMS_OUTPUT.put_line('> Dict Cache Hit rate = '||rowcac);
DBMS_OUTPUT.put_line('> Buffer Cache Hit rate = '||bufcac);
DBMS_OUTPUT.put_line('> Redo Log space requests = '||redlog);
DBMS_OUTPUT.put_line('> ');
DBMS_OUTPUT.put_line('> INIT.ORA SETTING');
DBMS_OUTPUT.put_line('> ****************');
DBMS_OUTPUT.put_line('> Shared Pool Size = '||spsize||' Bytes');
DBMS_OUTPUT.put_line('> DB Block Buffer = '||blkbuf||' Blocks');
DBMS_OUTPUT.put_line('> Log Buffer = '||logbuf||' Bytes');
DBMS_OUTPUT.put_line('> ');
if libcac < 99
then
DBMS_OUTPUT.put_line('*** HINT: Library Cache too low! Increase the Shared Pool Size.');
end if;
if rowcac < 85
then
DBMS_OUTPUT.put_line('*** HINT: Row Cache too low! Increase the Shared Pool Size.');
end if;
if bufcac < 90
then
DBMS_OUTPUT.put_line('*** HINT: Buffer Cache too low! Increase the DB Block Buffer value.');
end if;
if redlog > 100
then
DBMS_OUTPUT.put_line('*** HINT: Log Buffer value is rather low!');
end if;
end;
/
Prendi in considerazione l'usodbms_space.space_usage
e altre procedure in dbms_space
pacchetto.