Current location - Health Preservation Learning Network - Healthy weight loss - How does Oracle release the size of tables and tablespaces by deleting records in tables?
How does Oracle release the size of tables and tablespaces by deleting records in tables?
solution

carry out

Alter? Table? jk_test? Moving or something?

Alter? Table? jk_test? Moving? Storage (initial? 64k) or

Alter? Table? jk_test? De-allocation? Never used it or not?

Alter? Table? jk_test? Shrinkage? Space. Note: alter table jk_test move reduces the occupied space by eliminating row migration, clearing space fragmentation and deleting free space, which will lead to the invalid index on the table (because the ROWID has changed and cannot be found), so it is necessary to rebuild the index to perform move.

Find the index corresponding to the table.

Choice? Index Name, Table Name, Tablespace Name, Index Type, Status? From where? dba_indexes? Where is it? Table_owner='SCOTT' According to the value of status, only invalid ones are rebuilt. SQL = ' alter index ' | | index _ name | | ' rebuild '; It's a little comforting to use stored procedures to execute.

Also note that locks will be generated in the process of alter table move, so avoid operating during peak business hours!

Also note: truncate table jk_test will be executed faster and the occupied space will be released, which should be because the truncate statement will not enter oracle recylebin after execution. If you delete a table and add purge, it will not enter the recycle bin (the data in it can be retrieved through flashback).

Whether it is deleted or truncated, the size of the corresponding data file will not change. If you want to change the space occupied by the data file, you can execute the following statement:

Alter? Database? Data file? File name? Resize? 8g Redefine the size of the data file (not less than the size of the used space of the data file).

Add some purge knowledge. Cleaning operation:

1). Clear tablespace tablespace _ name: the recycle bin used to empty the tablespace.

2). Clear Tablespace Tablespace Name User Name: Clear the object of the specified user in the recycle bin of the specified tablespace.

3). Clear Recycle Bin: Delete the objects in the Recycle Bin of the current user.

4). Clear dba _ Recycle Bin: Delete the objects in all users' Recycle Bin. This command requires sysdba privileges.

5). Delete table table_name Clear:? Deleting an object, without putting it in the recycle bin, is permanently deleted and cannot be restored by flashback.

6). Clear the index recycle _ bin _ object _ name: When you want to release the space of the recycle bin and restore the table, you can relieve the space pressure by releasing the space occupied by the index of the object. Because the index can be rebuilt.

2. If some tables occupy the last block of the data file, you need to export or move these tables to other tablespaces first, then delete these tables and shrink them. However, if you move to another tablespace, you need to rebuild its index.

1、

SQL & gt? Alter? Table? t_obj? Moving? Tablespace t _ TBS 1; -You can also use exp and imp to move tables directly to other tablespaces.

2、

SQL> altered? owner.index_name? Reconstruction; ? -Rebuild index 3. Delete the original tablespace.