Home » RDBMS Server » Server Administration » How to shrink a tables size? (ORACLE 10.2)
How to shrink a tables size? [message #538140] Wed, 04 January 2012 06:58 Go to next message
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 #538143 is a reply to message #538140] Wed, 04 January 2012 07:05 Go to previous messageGo to next message
Michel Cadot
Messages: 68641
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Why some so long useless dash and empty end lines?

Quote:
How to shrink a tables size

Using ALTER TABLE SHRINK.

Regards
Michel

[Updated on: Wed, 04 January 2012 07:09]

Report message to a moderator

Re: How to shrink a tables size? [message #538144 is a reply to message #538143] Wed, 04 January 2012 07:09 Go to previous messageGo to next message
kastania
Messages: 19
Registered: May 2007
Junior Member
I have already applied the shrink command, as stated before. However I haven't gained and space.
Any other ideas?
Re: How to shrink a tables size? [message #538145 is a reply to message #538144] Wed, 04 January 2012 07:14 Go to previous messageGo to next message
Michel Cadot
Messages: 68641
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Quote:
, as stated before

Maybe but I was unable to read lines larger than 5 times the width of my screen so I ONLY read the title.
Now it took me 5 minutes to reformat your post and I have no more time to try to help you... too bad... next time keep your lines in 80 character width.

Regards
Michel
Re: How to shrink a tables size? [message #538150 is a reply to message #538145] Wed, 04 January 2012 07:32 Go to previous messageGo to next message
kastania
Messages: 19
Registered: May 2007
Junior Member
Ok.... Thanks for reformating...
Anyone else?
Why shrink doesn't work on my case? Does it have anything to do with the fact that most of my data are in the CLOB column?
Re: How to shrink a tables size? [message #538153 is a reply to message #538150] Wed, 04 January 2012 07:57 Go to previous messageGo to next message
John Watson
Messages: 8929
Registered: January 2010
Location: Global Village
Senior Member
The COMPACT keyword meant that no space was released.

Re: How to shrink a tables size? [message #538155 is a reply to message #538153] Wed, 04 January 2012 08:14 Go to previous messageGo to next message
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 #538157 is a reply to message #538155] Wed, 04 January 2012 08:19 Go to previous messageGo to next message
Michel Cadot
Messages: 68641
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Once again, keep your lines in 80 character width and format the queries. Format means slit the lines at appropriate places and indent.

That says, thanks for the feedback.

Regards
Michel
Re: How to shrink a tables size? [message #538158 is a reply to message #538155] Wed, 04 January 2012 08:21 Go to previous messageGo to next message
Michel Cadot
Messages: 68641
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Quote:
am I missing anything else?

block headers, extend headers, segment header.

Regards
Michel
Re: How to shrink a tables size? [message #538160 is a reply to message #538155] Wed, 04 January 2012 08:29 Go to previous messageGo to next message
John Watson
Messages: 8929
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 Go to previous messageGo to next message
kastania
Messages: 19
Registered: May 2007
Junior Member
Michel Cadot wrote on Wed, 04 January 2012 16:21
Quote:
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 #538162 is a reply to message #538160] Wed, 04 January 2012 08:37 Go to previous messageGo to next message
kastania
Messages: 19
Registered: May 2007
Junior Member
John Watson wrote on Wed, 04 January 2012 16:29
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';


Yes you are right... Sad
Can I undo the COMPACT option that I erroneusly used?
Re: How to shrink a tables size? [message #538164 is a reply to message #538161] Wed, 04 January 2012 08:44 Go to previous message
Michel Cadot
Messages: 68641
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
kastania wrote on Wed, 04 January 2012 15:36
Michel Cadot wrote on Wed, 04 January 2012 16:21
Quote:
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

Previous Topic: pre-allocate space for temporary tablespace?
Next Topic: Need to know the status of the Anonymous Block program
Goto Forum:
  


Current Time: Fri Apr 19 15:41:58 CDT 2024