Oracle tablespace shrinking Scheme

Source: Internet
Author: User
For Table space shrinking, Oracle only provides the extended function, but does not. Therefore, to achieve this requirement, you must first create an intermediate tablespace and then

For Table space shrinking, Oracle only provides the extended function, but does not. Therefore, to achieve this requirement, you must first create an intermediate tablespace and then

Application background:
In some cases, because the preliminary design is not fully considered, the tablespace pre-creation is too large, far exceeding the actual size. As a result, the need to shrink the space occupied by the tablespace arises.

Solution:
For Table space shrinking, Oracle only provides the extended function, but does not. Therefore, to achieve this requirement, you must first create an intermediate tablespace, and then migrate the data in the tablespace to this tablespace.

Solution:
1. Find all data objects in the tablespace;
Select segment_type, partition_name, segment_name from dba_segments;

2. Create a target space (not mandatory, but recommended ).
Create tablespace dbs_temp datafile 'd: \ dbs_temp01.dbf' size 100 m;

3. Rebuilding or transferring the corresponding data based on the object type;
For table:
Alter table xx move tablespace dbs_temp;
For partition table:
Alter table xx move partition xx1 tablespace dbs_temp;
For index:
Alter index ixx rebuild tablespace dbs_temp;
For the lob field:
Alter table xx move lob (col_name) store as (tablespace dbs_temp );

In general, the following statement can basically cover all data objects:
Select segment_type, segment_name, partition_name,
Case segment_type
When 'table' then 'alter table' | owner | '.' | segment_name | 'move tablespace dbs_temp ;',
When 'index' then 'alter Index' | owner | '.' | segment_name | 'rebuild tablespace dbs_temp ;',
When 'index partition' then 'alter Index' | owner | '.' | segment_name | 'rebuild tablespace dbs_temp ;',
When 'table partition' then 'alter table' | owner | '.' | segment_name | 'move partition' | partition_name | 'tablespace dbs_temp; 'sqltext
From dba_segments
Where tablespace_name = 'Fund _ table'
And segment_type not like 'lob % ';

The following figure shows how to migrate the lob field.
Select table_name, column_name, 'alter table' | owner | '. '| table_name | 'move lob (' | column_name | ') store as (tablespace dbs_temp); 'sqltext
From dba_lobs
Where tablespace_name = 'Fund _ table ';

4. Delete the cleared tablespace;
Drop tablespace dbs_old including contents and datafiles;
The following steps are simple.

5. If the table space name is required, use the original tablespace name to create a suitable tablespace.

6. migrate the data in the destination tablespace back to the created tablespace.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.