Skip to Main Content
  • Questions
  • how to decrease the database table size

Breadcrumb

Question and Answer

Connor McDonald

Thanks for the question, Santhosh.

Asked: April 05, 2017 - 12:28 pm UTC

Last updated: April 09, 2017 - 9:25 am UTC

Version: 12c

Viewed 10K+ times! This question is

You Asked

to reduce the size of the overall db space, we are deleting unused rows/data from our tables which occupies more memory. But even after deleting around half of the existing rows, the memory size didnot decrease but increase.

Before delete:

Rows in table: 1.8 crore records

Space occupied: 1.77GB

After Delete:

Rows in table: 1 crore records

Space occupied: 6.91GB

Space occupied is retrieved from "select segment_name,segment_type,(bytes/1073741824) as memory_in_gb from dba_segments"

is ther some other way to actually reduce the memory occupied by table. also why even after deleting rows the space occupied increased.

DDL:

CREATE TABLE table_1
(
TABLE_1_ID NUMBER(18) NOT NULL
, LAST_UPDATE_DATE TIMESTAMP(6) NOT NULL
, LAST_UPDATED_BY VARCHAR2(64) NOT NULL
, CREATION_DATE TIMESTAMP(6) NOT NULL
, CREATED_BY VARCHAR2(64) NOT NULL
, CONSTRAINT table_1_PK PRIMARY KEY
(
TABLE_1_ID
)
DISABLE
)
LOGGING
TABLESPACE "TABLESPACE_1"
PCTFREE 10
PCTUSED 60
INITRANS 1
STORAGE
(
INITIAL 131072
NEXT 131072
MINEXTENTS 1
MAXEXTENTS 2147483645
PCTINCREASE 0
FREELISTS 4
FREELIST GROUPS 32
BUFFER_POOL DEFAULT
);

COMMENT ON TABLE ..................

CREATE INDEX table_1_N1 ON table_1 (table_1_f_ID, DATE_1)
LOGGING
TABLESPACE ""Default""
PCTFREE 40
INITRANS 11
STORAGE
(
INITIAL 4096
NEXT 1
MINEXTENTS 1
MAXEXTENTS 2147483645
PCTINCREASE 0
FREELISTS 4
FREELIST GROUPS 32
BUFFER_POOL DEFAULT
);



CREATE UNIQUE INDEX table_1_U1 ON table_1 (table_1_ID)
TABLESPACE ""Default""
STORAGE
(
BUFFER_POOL DEFAULT
);

and Connor said...

By default, we dont free up the space for *other* objects, that space will be re-used by the *same* table as it grows again.

If you are not expecting that table to grow, then you can doing the following:

alter table table_1 move;
alter index table_1_N1 rebuild;
alter index table_1_U1 rebuild;

This is the most efficient means, but will lock the table. If you need to keep access available then you can do:

alter table table_1 shrink space;
alter index table_1_N1 coalesce;
alter index table_1_U1 coalesce;

More good info here

https://asktom.oracle.com/pls/apex/f?p=100:11:::NO:RP:P11_QUESTION_ID:9527343800346989243



Is this answer out of date? If it is, please let us know via a Comment