How Oracle delete table records release form and table space size

See table 1. The space occupied:
the SELECT SEGMENT_NAME,
       TABLESPACE_NAME,
       BYTES B,
       BYTES / KB 1024,
       BYTES / 1024/1024 MB
  the FROM user_segments
 the WHERE segment_name = 'T_RL_INTG_LOGALL'
   the AND TABLESPACE_NAME = 'FMIS9999';
2. See table the actual size of the space occupied:
the SELECT the SUM (BYTES) / 1024/1024 || 'MB' = the FROM user_segments the U-TABLESPACE_NAME the WHERE 'FMIS9999';
3. See table space corresponding to a data file:
the SELECT * the FROM D the DBA_DATA_FILES the WHERE D. TABLESPACE_NAME = 'FMIS9999';
usage 4. Display space:
the SELECT A.TABLESPACE_NAME,      
       FILENUM,   
       TOTAL "TOTAL (MB)",  
       F.FREE "the FREE (MB)",
       TO_CHAR(ROUND(FREE * 100 / TOTAL, 2), ‘990.00’) “FREE%”, 
       TO_CHAR(ROUND((TOTAL - FREE) * 100 / TOTAL, 2), ‘990.00’) “USED%”,    
       ROUND(MAXSIZES, 2) “MAX (MB)”
  FROM (SELECT TABLESPACE_NAME,          
               COUNT(FILE_ID) FILENUM,        
               SUM(BYTES / (1024 * 1024)) TOTAL,          
               SUM(MAXBYTES) / 1024 / 1024 MAXSIZES      
          FROM DBA_DATA_FILES       
         GROUP BY TABLESPACE_NAME) A,     
       (SELECT TABLESPACE_NAME, ROUND(SUM(BYTES / (1024 * 1024))) FREE     
          FROM DBA_FREE_SPACE      
         GROUP BY TABLESPACE_NAME) F
 WHERE A.TABLESPACE_NAME = F.TABLESPACE_NAME
5.查看数据文件的实际使用情况:
SELECT CEIL(MAX_BLOCK * BLOCK_SIZE / 1024)
  FROM (SELECT MAX(BLOCK_ID) MAX_BLOCK
          FROM DBA_EXTENTS
         WHERE FILE_ID IN (SELECT FILE_ID
                             FROM DBA_DATA_FILES D
                            WHERE D.TABLESPACE_NAME = ‘FMIS9999’)) M,
       (SELECT VALUE / 1024 BLOCK_SIZE
          FROM V$PARAMETER
         WHERE NAME = ‘db_block_size’) B

First, create a test table t_rl_intg_logall of thousands of records, and view the amount of space 3873M
the Delete t_rl_intg_logall. View size will not change again, this time to perform select * from t_rl_intg_logall will find the speed super slow, the query result is empty, see its COST, I found to be more than 100,000. It is difficult to understand, in fact, did not release its share space reasons.
Execute alter table t_rl_intg_logall move or alter table t_rl_intg_logall move storage (initial 64k )
or alter table t_rl_intg_logall deallocate unused or alter table t_rl_intg_logall shrink space.
Note: Because the alter table t_rl_intg_logall move through the elimination of the line of migration, remove space debris, remove free space to achieve reduce the amount of space, but will result in an index on this table is not valid (because ROWID has changed, it can not be found), so you need to perform the move to rebuild the index.
Find the corresponding index table.
select index_name, table_name, tablespace_name, index_type , status, table_owner from dba_indexes WHERE table_owner = 'FMIS9999';
in accordance with the status value, reconstruction of an invalid line.
sql = 'alter index' || index_name || 'rebuild'; executed using stored procedures, little comfort.
Also note that the alter table move the process will produce a lock should be avoided during peak periods operations!
Check again that the amount of space, found very small, and execute the query again, and soon the bar.
Otherwise: truncate table t_rl_intg_logall will execute faster, but also release its share of space, I think it was after truncate statement execution will not enter oracle Recycle Bin (recylebin) sake. If the drop is not a purge table plus Recycle Bin (this data can be retrieved through the inside flashback).
Either delete or truncate the size of the corresponding data files will not change, if you want to change the data footprint size of the executable file the following statement: alter database datafile 'filename' resize size 8g redefinition of the data file (data file can not be less than the with the size of the space).
Another add some knowledge PURGE
Purge Operation:
. 1) Purge TABLESPACE tablespace_name:. Recycle empty table space for the Bin
2) Purge TABLESPACE tablespace_name User USER_NAME:. Recycle Bin Empty space specified table the user specified objects
. 3) Purge recyclebin: delete objects in the user's Recycle Bin current
4) purge dba_recyclebin:. delete all user objects in the Recycle Bin, the command to sysdba permissions
5) Drop table table_name purge:. delete an object and not on the Recycle Bin, that is permanent the deletion can not be restored with Flashback.
6) Purge index recycle_bin_object_name:. When you want to free up space in the Recycle bin, want to restore the table, you can free up space occupied by the object index to ease space pressures. Because the index is rebuilt.
Second, if some of the tables occupied by the data file of the last few blocks, you'll need to export the table or move to another table space, and then delete the table, and then shrink. But if it is moved to another table space, we need to rebuild its index.

1) SQL> alter table t_obj move tablespace t_tbs1; - move to another table tablespace

Also can be used directly to exp and imp

2) SQL> alter owner.index_name rebuild; - rebuilding the index

3) Delete the original table space
III: After table analysis can also be optimized (I have not tried)
the Analyze the Table ysgl_compile_reqsub 
Compute statistics for All the Indexes; 
it also depends on the situation, not what can be optimized, so next time have the opportunity to test a bit.
----------------
Disclaimer: This article is the original article CSDN bloggers "wangl2014", and follow CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement. .
Original link: https: //blog.csdn.net/wangl2014/article/details/84337994

Released seven original articles · won praise 1 · views 2398

Guess you like

Origin blog.csdn.net/lisizhe1989/article/details/104514981
Recommended