我有一张桌子,它似乎占用了比它需要的更多的空间。有人建议我将数据复制到新表并重命名新表和旧表以交换它们。如何确认当前表是否实际上是碎片化的?如何估计或计算包含相同数据的新表的新大小?
问问题
23864 次
3 回答
2
如果您的统计数据是最新的,那么这应该可以很好地表明表中的块是否比行数据量所建议的多得多。
select table_name, round((num_rows * avg_row_len) /(8*1024)), blocks
from user_tables where ....
该空间将用于将来的插入,因此不一定是问题。如果您已经完成了大型归档或数据删除,那么回收空间可能是值得的(尤其是在您进行大量全表扫描的情况下)。[注意:我假设 8k 块,这是默认值。]
如果您执行 CREATE/DROP/RENAME,您将丢失任何索引、约束、授权(如果您使用它们,则加上表注释)。
您最好检查当前表空间(查看 USER_SEGMENTS)并执行ALTER TABLE tablename MOVE current_tablespace;
您还需要在以后重建索引。从 USER_INDEXES 中选择它们并执行ALTER INDEX ... REBUILD;
于 2011-06-15T00:05:56.693 回答
0
-- 尝试使用作为 DBA 连接的 svrmgrl 运行此脚本
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;
/
于 2011-06-14T11:11:15.787 回答
0
考虑使用dbms_space.space_usage
和dbms_space
包中的其他程序。
于 2011-06-16T20:15:50.470 回答