Shrinking segments
Posted by carl.reitschuster on 8th September 2006
Hi reader,
with oracle 10.2 you have something like a segment fragment which could release space not needed anymore. First you enable row movement to enable reorganization. Then you start to shrink. With the dba_segments view you can query the segment properties of your table or index.
SELECT Us.Segment_Name,
Us.Segment_Type,
Us.Bytes,
Us.Blocks
FROM User_Segments Us
WHERE Us.Segment_Name = ‘EVENTLOG’;
SQL>
SQL> SELECT Us.Segment_Name,
2 Us.Segment_Type,
3 Us.Bytes,
4 Us.Blocks
5 FROM User_Segments Us
6 WHERE Us.Segment_Name = ‘EVENTLOG’
7 ;SEGMENT_NAME SEGMENT_TYPE BYTES BLOCKS
——————————————- —————— ———- ———-
EVENTLOG TABLE 84934656 10368SQL>
Like a diskdefragmenter must be able to move disk blocks of a file the table defragmentation only works effective if rows are allowed to be moved from one oracle block to another. This means the rowid of a table row changes.
ALTER TABLE EVENTLOG ENABLE ROW MOVEMENT;
ALTER TABLE EVENTLOG SHRINK SPACE;
SQL> ALTER TABLE EVENTLOG ENABLE ROW MOVEMENT;
Table altered
SQL> ALTER TABLE EVENTLOG SHRINK SPACE;
Table altered
SQL>
In this example the number blocks could be reduced from 10368 to 128! Also this means that the high water mark which is the end position of the Full Table Scan is reseted too causing reduced resource usage for Full Table Scans.
SQL>
SQL> SELECT Us.Segment_Name,
2 Us.Segment_Type,
3 Us.Bytes,
4 Us.Blocks
5 FROM User_Segments Us
6 WHERE Us.Segment_Name = ‘EVENTLOG’
7 ;
SEGMENT_NAME SEGMENT_TYPE BYTES BLOCKS
——————————————- —————— ———- ———-
EVENTLOG TABLE 1048576 128
SQL>
How do you detect candidates for shrinking? simply look into Segment Advisor Recommendations of the database Homepage of the DbConsole or do this by SQL using the Dba_Advisor_Findings view :
SELECT Daf.Task_Id,
Daf.Finding_Id,
Daf.Task_Name,
Daf.TYPE,
Daf.Object_Id,
Daf.Message
FROM Dba_Advisor_Findings Daf
WHERE Daf.Task_Name LIKE ‘SYS_AUTO_SPCADV%’
AND Message LIKE ‘%EVENTLOG%’;
SQL>
SQL> SELECT Daf.Task_Id,
2 Daf.Finding_Id,
3 Daf.Task_Name,
4 Daf.TYPE,
5 Daf.Object_Id,
6 Daf.Message
7 FROM Dba_Advisor_Findings Daf
8 WHERE Daf.Task_Name LIKE ‘SYS_AUTO_SPCADV%’
9 AND Message LIKE ‘%EVENTLOG%’
10 ;TASK_ID FINDING_ID TASK_NAME TYPE OBJECT_ID MESSAGE
———- ———- —————————— ———– ———- ——————————————————————————–
14837 10 SYS_AUTO_SPCADV_250201882006 INFORMATION 28 Zeilenverschiebung der Tabelle EVENTLOG aktivieren und Verkleinerung vorneh
14870 11 SYS_AUTO_SPCADV_25041982006 INFORMATION 28 Zeilenverschiebung der Tabelle EVENTLOG aktivieren und Verkleinerung vorneh
15127 7 SYS_AUTO_SPCADV_410202182006 INFORMATION 23 Zeilenverschiebung der Tabelle EVENTLOG aktivieren und Verkleinerung vorneh
15228 1 SYS_AUTO_SPCADV_921202282006 INFORMATION 1 Zeilenverschiebung der Tabelle EVENTLOG aktivieren und Verkleinerung vornehSQL>
HTH Karl
Links
Posted in 10.2, SQL | No Comments »