|
IOTN :: Field Book :: ORACLE
|
segment shrink [ alter table ... shrink space; ]
|
ÃÖ±æÈ£
[LIST]
|
2009-03-31 22:40:26, Á¶È¸ : 32,511 |
Ãß°¡
12.2 online °¡´É
alter table ... enable row movement;
alter table ... shrink space;
[ insert ÃÊ´ç 100°Ç À̽´ ¾øÀ½ / ¿ë·®¸¸Å ¿À·¡ °É¸². / undo tablespace full À̽´ ¾øÀ½ ÀÚµ¿ resize µÊ ]
alter table ... deallocate unused;
PURPOSE
--------------------------------------------------------------------------------
Oracle10g¿¡¼´Â, ¼¼±×¸ÕÆ®¸¦ shrink ½Ãų ¿É¼ÇÀÌ Á¸ÀçÇϸç,
ÀÌ ±â´ÉÀ» È°¿ëÇϸé DBA°¡°¡ °ø°£À» Á»´õ È¿À²ÀûÀ¸·Î È°¿ëÇÒ ¼öÀÖ´Ù ÀÌ ±â´ÉÀº,
¶ÇÇÑ ÁúÀÇ Ã³¸® ¼Óµµ °³¼±¿¡µµ µµ¿òÀÌ µÈ´Ù.
Explanation
--------------------------------------------------------------------------------
1. Áغñ »çÇ×
Init.ora ÆĶó¹ÌÅÍÀÎ 'Compatible' °ªÀÌ 10.0 ÀÌ»óÀ̾î¾ß ÇÔ.
¼¼±×¸ÓÆ®´Â, AUTO Segment Space Managed Tablespace¿¡ Á¸ÀçÇØ¾ß ÇÔ.
2. µ¿ÀÛ ¹æ¹ý
1) Å×À̺íÀÇ row movement ±â´ÉÀ» È°¼ºÈ ½ÃŲ´Ù.
SQL> ALTER TABLE scott.emp ENABLE ROW MOVEMENT;
2) Å×À̺íÀ» shrink ½ÃÅ°Áö¸¸, HWM (High Water Mark)À» shrink ½ÃÅ°Áö ¾Ê´Â´Ù.
SQL> ALTER TABLE scott.emp SHRINK SPACE COMPACT;
3) Å×À̺í°ú HWMÀ» shrink ½ÃŲ´Ù.
SQL> ALTER TABLE scott.emp SHRINK SPACE;
4) Å×ÀÌºí ¹× °ü·ÃµÈ À妽º¸¦ ¸ðµÎ shrink½ÃŲ´Ù.
SQL> ALTER TABLE scott.emp SHRINK SPACE CASCADE;
5) MView ÇüÅÂÀÇ Å×À̺íÀ» shrink½ÃŲ´Ù.
SQL> ALTER TABLE <table name> SHRINK SPACE;
6) À妽º¸¸ shrink ½ÃŲ´Ù.
SQL> ALTER INDEX <index nam> SHRINK SPACE;
3. Àû¿ë ´ë»ó
1) Normal Table
2) Index
3) Lob
4) IOT
5) MView
4. Query/DML Concurrency
Segment shrink¸¦ ÇÒ ¶§ÀÇ online 󸮴Â, DML-ȣȯ ¶ôÀ» »ç¿ëÇÑ´Ù. µû¶ó¼ DMLÀº
shrink¸¦ ó¸® Çϴµ¿¾È¿¡µµ »ç¿ëÇÒ ¼ö ÀÖ´Ù. space-release/HWM Á¶Á¤À» ÇÏ´Â ´Ü°è¿¡¼´Â,
Å×ÀÌºí¿¡ ´ëÇØ DML°í ȣȯµÇÁö ¾Ê´Â ¶ôÀ» »ç¿ëÇÑ´Ù µû¶ó¼, DMLÀº shink°¡ ³¡³¯ ¶§ ±îÁö
Àá½Ã Áߴܵdzª.
shrink¸¦ ½ÇÇàÇÔÀ¸·Î½á ¹ß»ýÇÏ´Â DML ó¸® °ü·Ã ¿¡·¯´Â ¾ø´Ù.
Äõ¸®´Â ¼¼±×¸ÕÆ®ÀÇ HWM¿¡ ´ëÇÑ Ä³½¬¸¦ »ç¿ëÇÑ´Ù. ¿À¶óŬÀº, HWMÀÌ ¾ðÁ¦³ª Ä¿Áú °ÍÀ¸·Î °£ÁÖÇÑ´Ù. µû¶ó¼
CRÀº ¼¼±×¸ÕÆ® Çì´õ ¹× ÀͽºÅÙÆ® ¸Ê ºí·°¿¡ ´ëÇؼ´Â ÇÊ¿äÇÏÁö ¾Ê´Ù. ¼¼±×¸ÕÆ® HWMÀÌ ÀÛ¾ÆÁö´Â À¯ÀÏÇÑ
°æ¿ì´Â, drop ¶Ç´Â truncate ÀÛ¾÷ »ÓÀÌ´Ù.
¿À¶óŬÀº, drop/truncate DDL¿Í ÁúÀÇ󸮰¡ µ¿½Ã¿¡ Á¸ÀçÇÒ ¼öÀÖ°Ô Çã¿ëÇϴµ¥, ÀÌ°ÍÀº ÁúÀÇ Ã³¸®°¡
¶ôÀ» ÇÊ¿ä·Î ÇÏÁö ¾Ê±â ¶§¹®ÀÌ´Ù. ¸¸¾à drop/truncate ÀÛ¾÷ÀÌ ³¡³ ÈĶó¸é, ÇØ´ç °ø°£Àº ´Ù¸¥ ¼¼±×¸ÕÆ®¿¡
ÀÇÇØ »ç¿ëµÇ¸ç, ÁúÀÇ´Â "8103 - object does not exist"¶ó´Â ¿¡·¯ ¸Þ½ÃÁö¿Í ÇÔ²² ½ÇÆÐÇÏ°Ô µÈ´Ù.
¼¼±×¸ÕÆ®¸¦ shrinkÇÏ´Â µ¿¾È, ¼¼±×¸ÕÆ®ÀÇ HWM°¡ º¯°æµÈ´Ù¸é, ÇØ´ç ¼¼±×¸ÕÆ®¿Í °ü·ÃµÈ ºñÆ®¸Ê ºí·°°ú
¼¼±×¸ÕÆ® Çì´õÀÇ incarnation number°¡ º¯°æµÈ´Ù. ÈÄ¼Ó µ¥ÀÌÅÍ ºí·° °ü·Ã ÀÛ¾÷Àº »õ·Î ºÎ¿©µÈ
incarnation number¸¦ »ç¿ëÇÑ´Ù.
¸¸¾à ÀÌ ´Ü°è¿¡¼ ½ÇÇàµÇ´Â ÁúÀÇ°¡ ÀÖ¾ú´Ù¸é, "10632 - invalid rowid" ¿¡·¯¿Í ÇÔ²² ½ÇÆÐÇϴµ¥
´ÙÀ½°ú °°Àº Á¶°ÇÀÌ ¸¸Á· µÇ¾î¾ß ÇÑ´Ù.
1) °»½ÅµÈ ºñÆ®¸Ê ºí·°À» Àд´٠(»õ·Î¿î inc#). ÀÌ °æ¿ì failure´Â, ÇØ´ç °ø°£ÀÌ Àç »ç¿ëµÇÁö ¾Ê¾Ò´Ù¸é
¹ß»ýÇÏ°Ô µÈ´Ù.
2) °ø°£ÀÌ µ¿ÀÏÇÑ °´Ã¼ ¶Ç´Â ´Ù¸¥ °´Ã¼¿¡ ÀÇÇØ Àç È°¿ë µÇ¾ú´Ù.
5. Online Segment Shrink¿Í °ü·ÃµÈ Á¦¾à»çÇ×
ASSMÀÇ ¼¼±×¸ÕÆ®´Â shrink °¡´ÉÇÏ´Ù. ±×·¯³ª, ASSM Å×ÀÌºí½ºÆäÀ̽º¿¡ À§Ä¡ÇÏ´Â °´Ã¼
°¡¿îµ¥ ´ÙÀ½°ú °°Àº °´Ã¼¿¡´Â Á¦¾à»çÇ×ÀÌ µû¸¥´Ù :
1) Ŭ·¯½ºÅÍ¿¡ ¼ÓÇÏ´Â Å×À̺í
2) long Ä÷³À» Æ÷ÇÔÇÑ Å×À̺í
3) on-commit materialized view¿Í ¿¬°üµÈ Å×À̺í
4) rowid based materialized view¿Í ¿¬°üµÈ Å×À̺í
5) Lob index
6. Shrink ¼öÇà½Ã ÀÇÁ¸ °ü°è °ü¸®¿Í Á¦¾à»çÇ×
¼¼±×¸ÕÆ®¸¦ shrink Çϴµ¿¾È, °í·ÁµÇ´Â À¯ÀÏÇÑ ÀÇÁ¸ °ü°è´Â, Å×À̺í - À妽º°£ °ü°èÀÌ´Ù.
À妽º´Â, shrink ÈÄ¿¡µµ unusable »óÅ·Π³²Áö ¾Ê´Â´Ù.
¼¼±×¸ÕÆ® shink¸¦ °úÁ¤¿¡¼ ¾ÐÃà (compaction)´Ü°è´Â insert/delete ÀÛ¾÷À» ½ÖÀ¸·Î ó¸®ÇÏ¿©
ÀÌ·ç¾îÁø´Ù. DML trigger´Â µ¥ÀÌÅ͸¦ À̵¿ÇÏ´Â ´Ü°è¿¡¼´Â È£ÃâµÇÁö ¾Ê´Â´Ù. µ¥ÀÌÅÍÀÇ ³»¿ëÀÌ
º¯°æµÇ´Â °ÍÀÌ ¾Æ´Ï¹Ç·Î, trigger°¡ È£Ãâ µÉ ÇÊ¿ä°¡ ¾ø´Ù.
ROWID¿¡ ±â¹ÝÀ» µÐ trigger´Â, shrink¸¦ Çϱâ Àü disable ½ÃÄÑ¾ß Çϴµ¥ ÀÌ°ÍÀº shink Çϴµ¿¾È
Æ®¸®°Å°¡ È£Ãâ µÇÁö ¾Êµµ·Ï Çϱâ À§ÇؼÀÌ´Ù.
on-commit materialized view¿Í ¿¬°üµÈ ¼¼±×¸ÕÆ®´Â shrink ½Ãų ¼ö ¾ø´Ù.
Primary key¸¦ ±â¹ÝÀ¸·Î ÇÑ materialized view´Â, shrink¸¦ ½ÃŲ ÀÌÈÄ¿¡ refresh ¶Ç´Â rebuild
ÇÒ ÇÊ¿ä°¡ ¾ø´Ù.
ÇÏÁö¸¸, rowid¿¡ ±â¹ÝÀ» µÐ materialized view¿¡ ´ëÇؼ´Â refresh ¶Ç´Â rebuild¸¦ ¼öÇàÇØ ÁÖ¾î¾ß
ÇÑ´Ù.
7. °¡¿ë¼º
¼¼±×¸ÕÆ® shrink´Â, ¿Â¶óÀÎÁß¿¡ ¼öÇàµÉ ¼ö ÀÖ´Ù. µû¶ó¼, °´Ã¼¿¡ ´ëÇÑ °¡¿ë¼ºÀÌ Çâ»ó µÇ¾ú´Ù.
DML ÀÛ¾÷Àº ¼¼±×¸ÕÆ® shrink Áß¿¡µµ ¼öÇà °¡´ÉÇϳª, parallel DMLÀ» ¼öÇàµÉ ¼ö ¾ø´Ù.
¼¼±×¸ÕÆ®¸¦ shrink ½ÃÅ°´Âµ¿¾È µ¥ÀÌÅÍ´Â ¾ÐÃà(compaction) ´Ü°è¿¡¼ À̵¿À̵ȴÙ. ¾ÐÃà ´Ü°è°¡ ÁøÇàµÇ´Â
µ¿¾È °³º° row ¶Ç´Â µ¥ÀÌÅÍ ºí·°¿¡ ´ëÇÑ lockÀÌ »ç¿ëµÈ´Ù.
ÀÌ »óȲÀº, lockÀ» ÀÌ¿ëÇØ, update³ª delete¿Í °°Àº concurrent DMLÀÌ ¼öÇàµÇ´Â »óȲ°ú À¯»çÇÏ´Ù.
¾ÐÃàÀº, ÀÛÀº Æ®·£Àè¼Ç ´Ù´µ·Î ¼öÇàµÇ¹Ç·Î, °´Ã¼¿¡ ´ëÇÑ °¡¿ë¼ºÀº ½É°¢ÇÏ°Ô ¿µÇâÀ» ¹ÞÁö ¾Ê´Â´Ù.
ÇÏÁö¸¸, ¼¼±×¸ÕÆ®¸¦ shrink ½ÃÅ°´Â ƯÁ¤ ´Ü°è¿¡¼´Â (HWMÀ» Á¶Á¤ÇÏ´Â ´Ü°è), ¼¼±×¸ÕÆ®´Â, exclusive ¸ðµå·Î
lockÀÌ °É¸°´Ù.
ÀÌ ´Ü°è´Â ¸Å¿ì ªÀº ±â°£À̸ç, °´Ã¼¿¡ ´ëÇÑ °¡¿ë¼º¿¡ ¹ÌÄ¡´Â ¿µÇâÀÌ ÃÖ¼ÒÈ£ µÈ´Ù.
8. º¸¾È
¼¼±×¸ÕÆ® shrink¸¦ ¼öÇàÇϱâ À§Çؼ´Â °´Ã¼¿¡ ´ëÇؼ ALTER ½ÃÅ°´Â ±ÇÇÑ°ú µ¿µîÇÑ ±ÇÇÑÀÌ ÇÊ¿äÇÏ´Ù.
9. »ó¼¼ ¿¹Á¦
SQL> set serveroutput on
SQL> declare
2 v_unformatted_blocks number;
3 v_unformatted_bytes number;
4 v_fs1_blocks number;
5 v_fs1_bytes number;
6 v_fs2_blocks number;
7 v_fs2_bytes number;
8 v_fs3_blocks number;
9 v_fs3_bytes number;
10 v_fs4_blocks number;
11 v_fs4_bytes number;
12 v_full_blocks number;
13 v_full_bytes number;
14 begin
15 dbms_space.space_usage ('SYSTEM', 'T_SHRINK', 'TABLE', v_unformatted_blocks,
16 v_unformatted_bytes, v_fs1_blocks, v_fs1_bytes, v_fs2_blocks, v_fs2_bytes,
17 v_fs3_blocks, v_fs3_bytes, v_fs4_blocks, v_fs4_bytes, v_full_blocks, v_full_bytes);
18 dbms_output.put_line('Unformatted Blocks = '||v_unformatted_blocks);
19 dbms_output.put_line('FS1 Blocks = '||v_fs1_blocks);
20 dbms_output.put_line('FS2 Blocks = '||v_fs2_blocks);
21 dbms_output.put_line('FS3 Blocks = '||v_fs3_blocks);
22 dbms_output.put_line('FS4 Blocks = '||v_fs4_blocks);
23 dbms_output.put_line('Full Blocks = '||v_full_blocks);
24 end;
25 /
Unformatted Blocks = 0
FS1 Blocks = 0
FS2 Blocks = 1
FS3 Blocks = 1
FS4 Blocks = 3
Full Blocks = 0
PL/SQL procedure successfully completed.
SQL> alter table t_shrink shrink space compact;
alter table t_shrink shrink space compact
*
ERROR at line 1:
ORA-10636: ROW MOVEMENT is not enabled
SQL> ALTER TABLE t_shrink ENABLE ROW MOVEMENT;
Table altered.
SQL> ALTER TABLE t_shrink SHRINK SPACE COMPACT;
Table altered.
SQL> set serveroutput on
SQL> declare
2 v_unformatted_blocks number;
3 v_unformatted_bytes number;
4 v_fs1_blocks number;
5 v_fs1_bytes number;
6 v_fs2_blocks number;
7 v_fs2_bytes number;
8 v_fs3_blocks number;
9 v_fs3_bytes number;
10 v_fs4_blocks number;
11 v_fs4_bytes number;
12 v_full_blocks number;
13 v_full_bytes number;
14 begin
15 dbms_space.space_usage ('SYSTEM', 'T_SHRINK', 'TABLE', v_unformatted_blocks,
16 v_unformatted_bytes, v_fs1_blocks, v_fs1_bytes, v_fs2_blocks, v_fs2_bytes,
17 v_fs3_blocks, v_fs3_bytes, v_fs4_blocks, v_fs4_bytes, v_full_blocks, v_full_bytes);
18 dbms_output.put_line('Unformatted Blocks = '||v_unformatted_blocks);
19 dbms_output.put_line('FS1 Blocks = '||v_fs1_blocks);
20 dbms_output.put_line('FS2 Blocks = '||v_fs2_blocks);
21 dbms_output.put_line('FS3 Blocks = '||v_fs3_blocks);
22 dbms_output.put_line('FS4 Blocks = '||v_fs4_blocks);
23 dbms_output.put_line('Full Blocks = '||v_full_blocks);
24 end;
25 /
Unformatted Blocks = 0
FS1 Blocks = 0
FS2 Blocks = 0
FS3 Blocks = 0
FS4 Blocks = 2
Full Blocks = 1
PL/SQL procedure successfully completed.
SQL> ALTER TABLE t_shrink SHRINK SPACE;
Table altered.
SQL> declare
2 v_unformatted_blocks number;
3 v_unformatted_bytes number;
4 v_fs1_blocks number;
5 v_fs1_bytes number;
6 v_fs2_blocks number;
7 v_fs2_bytes number;
8 v_fs3_blocks number;
9 v_fs3_bytes number;
10 v_fs4_blocks number;
11 v_fs4_bytes number;
v_full_blocks number;
13 v_full_bytes number;
14 begin
15 dbms_space.space_usage ('SYSTEM', 'T_SHRINK', 'TABLE', v_unformatted_blocks,
16 v_unformatted_bytes, v_fs1_blocks, v_fs1_bytes, v_fs2_blocks, v_fs2_bytes,
17 v_fs3_blocks, v_fs3_bytes, v_fs4_blocks, v_fs4_bytes, v_full_blocks, v_full_bytes);
18 dbms_output.put_line('Unformatted Blocks = '||v_unformatted_blocks);
19 dbms_output.put_line('FS1 Blocks = '||v_fs1_blocks);
20 dbms_output.put_line('FS2 Blocks = '||v_fs2_blocks);
21 dbms_output.put_line('FS3 Blocks = '||v_fs3_blocks);
22 dbms_output.put_line('FS4 Blocks = '||v_fs4_blocks);
23 dbms_output.put_line('Full Blocks = '||v_full_blocks);
24 end;
25 /
Unformatted Blocks = 0
FS1 Blocks = 0
FS2 Blocks = 0
FS3 Blocks = 0
FS4 Blocks = 1
Full Blocks = 1
PL/SQL procedure successfully completed.
Example
--------------------------------------------------------------------------------
Reference Documents
--------------------------------------------------------------------------------
<Note:242090.1>
http://kr.forums.oracle.com/forums/thread.jspa?threadID=477210&tstart=30
| 18.97.9.172
|
|
|
|
|
ORA-10635: Invalid segment or tablespace type
SELECT TABLESPACE_NAME,SEGMENT_SPACE_MANAGEMENT FROM DBA_TABLESPACES;
MANUAL => [ ORA-10635 ]
create tablespace ... segment space management manual; [ ORA-10635 ] |
2014-03-19 16:28:49
|
|
|
-- Shrink a LOB segment.
ALTER TABLE table_name MODIFY LOB(lob_column) (SHRINK SPACE);
-- Shrink an IOT overflow segment.
ALTER TABLE iot_name OVERFLOW SHRINK SPACE;
-- Shrink table, index ̵̧
select c1||';' sql from table(dbms_space.asa_recommendations());
Ãâó: https://oracle-base.com/articles/10g/space-object-transaction-management-10g |
2015-06-11 17:23:41
|
|
|
ÁÖÀÇ!
SQL> alter index SCOTT.EMP_UX1 shrink space;
*
ERROR at line 1:
ORA-30036: unable to extend segment by 8 in undo tablespace 'UNDOTBS1'
Undo Tablespace ¿ë·® ¸ð´ÏÅÍ ÇÊ¿ä.
Ãß°¡ ¿¡·¯
SQL> alter table SCOTT.EMP shrink space;
alter table SCOTT.EMP shrink space
*
ERROR at line 1:
ORA-10662: Segment has long columns
Cause: Shrink was issued on a segment with long columns. This is not supported. |
2015-06-12 17:34:42
|
Copyright 1999-2024 Zeroboard / skin by ÃÖ±æÈ£(gilho.kr@gmail.com)
|
|
|