How to shrink a tables size? [message #538140] |
Wed, 04 January 2012 06:58 |
kastania
Messages: 19 Registered: May 2007
|
Junior Member |
|
|
I have a table
desc STG_XML
Name Null Type
------------------------------ -------- ------------------------
ENTITY_ID NOT NULL VARCHAR2(100 CHAR)
ENTITY_TYPE_ID NOT NULL NUMBER
SOURCE_ID NOT NULL VARCHAR2(512 CHAR)
XML_SCHEMA_ID NOT NULL NUMBER
JOB_ID NOT NULL NUMBER
FINGERPRINT NOT NULL VARCHAR2(100 CHAR)
ENTITY_XML_DATA CLOB()
ARCHIVED NUMBER(1)
CREATION_DATE TIMESTAMP(6)
MODIFICATION_DATE TIMESTAMP(6)
ARCHIVING_DATE TIMESTAMP(6)
CREATED_BY VARCHAR2(50 CHAR)
MODIFIED_BY VARCHAR2(50 CHAR)
The problem is that the data of the table are 40GB while on the DB the table holds 400GB! How can I shrink and reuse that space except from drop/recreate and drop/import? How can I prevent this situation from happening?
The table has no initial data, so that I can play with the INITIAL parameter. Data are inserted, updated and deleted all the time.
I have run DBMS_ADVISOR which recommented to SHRINK table. I have performed the shrink : alter table STG_XML shrink space COMPACT; but I haven't gained any space.
Why?
What shall I do?
[Updated on: Wed, 04 January 2012 07:11] by Moderator Report message to a moderator
|
|
|
|
|
|
|
|
Re: How to shrink a tables size? [message #538155 is a reply to message #538153] |
Wed, 04 January 2012 08:14 |
kastania
Messages: 19 Registered: May 2007
|
Junior Member |
|
|
I think I have found why this discrepancy occurs.
It is my fault...
Please tell me if I am right.
I run
select sum(bytes)/1024 SIZE_KB, SEGMENT_NAME
from user_segments group by SEGMENT_NAME order by SIZE_KB desc;
Result: 400GB
and
select TABLE_NAME, ROUND((AVG_ROW_LEN * NUM_ROWS / 1024), 2) SIZE_KB
from USER_TABLES order by SIZE_KB desc;
Result: 40GB
I concluded that there was unused space.(WRONG)
I performed shrink compact, shrink space and rerun the commands. No big difference.
I created a new table as select the new one and rerun the commands. That was when I noticed that the second query in the new table resulted NULL, and it then came to me...I MUST REESTIMATE STATISTICS... daaaaaa
I estimated statistics and now after rerunning the commands the difference between the two results is 41MB.
am I missing anything else?
[Updated on: Wed, 04 January 2012 08:17] by Moderator Report message to a moderator
|
|
|
|
|
Re: How to shrink a tables size? [message #538160 is a reply to message #538155] |
Wed, 04 January 2012 08:29 |
John Watson
Messages: 8962 Registered: January 2010 Location: Global Village
|
Senior Member |
|
|
Quote:am I missing anything else? I'm afraid you are!
It is nothing to do with statistics. It is your use of COMPACT. Try this if you want to prove it:
create table t1(c2 varchar2(10));
alter table t1 enable row movement;
insert into t1 select '1234567890' from dual connect by level < 1000000;
select bytes from user_segments where segment_name='T1';
delete from t1;
alter table t1 shrink space compact;
select bytes from user_segments where segment_name='T1';
alter table t1 shrink space;
select bytes from user_segments where segment_name='T1';
|
|
|
Re: How to shrink a tables size? [message #538161 is a reply to message #538158] |
Wed, 04 January 2012 08:36 |
kastania
Messages: 19 Registered: May 2007
|
Junior Member |
|
|
Michel Cadot wrote on Wed, 04 January 2012 16:21Quote:am I missing anything else?
block headers, extend headers, segment header.
Regards
Michel
If you want to help, be more specific and detailed, else please help someone else, that appreciates irony.
I'll be more carefull when pasting code
|
|
|
|
Re: How to shrink a tables size? [message #538164 is a reply to message #538161] |
Wed, 04 January 2012 08:44 |
|
Michel Cadot
Messages: 68729 Registered: March 2007 Location: Saint-Maur, France, https...
|
Senior Member Account Moderator |
|
|
kastania wrote on Wed, 04 January 2012 15:36Michel Cadot wrote on Wed, 04 January 2012 16:21Quote:am I missing anything else?
block headers, extend headers, segment header.
Regards
Michel
If you want to help, be more specific and detailed, else please help someone else, that appreciates irony.
I'll be more carefull when pasting code
If you don't understand do not name it irony, just say you don't understand.
Regards
Michel
|
|
|