Solutions to ora-03297 (tablespace cannot be recycled) Problems

Source: Internet
Author: User

In solving the problem of full disk space and tablespace recovery of the business letter project, encountered a ora-03297 error prompt, the solution is summarized as follows:
In actual use, we often encounter that a tablespace in Oracle occupies a large amount of space while the data volume occupies only a small amount of space. In this case, we can use alter database datafile '***. dbf'resize NNM command to shrink the tablespace, but during the contraction process encountered a ora-03297 error, indicating that there is data after the defined space, cannot contract.
Method 1,Estimate the space usage of each data file in the tablespace:
A. SQL> SELECT FILE #, name from V $ datafile;

B. SQL> select max (block_id) from dba_extents where file_id = 11;

Max (block_id)
-------------
2560000

SQL> show parameter db_block_size

Name type value
----------------------------- ------- ----------- Db_block_size integer 8192
C. SQL> select 2560000*8/1024 from dual;

2560000*8/1024
-----------
20000

This indicates that the maximum block used in the file is at 20 GB, Which is exactly at the end of the data file.
D. Find the objects in the block, delete them, and recreate them.
SQL> select T. Owner, T. segment_name, T. segment_type from dba_extents t where T. tablespace_name = 'shtd ';
E. shrink the tablespace.
SQL> alter database datafile '/data/shtd/users01.dbf' resize 1024 m;

Database altered.
Repeat Step B -- d until the maximum block is approximately the same as the space used.
Summary: if a large number of database objects exist in the tablespace, this method is too slow. At the same time, the authorization of the objects is lost due to the reconstruction after deletion, and other users cannot operate on the objects.

Method 2,Locate all objects in the block and delete and recreate the object.

SQL> select * From dba_extents where block_id = (select max (block_id) from dba_extents where file_id = 11 );

Method 3,If some tables occupy the last part of the data file, you must first export or move the table to another tablespace, then delete the table, and then contract it. However, if you want to move to another tablespace, you need to re-create its index.

SQL> ALTER TABLE t_obj move tablespace t_tbs1;

Disadvantage: after the table is removed, the table's indexes are not removed together, if the table has a primary key or unique index will not be able to delete the tablespace, A ORA-02429 error will occur.
Solution: Delete the table constraints. Alter table tablename drop constraint con_name;

Method 4,Use the exp tool to export the entire tablespace, delete the tablespace, recreate the home space, and then import it.
[Oracle @ shtdtest shtd] $ exp username/password @ shtd file = users. dmp tablespaces = users
Connect to: Oracle9i Enterprise Edition Release 9.2.0.4.0-Production
With the partitioning, OLAP and Oracle Data Mining options
Jserver release 9.2.0.4.0-Production
The zhs16gbk and al16utf16 nchar character sets have been exported.

Will export the selected tablespace...
Used for table space shtd...
. Exporting cluster definition...
. Exporting table definition...

... Exporting row tb_chk_detail 0
... The table tb_chk_item 0 is being exported.
... The table tb_chk_result 0 is being exported.
... The table tb_contact 0 is being exported.
... The table tb_contract 0 row is being exported.
.. Export table tb_cust_biz 0 row exported
.. Row tb_cust_info 0 is being exported.
.. Row tb_cust_profile 0 is being exported
.. Row tb_cust_reg 0 is being exported
.
.
.
. The reference integrity constraints are being exported.
. Exporting trigger...
The export is successfully terminated without warning.

SQL> drop tablespace shtd including contents and datafiles;
SQL> Create tablespace shtd datafile '/data/shtd/shtd01.dbf' size1024m extent management local segment space management auto;

[Oracle @ shtdtest shtd] $ imp

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.