Oracle delete data after the release of the data file occupies disk space

Oracle delete data after the release of the data file share disk space
when inserted into a large amount of test data into the database, the test is completed the test user and delete all its data, but the data file has not narrowed. This was after the access to information that is Oracle "high water" caused, then how the size of the data files down it? Solution is as follows:

concept:

Knowledge of table space, see here, a detailed description of the storage structure Oracle database.

High water level: High Water Mark (HWM), it is an indicator segment (Segment), defines the block level segment (Segment) has been configured before.

It is said that, with the insert data, using the segment (Segment) a data block (data block) is increasing, this time the high level (the HWM) along with the rise. When (either delete or truncate table), although the data is deleted occupied data blocks (data block) have been reduced accordingly, but the high level (the HWM) and does not fall. When a large amount of blank data block (data block) in the presence of a high level (HWM), if the full table scan (Full Table Scan, FTS) will cause the occurrence of a lot of extra IO. Because the data block (data block) in a full table scan (FTS) when reading segment (Segment) will always be read into the high level (the HWM) until the end. High water level (HWM) is a segment (Segment) a data block (data block) there is no dividing line use, so the time a full table scan (FTS) takes not only will not delete data is reduced, it will increase. (About the content of this section query efficiency to be verified, the author is not personally verify, but it is certain that the high water level does not decline as deleting data.)

Reduce the high level of correct approach is to first reduce the HWM, and then determine the size of actual possession, and then resize the data file.

More data files, which we use as a large file Demo, other data files to do the same. I selected file is: D: \ oracle \ product \ 10.2.0 \ oradata \ orcl \ about USERS01.DBF 1.4GB.

1. Log in sqlplus:

语法:sqlplus username/password@hostname:port/sid

例:sqlplus system/orcl@localhost:1521/orcl

2. Query the number of data files:

SQL> select file#, name from v$datafile;

FILE# NAME

1 D:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\SYSTEM01.DBF

2 D:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\UNDOTBS01.DBF

3 D:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\SYSAUX01.DBF

4 D:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\USERS01.DBF

We can see, our number of data files to operate on four.

The file ID number query this data file maximum data block (data block) :( It seems that this is the largest number may represent the number of data blocks in the data file, which is to be verified.)

SQL> select max(block_id) from dba_extents where file_id=4;

MAX(BLOCK_ID)

65673

3. Calculate the space occupied by the actual table space:

- query data block size, byte units

SQL> select value from v$parameter where name=‘db_block_size’

NAME TYPE VALUE


db_block_size integer 8192

–8192 byte = 8 kb

- Next, calculation of physical space occupied space

SQL> select 65673 * 8 / 1024 from dual;

65673*8/1024

513.070313

- the actual physical space occupied by a 513MB multipoint

4. The final step, the size of the data files to modify our physical space than the big point of this table space actually occupied on the line:

SQL> alter database datafile ‘D:\oracle\product\10.2.0\oradata\orcl\USERS01.DBF’ resize 600m;

Database has changed.

OK, the data from the file into a 600MB 1.4GB before the amendment. For other data files, we also know how to shrink it?

Released seven original articles · won praise 1 · views 2379

Guess you like

Origin blog.csdn.net/lisizhe1989/article/details/104514999