验证:oracle delete 数据库空间是可以重新被使用的

SQL> create tablespace itdba_1 datafile '/u01/ora11g/itdba/oradata/d11g/itdba1.dbf' size 200M autoextend off;
Tablespace created.
SQL> select name from v$datafile;
NAME
--------------------------------------------------------------------------------
/u01/ora11g/itdba/oradata/d11g/system01.dbf
/u01/ora11g/itdba/oradata/d11g/sysaux01.dbf
/u01/ora11g/itdba/oradata/d11g/undotbs01.dbf
/u01/ora11g/itdba/oradata/d11g/users01.dbf
/u01/ora11g/itdba/oradata/d11g/example01.dbf
/u01/ora11g/itdba/oradata/d11g/itdba1.dbf
6 rows selected.
SQL> create table t_itdba_1 tablespace itdba_1 as select * from dba_extents;
Table created.

创建表空间,创建表。

SQL> insert into t_itdba_1 select /* +append */ * from t_itdba_1 nologging;
9883 rows created.
SQL> /
19766 rows created.
SQL> /
39532 rows created.

初始化数据

SQL>  select bytes/1024/1024 ,segment_name from dba_segments where segment_name='T_ITDBA_1';
BYTES/1024/1024 SEGMENT_NAME
--------------- ------------------------------
            104 T_ITDBA_1
Elapsed: 00:00:00.01
SQL> delete from T_ITDBA_1;
1265024 rows deleted.
Elapsed: 00:00:35.68
SQL> commit;

数据统计:

SQL>  select bytes/1024/1024 ,segment_name from dba_segments where segment_name='T_ITDBA_1';
BYTES/1024/1024 SEGMENT_NAME
--------------- ------------------------------
            104 T_ITDBA_1

数据存储空间没有变化:

SQL>  insert into t_itdba_1 select * from dba_extents nologging;
10087 rows created.
Elapsed: 00:00:12.84
SQL>  insert into t_itdba_1 select /* +append */ * from t_itdba_1 nologging;
10087 rows created.
Elapsed: 00:00:00.13
SQL> /
20174 rows created.
Elapsed: 00:00:00.18
SQL> /
SQL> select bytes/1024/1024 ,segment_name from dba_segments where segment_name='T_ITDBA_1';
BYTES/1024/1024 SEGMENT_NAME
--------------- ------------------------------
            104 T_ITDBA_1

数据的占用的空间的的确确没有增加,如果,但是为什么有的表却不断的在浪费空间,形成碎片呢?

SQL> update T_ITDBA_1 set OWNER='aaaaaaaaaaaaaaaaaaaaaaaaaaa';
1291136 rows updated.
Elapsed: 00:01:27.36
SQL> commit;
Commit complete.
Elapsed: 00:00:00.00
SQL> select bytes/1024/1024 ,segment_name from dba_segments where segment_name='T_ITDBA_1';
BYTES/1024/1024 SEGMENT_NAME
--------------- ------------------------------
            136 T_ITDBA_1
SQL>  update T_ITDBA_1 set OWNER='aaaaaaaaaaaaaaaaaaaaaaaaab';
1291136 rows updated.
Elapsed: 00:01:14.79
SQL> commit;
Commit complete.
Elapsed: 00:00:00.00
SQL> select bytes/1024/1024 ,segment_name from dba_segments where segment_name='T_ITDBA_1';

BYTES/1024/1024 SEGMENT_NAME
--------------- ------------------------------
            136 T_ITDBA_1
Elapsed: 00:00:00.06
SQL> update T_ITDBA_1 set SEGMENT_NAME='abcde000000000000000000000';
1291136 rows updated.
Elapsed: 00:01:32.36
SQL> commit;
Commit complete.
Elapsed: 00:00:00.00
SQL> select bytes/1024/1024 ,segment_name from dba_segments where segment_name='T_ITDBA_1';
BYTES/1024/1024 SEGMENT_NAME
--------------- ------------------------------
            144 T_ITDBA_1
Elapsed: 00:00:00.06
SQL> 

更新会使用到更多的数据,那么也就会占用更多的空间。那么这个时候是否有有表链 这种情况呢?

SQL>  exec dbms_stats.gather_table_stats(user,'T_ITDBA_1');
PL/SQL procedure successfully completed.
Elapsed: 00:00:04.99
SQL> select table_name,
  2         num_rows,
  3         CHAIN_CNT,
  4         ROUND((CHAIN_CNT / num_rows) * 100, 2) as "RT%"
  5    from dba_tables
  6   where table_name = 'T_ITDBA_1';

TABLE_NAME                       NUM_ROWS  CHAIN_CNT        RT%
------------------------------ ---------- ---------- ----------
T_ITDBA_1                         1291136          0          0

Elapsed: 00:00:00.06

经过查询,没有产生链表!那么这种更新,很有可能数据直接转移到新的块上还是?这种现象到底什么原因呢?对于这个问题,我重新实验

SQL> drop table T_ITDBA_1;
Table dropped.
Elapsed: 00:00:02.24
SQL> create table t_itdba_1 tablespace itdba_1 as select * from dba_extents;
Table created.
Elapsed: 00:00:16.58
SQL> exec dbms_stats.gather_table_stats(user,'T_ITDBA_1');
PL/SQL procedure successfully completed.
Elapsed: 00:00:00.23
SQL> select bytes/1024 ,segment_name from dba_segments where segment_name='T_ITDBA_1';
BYTES/1024 SEGMENT_NAME
---------- ------------------------------
       896 T_ITDBA_1
Elapsed: 00:00:00.25
SQL> 

查询该表数据行于数据块之间的对应关系


     75159          6      18589              87
     75159          6      18620             110
     75159          6      18626             108
     75159          6      18635              76
     75159          6      18657              97
     75159          6      18574             129
     75159          6      18577             132
     75159          6      18582             120

 OBJECT_ID    FILE_ID   BLOCK_ID COUNT(BLOCK_ID)
---------- ---------- ---------- ---------------
     75159          6      18588             127
     75159          6      18598              90
     75159          6      18604              78
     75159          6      18616             104
     75159          6      18617             107
     75159          6      18627             105

数据很多,我把它存放到一张表里

SQL> create table t_itdba_01 as
select object_id, file_id, block_id, count(block_id) countt
  2    3    from (select rowid,
               dbms_rowid.rowid_object(rowid) object_id,
               dbms_rowid.rowid_relative_fno(rowid) file_id,
               dbms_rowid.rowid_block_number(rowid) block_id
  4    5    6    7            FROM T_ITDBA_1)
  8   group by object_id, file_id, block_id;
Table created.
Elapsed: 00:00:00.55
SQL> update T_ITDBA_1 set SEGMENT_NAME='abcde000000000000000000000';
10294 rows updated.
Elapsed: 00:00:00.26
SQL> commit;
Commit complete.
Elapsed: 00:00:00.05
SQL>  exec dbms_stats.gather_table_stats(user,'T_ITDBA_1');
PL/SQL procedure successfully completed.
Elapsed: 00:00:00.21
SQL> select table_name,
  2         num_rows,
  3         CHAIN_CNT,
  4         ROUND((CHAIN_CNT / num_rows) * 100, 2) as "RT%"
  5    from dba_tables
  6   where table_name = 'T_ITDBA_1';

TABLE_NAME                       NUM_ROWS  CHAIN_CNT        RT%
------------------------------ ---------- ---------- ----------
T_ITDBA_1                           10294          0          0

Elapsed: 00:00:00.06
SQL> select bytes/1024 ,segment_name from dba_segments where segment_name='T_ITDBA_1';

BYTES/1024 SEGMENT_NAME
---------- ------------------------------
       960 T_ITDBA_1

Elapsed: 00:00:00.01
SQL> 

占用空间增加,创建映射表

SQL> create table t_itdba_02 as
  2  select object_id, file_id, block_id, count(block_id) countt
  3    from (select rowid,
  4                 dbms_rowid.rowid_object(rowid) object_id,
  5                 dbms_rowid.rowid_relative_fno(rowid) file_id,
  6                 dbms_rowid.rowid_block_number(rowid) block_id
  7            FROM T_ITDBA_1)
  8   group by object_id, file_id, block_id;
Table created.
Elapsed: 00:00:00.51
SQL> 

比对数据

SQL> select a.block_id, b.countt - a.countt
  2    from t_itdba_01 a, t_itdba_02 b
  3   where a.block_id = b.block_id
  4     and (b.countt - a.countt) <> 0;

no rows selected

Elapsed: 00:00:00.00
SQL> 

占用的空间增加,使用的块数没增加,难道仅仅使用块的free部分,碎片到底怎么产生的,还是我测试力度不够! 也就是说,数据库什么时候会用到delete 部分的数据空间??

1 exten 分配产生,2 行连接,3 行迁移

在分配上:做个实验

update T_ITDBA_1 set owner='2dfadafsfsafdsafdsf';
SQL> select segment_name,extent_id,block_id,bytes from dba_extents   where segment_name= 'T_ITDBA_1';
SEGMENT_NAME                    EXTENT_ID   BLOCK_ID      BYTES
------------------------------ ---------- ---------- ----------
T_ITDBA_1                               0      18560      65536
T_ITDBA_1                               1      18568      65536
T_ITDBA_1                               2      18576      65536
T_ITDBA_1                               3      18584      65536
T_ITDBA_1                               4      18592      65536
T_ITDBA_1                               5      18600      65536
T_ITDBA_1                               6      18608      65536
T_ITDBA_1                               7      18616      65536
T_ITDBA_1                               8      18624      65536
T_ITDBA_1                               9      18632      65536
T_ITDBA_1                              10      18640      65536

SEGMENT_NAME                    EXTENT_ID   BLOCK_ID      BYTES
------------------------------ ---------- ---------- ----------
T_ITDBA_1                              11      18648      65536
T_ITDBA_1                              12      18656      65536
T_ITDBA_1                              13      18664      65536
T_ITDBA_1                              14      18672      65536
SQL> select segment_name,extent_id,block_id,bytes,blocks from dba_extents   where segment_name= 'T_ITDBA_1'
  2  ;

SEGMENT_NAME                    EXTENT_ID   BLOCK_ID      BYTES     BLOCKS
------------------------------ ---------- ---------- ---------- ----------
T_ITDBA_1                               0      18560      65536          8
T_ITDBA_1                               1      18568      65536          8
T_ITDBA_1                               2      18576      65536          8
T_ITDBA_1                               3      18584      65536          8
T_ITDBA_1                               4      18592      65536          8
T_ITDBA_1                               5      18600      65536          8
T_ITDBA_1                               6      18608      65536          8
T_ITDBA_1                               7      18616      65536          8
T_ITDBA_1                               8      18624      65536          8
T_ITDBA_1                               9      18632      65536          8
T_ITDBA_1                              10      18640      65536          8

SEGMENT_NAME                    EXTENT_ID   BLOCK_ID      BYTES     BLOCKS
------------------------------ ---------- ---------- ---------- ----------
T_ITDBA_1                              11      18648      65536          8
T_ITDBA_1                              12      18656      65536          8
T_ITDBA_1                              13      18664      65536          8
T_ITDBA_1                              14      18672      65536          8
T_ITDBA_1                              15      18680      65536          8
T_ITDBA_1                              16      18688    1048576        128

rowid 没有变化,但是占用的空间却变大了

SQL> select object_id, file_id, block_id, count(block_id)
  2    from (select rowid,
  3                 dbms_rowid.rowid_object(rowid) object_id,
               dbms_rowid.rowid_relative_fno(rowid) file_id,
               dbms_rowid.rowid_block_number(rowid) block_id
          FROM T_ITDBA_1)
 group by object_id, file_id, block_id
  4    5    6    7    8  ;

 OBJECT_ID    FILE_ID   BLOCK_ID COUNT(BLOCK_ID)
---------- ---------- ---------- ---------------
     75159          6      18570             119
     75159          6      18581             122
     75159          6      18584             127<pre name="code" class="html">SQL> truncate table T_ITDBA_1;

Table truncated.

Elapsed: 00:00:00.53
SQL> select segment_name,extent_id,block_id,bytes,blocks from dba_extents   where segment_name= 'T_ITDBA_1';

SEGMENT_NAME                    EXTENT_ID   BLOCK_ID      BYTES     BLOCKS
------------------------------ ---------- ---------- ---------- ----------
T_ITDBA_1                               0      18560      65536          8

Elapsed: 00:00:00.02
SQL>
SQL>
SQL> insert into T_ITDBA_1 select * from dba_extents;

10066 rows created.

Elapsed: 00:00:02.47
SQL> commit;

Commit complete.

Elapsed: 00:00:00.01
SQL> insert into T_ITDBA_1 select * from  T_ITDBA_1;

10066 rows created.

Elapsed: 00:00:00.04
SQL> /    

20132 rows created.

Elapsed: 00:00:00.05
SQL> /

40264 rows created.

Elapsed: 00:00:00.09
SQL> commit;

Commit complete.

Elapsed: 00:00:00.00
SQL> select segment_name,extent_id,block_id,bytes,blocks from dba_extents   where segment_name= 'T_ITDBA_1';

SEGMENT_NAME                    EXTENT_ID   BLOCK_ID      BYTES     BLOCKS
------------------------------ ---------- ---------- ---------- ----------
T_ITDBA_1                               0      18560      65536          8
T_ITDBA_1                               1      18568      65536          8
T_ITDBA_1                               2      18576      65536          8
T_ITDBA_1                               3      18584      65536          8
T_ITDBA_1                               4      18592      65536          8
T_ITDBA_1                               5      18600      65536          8
T_ITDBA_1                               6      18608      65536          8
T_ITDBA_1                               7      18616      65536          8
T_ITDBA_1                               8      18624      65536          8
T_ITDBA_1                               9      18632      65536          8
T_ITDBA_1                              10      18640      65536          8

SEGMENT_NAME                    EXTENT_ID   BLOCK_ID      BYTES     BLOCKS
------------------------------ ---------- ---------- ---------- ----------
T_ITDBA_1                              11      18648      65536          8
T_ITDBA_1                              12      18656      65536          8
T_ITDBA_1                              13      18664      65536          8
T_ITDBA_1                              14      18672      65536          8
T_ITDBA_1                              15      18680      65536          8
T_ITDBA_1                              16      18688    1048576        128
T_ITDBA_1                              17      18816    1048576        128
T_ITDBA_1                              18      18944    1048576        128
T_ITDBA_1                              19      19072    1048576        128
T_ITDBA_1                              20      19200    1048576        128
T_ITDBA_1                              21      19328    1048576        128

22 rows selected.

Elapsed: 00:00:00.01
SQL> update T_ITDBA_1 set owner='0';

80528 rows updated.

Elapsed: 00:00:03.28
SQL> commit;

Commit complete.

Elapsed: 00:00:00.00
SQL> select segment_name,extent_id,block_id,bytes,blocks from dba_extents   where segment_name= 'T_ITDBA_1';

SEGMENT_NAME                    EXTENT_ID   BLOCK_ID      BYTES     BLOCKS
------------------------------ ---------- ---------- ---------- ----------
T_ITDBA_1                               0      18560      65536          8
T_ITDBA_1                               1      18568      65536          8
T_ITDBA_1                               2      18576      65536          8
T_ITDBA_1                               3      18584      65536          8
T_ITDBA_1                               4      18592      65536          8
T_ITDBA_1                               5      18600      65536          8
T_ITDBA_1                               6      18608      65536          8
T_ITDBA_1                               7      18616      65536          8
T_ITDBA_1                               8      18624      65536          8
T_ITDBA_1                               9      18632      65536          8
T_ITDBA_1                              10      18640      65536          8

SEGMENT_NAME                    EXTENT_ID   BLOCK_ID      BYTES     BLOCKS
------------------------------ ---------- ---------- ---------- ----------
T_ITDBA_1                              11      18648      65536          8
T_ITDBA_1                              12      18656      65536          8
T_ITDBA_1                              13      18664      65536          8
T_ITDBA_1                              14      18672      65536          8
T_ITDBA_1                              15      18680      65536          8
T_ITDBA_1                              16      18688    1048576        128
T_ITDBA_1                              17      18816    1048576        128
T_ITDBA_1                              18      18944    1048576        128
T_ITDBA_1                              19      19072    1048576        128
T_ITDBA_1                              20      19200    1048576        128
T_ITDBA_1                              21      19328    1048576        128

22 rows selected.

Elapsed: 00:00:00.01
SQL> insert into T_ITDBA_1 select * from dba_extents;

10087 rows created.

Elapsed: 00:00:01.95
SQL> commit;

Commit complete.

Elapsed: 00:00:00.01
SQL> select segment_name,extent_id,block_id,bytes,blocks from dba_extents   where segment_name= 'T_ITDBA_1';

SEGMENT_NAME                    EXTENT_ID   BLOCK_ID      BYTES     BLOCKS
------------------------------ ---------- ---------- ---------- ----------
T_ITDBA_1                               0      18560      65536          8
T_ITDBA_1                               1      18568      65536          8
T_ITDBA_1                               2      18576      65536          8
T_ITDBA_1                               3      18584      65536          8
T_ITDBA_1                               4      18592      65536          8
T_ITDBA_1                               5      18600      65536          8
T_ITDBA_1                               6      18608      65536          8
T_ITDBA_1                               7      18616      65536          8
T_ITDBA_1                               8      18624      65536          8
T_ITDBA_1                               9      18632      65536          8
T_ITDBA_1                              10      18640      65536          8

SEGMENT_NAME                    EXTENT_ID   BLOCK_ID      BYTES     BLOCKS
------------------------------ ---------- ---------- ---------- ----------
T_ITDBA_1                              11      18648      65536          8
T_ITDBA_1                              12      18656      65536          8
T_ITDBA_1                              13      18664      65536          8
T_ITDBA_1                              14      18672      65536          8
T_ITDBA_1                              15      18680      65536          8
T_ITDBA_1                              16      18688    1048576        128
T_ITDBA_1                              17      18816    1048576        128
T_ITDBA_1                              18      18944    1048576        128
T_ITDBA_1                              19      19072    1048576        128
T_ITDBA_1                              20      19200    1048576        128
T_ITDBA_1                              21      19328    1048576        128

22 rows selected.

Elapsed: 00:00:00.02
SQL>  insert into T_ITDBA_1 select * from  T_ITDBA_1 where owner<>'0';

10087 rows created.

Elapsed: 00:00:00.03
SQL> /

20174 rows created.

Elapsed: 00:00:00.06
SQL> /

40348 rows created.

Elapsed: 00:00:00.10
SQL> /

80696 rows created.

Elapsed: 00:00:00.21
SQL> /
/

161392 rows created.

Elapsed: 00:00:00.65
SQL> /
322784 rows created.

Elapsed: 00:00:02.09
SQL> commit;
SP2-0042: unknown command "/commit" - rest of line ignored.
SQL> commit;

Commit complete.

Elapsed: 00:00:00.00
SQL> select segment_name,extent_id,block_id,bytes,blocks from dba_extents   where segment_name= 'T_ITDBA_1';

SEGMENT_NAME                    EXTENT_ID   BLOCK_ID      BYTES     BLOCKS
------------------------------ ---------- ---------- ---------- ----------
T_ITDBA_1                               0      18560      65536          8
T_ITDBA_1                               1      18568      65536          8
T_ITDBA_1                               2      18576      65536          8
T_ITDBA_1                               3      18584      65536          8
T_ITDBA_1                               4      18592      65536          8
T_ITDBA_1                               5      18600      65536          8
T_ITDBA_1                               6      18608      65536          8
T_ITDBA_1                               7      18616      65536          8
T_ITDBA_1                               8      18624      65536          8
T_ITDBA_1                               9      18632      65536          8
T_ITDBA_1                              10      18640      65536          8

SEGMENT_NAME                    EXTENT_ID   BLOCK_ID      BYTES     BLOCKS
------------------------------ ---------- ---------- ---------- ----------
T_ITDBA_1                              11      18648      65536          8
T_ITDBA_1                              12      18656      65536          8
T_ITDBA_1                              13      18664      65536          8
T_ITDBA_1                              14      18672      65536          8
T_ITDBA_1                              15      18680      65536          8
T_ITDBA_1                              16      18688    1048576        128
T_ITDBA_1                              17      18816    1048576        128
T_ITDBA_1                              18      18944    1048576        128
T_ITDBA_1                              19      19072    1048576        128
T_ITDBA_1                              20      19200    1048576        128
T_ITDBA_1                              21      19328    1048576        128

SEGMENT_NAME                    EXTENT_ID   BLOCK_ID      BYTES     BLOCKS
------------------------------ ---------- ---------- ---------- ----------
T_ITDBA_1                              22      19456    1048576        128
T_ITDBA_1                              23      19584    1048576        128
T_ITDBA_1                              24      19712    1048576        128
T_ITDBA_1                              25      19840    1048576        128
T_ITDBA_1                              26      19968    1048576        128
T_ITDBA_1                              27      20096    1048576        128
T_ITDBA_1                              28      20224    1048576        128
T_ITDBA_1                              29      20352    1048576        128
T_ITDBA_1                              30      20480    1048576        128
T_ITDBA_1                              31      20608    1048576        128
T_ITDBA_1                              32      20736    1048576        128

SEGMENT_NAME                    EXTENT_ID   BLOCK_ID      BYTES     BLOCKS
------------------------------ ---------- ---------- ---------- ----------
T_ITDBA_1                              33      20864    1048576        128
T_ITDBA_1                              34      20992    1048576        128
T_ITDBA_1                              35      21120    1048576        128
T_ITDBA_1                              36      21248    1048576        128
T_ITDBA_1                              37      21376    1048576        128
T_ITDBA_1                              38      21504    1048576        128
T_ITDBA_1                              39      21632    1048576        128
T_ITDBA_1                              40      21760    1048576        128
T_ITDBA_1                              41      21888    1048576        128
T_ITDBA_1                              42      22016    1048576        128
T_ITDBA_1                              43      22144    1048576        128

SEGMENT_NAME                    EXTENT_ID   BLOCK_ID      BYTES     BLOCKS
------------------------------ ---------- ---------- ---------- ----------
T_ITDBA_1                              44      22272    1048576        128
T_ITDBA_1                              45      22400    1048576        128
T_ITDBA_1                              46      22528    1048576        128
T_ITDBA_1                              47      22656    1048576        128
T_ITDBA_1                              48      22784    1048576        128
T_ITDBA_1                              49      22912    1048576        128
T_ITDBA_1                              50      23040    1048576        128
T_ITDBA_1                              51      23168    1048576        128
T_ITDBA_1                              52      23296    1048576        128
T_ITDBA_1                              53      23424    1048576        128
T_ITDBA_1                              54      23552    1048576        128

SEGMENT_NAME                    EXTENT_ID   BLOCK_ID      BYTES     BLOCKS
------------------------------ ---------- ---------- ---------- ----------
T_ITDBA_1                              55      23680    1048576        128
T_ITDBA_1                              56      23808    1048576        128
T_ITDBA_1                              57      23936    1048576        128
T_ITDBA_1                              58      24064    1048576        128
T_ITDBA_1                              59      24192    1048576        128
T_ITDBA_1                              60      24320    1048576        128
T_ITDBA_1                              61      24448    1048576        128
T_ITDBA_1                              62      24576    1048576        128
T_ITDBA_1                              63      24704    1048576        128
T_ITDBA_1                              64      24832    1048576        128
T_ITDBA_1                              65      24960    1048576        128

SEGMENT_NAME                    EXTENT_ID   BLOCK_ID      BYTES     BLOCKS
------------------------------ ---------- ---------- ---------- ----------
T_ITDBA_1                              66      25088    1048576        128
T_ITDBA_1                              67      25216    1048576        128
T_ITDBA_1                              68      25344    1048576        128
T_ITDBA_1                              69      25472    1048576        128
T_ITDBA_1                              70        128    1048576        128

71 rows selected.

Elapsed: 00:00:00.01
SQL>  select bytes/1024 ,segment_name from dba_segments where segment_name='T_ITDBA_1';

BYTES/1024 SEGMENT_NAME
---------- ------------------------------
     57344 T_ITDBA_1

Elapsed: 00:00:00.01
SQL> delete from T_ITDBA_1 where owner='0';

80528 rows deleted.

Elapsed: 00:00:02.26
SQL> commit;

Commit complete.

Elapsed: 00:00:00.00
SQL> select segment_name,extent_id,block_id,bytes,blocks from dba_extents   where segment_name= 'T_ITDBA_1';

SEGMENT_NAME                    EXTENT_ID   BLOCK_ID      BYTES     BLOCKS
------------------------------ ---------- ---------- ---------- ----------
T_ITDBA_1                               0      18560      65536          8
T_ITDBA_1                               1      18568      65536          8
T_ITDBA_1                               2      18576      65536          8
T_ITDBA_1                               3      18584      65536          8
T_ITDBA_1                               4      18592      65536          8
T_ITDBA_1                               5      18600      65536          8
T_ITDBA_1                               6      18608      65536          8
T_ITDBA_1                               7      18616      65536          8
T_ITDBA_1                               8      18624      65536          8
T_ITDBA_1                               9      18632      65536          8
T_ITDBA_1                              10      18640      65536          8

SEGMENT_NAME                    EXTENT_ID   BLOCK_ID      BYTES     BLOCKS
------------------------------ ---------- ---------- ---------- ----------
T_ITDBA_1                              11      18648      65536          8
T_ITDBA_1                              12      18656      65536          8
T_ITDBA_1                              13      18664      65536          8
T_ITDBA_1                              14      18672      65536          8
T_ITDBA_1                              15      18680      65536          8
T_ITDBA_1                              16      18688    1048576        128
T_ITDBA_1                              17      18816    1048576        128
T_ITDBA_1                              18      18944    1048576        128
T_ITDBA_1                              19      19072    1048576        128
T_ITDBA_1                              20      19200    1048576        128
T_ITDBA_1                              21      19328    1048576        128

SEGMENT_NAME                    EXTENT_ID   BLOCK_ID      BYTES     BLOCKS
------------------------------ ---------- ---------- ---------- ----------
T_ITDBA_1                              22      19456    1048576        128
T_ITDBA_1                              23      19584    1048576        128
T_ITDBA_1                              24      19712    1048576        128
T_ITDBA_1                              25      19840    1048576        128
T_ITDBA_1                              26      19968    1048576        128
T_ITDBA_1                              27      20096    1048576        128
T_ITDBA_1                              28      20224    1048576        128
T_ITDBA_1                              29      20352    1048576        128
T_ITDBA_1                              30      20480    1048576        128
T_ITDBA_1                              31      20608    1048576        128
T_ITDBA_1                              32      20736    1048576        128

SEGMENT_NAME                    EXTENT_ID   BLOCK_ID      BYTES     BLOCKS
------------------------------ ---------- ---------- ---------- ----------
T_ITDBA_1                              33      20864    1048576        128
T_ITDBA_1                              34      20992    1048576        128
T_ITDBA_1                              35      21120    1048576        128
T_ITDBA_1                              36      21248    1048576        128
T_ITDBA_1                              37      21376    1048576        128
T_ITDBA_1                              38      21504    1048576        128
T_ITDBA_1                              39      21632    1048576        128
T_ITDBA_1                              40      21760    1048576        128
T_ITDBA_1                              41      21888    1048576        128
T_ITDBA_1                              42      22016    1048576        128
T_ITDBA_1                              43      22144    1048576        128

SEGMENT_NAME                    EXTENT_ID   BLOCK_ID      BYTES     BLOCKS
------------------------------ ---------- ---------- ---------- ----------
T_ITDBA_1                              44      22272    1048576        128
T_ITDBA_1                              45      22400    1048576        128
T_ITDBA_1                              46      22528    1048576        128
T_ITDBA_1                              47      22656    1048576        128
T_ITDBA_1                              48      22784    1048576        128
T_ITDBA_1                              49      22912    1048576        128
T_ITDBA_1                              50      23040    1048576        128
T_ITDBA_1                              51      23168    1048576        128
T_ITDBA_1                              52      23296    1048576        128
T_ITDBA_1                              53      23424    1048576        128
T_ITDBA_1                              54      23552    1048576        128

SEGMENT_NAME                    EXTENT_ID   BLOCK_ID      BYTES     BLOCKS
------------------------------ ---------- ---------- ---------- ----------
T_ITDBA_1                              55      23680    1048576        128
T_ITDBA_1                              56      23808    1048576        128
T_ITDBA_1                              57      23936    1048576        128
T_ITDBA_1                              58      24064    1048576        128
T_ITDBA_1                              59      24192    1048576        128
T_ITDBA_1                              60      24320    1048576        128
T_ITDBA_1                              61      24448    1048576        128
T_ITDBA_1                              62      24576    1048576        128
T_ITDBA_1                              63      24704    1048576        128
T_ITDBA_1                              64      24832    1048576        128
T_ITDBA_1                              65      24960    1048576        128

SEGMENT_NAME                    EXTENT_ID   BLOCK_ID      BYTES     BLOCKS
------------------------------ ---------- ---------- ---------- ----------
T_ITDBA_1                              66      25088    1048576        128
T_ITDBA_1                              67      25216    1048576        128
T_ITDBA_1                              68      25344    1048576        128
T_ITDBA_1                              69      25472    1048576        128
T_ITDBA_1                              70        128    1048576        128

71 rows selected.

Elapsed: 00:00:00.02
SQL> insert into t_itdba_1 select * from t_itdba_1;                                                                     

645568 rows created.

Elapsed: 00:00:02.75
SQL> commit;

Commit complete.

Elapsed: 00:00:00.00
SQL> select segment_name,extent_id,block_id,bytes,blocks from dba_extents   where segment_name= 'T_ITDBA_1';

SEGMENT_NAME                    EXTENT_ID   BLOCK_ID      BYTES     BLOCKS
------------------------------ ---------- ---------- ---------- ----------
T_ITDBA_1                               0      18560      65536          8
T_ITDBA_1                               1      18568      65536          8
T_ITDBA_1                               2      18576      65536          8
T_ITDBA_1                               3      18584      65536          8
T_ITDBA_1                               4      18592      65536          8
T_ITDBA_1                               5      18600      65536          8
T_ITDBA_1                               6      18608      65536          8
T_ITDBA_1                               7      18616      65536          8
T_ITDBA_1                               8      18624      65536          8
T_ITDBA_1                               9      18632      65536          8
T_ITDBA_1                              10      18640      65536          8

SEGMENT_NAME                    EXTENT_ID   BLOCK_ID      BYTES     BLOCKS
------------------------------ ---------- ---------- ---------- ----------
T_ITDBA_1                              11      18648      65536          8
T_ITDBA_1                              12      18656      65536          8
T_ITDBA_1                              13      18664      65536          8
T_ITDBA_1                              14      18672      65536          8
T_ITDBA_1                              15      18680      65536          8
T_ITDBA_1                              16      18688    1048576        128
T_ITDBA_1                              17      18816    1048576        128
T_ITDBA_1                              18      18944    1048576        128
T_ITDBA_1                              19      19072    1048576        128
T_ITDBA_1                              20      19200    1048576        128
T_ITDBA_1                              21      19328    1048576        128

SEGMENT_NAME                    EXTENT_ID   BLOCK_ID      BYTES     BLOCKS
------------------------------ ---------- ---------- ---------- ----------
T_ITDBA_1                              22      19456    1048576        128
T_ITDBA_1                              23      19584    1048576        128
T_ITDBA_1                              24      19712    1048576        128
T_ITDBA_1                              25      19840    1048576        128
T_ITDBA_1                              26      19968    1048576        128
T_ITDBA_1                              27      20096    1048576        128
T_ITDBA_1                              28      20224    1048576        128
T_ITDBA_1                              29      20352    1048576        128
T_ITDBA_1                              30      20480    1048576        128
T_ITDBA_1                              31      20608    1048576        128
T_ITDBA_1                              32      20736    1048576        128

SEGMENT_NAME                    EXTENT_ID   BLOCK_ID      BYTES     BLOCKS
------------------------------ ---------- ---------- ---------- ----------
T_ITDBA_1                              33      20864    1048576        128
T_ITDBA_1                              34      20992    1048576        128
T_ITDBA_1                              35      21120    1048576        128
T_ITDBA_1                              36      21248    1048576        128
T_ITDBA_1                              37      21376    1048576        128
T_ITDBA_1                              38      21504    1048576        128
T_ITDBA_1                              39      21632    1048576        128
T_ITDBA_1                              40      21760    1048576        128
T_ITDBA_1                              41      21888    1048576        128
T_ITDBA_1                              42      22016    1048576        128
T_ITDBA_1                              43      22144    1048576        128

SEGMENT_NAME                    EXTENT_ID   BLOCK_ID      BYTES     BLOCKS
------------------------------ ---------- ---------- ---------- ----------
T_ITDBA_1                              44      22272    1048576        128
T_ITDBA_1                              45      22400    1048576        128
T_ITDBA_1                              46      22528    1048576        128
T_ITDBA_1                              47      22656    1048576        128
T_ITDBA_1                              48      22784    1048576        128
T_ITDBA_1                              49      22912    1048576        128
T_ITDBA_1                              50      23040    1048576        128
T_ITDBA_1                              51      23168    1048576        128
T_ITDBA_1                              52      23296    1048576        128
T_ITDBA_1                              53      23424    1048576        128
T_ITDBA_1                              54      23552    1048576        128

SEGMENT_NAME                    EXTENT_ID   BLOCK_ID      BYTES     BLOCKS
------------------------------ ---------- ---------- ---------- ----------
T_ITDBA_1                              55      23680    1048576        128
T_ITDBA_1                              56      23808    1048576        128
T_ITDBA_1                              57      23936    1048576        128
T_ITDBA_1                              58      24064    1048576        128
T_ITDBA_1                              59      24192    1048576        128
T_ITDBA_1                              60      24320    1048576        128
T_ITDBA_1                              61      24448    1048576        128
T_ITDBA_1                              62      24576    1048576        128
T_ITDBA_1                              63      24704    1048576        128
T_ITDBA_1                              64      24832    1048576        128
T_ITDBA_1                              65      24960    1048576        128

SEGMENT_NAME                    EXTENT_ID   BLOCK_ID      BYTES     BLOCKS
------------------------------ ---------- ---------- ---------- ----------
T_ITDBA_1                              66      25088    1048576        128
T_ITDBA_1                              67      25216    1048576        128
T_ITDBA_1                              68      25344    1048576        128
T_ITDBA_1                              69      25472    1048576        128
T_ITDBA_1                              70        128    1048576        128
T_ITDBA_1                              71        256    1048576        128
T_ITDBA_1                              72        384    1048576        128
T_ITDBA_1                              73        512    1048576        128
T_ITDBA_1                              74        640    1048576        128
T_ITDBA_1                              75        768    1048576        128
T_ITDBA_1                              76        896    1048576        128

SEGMENT_NAME                    EXTENT_ID   BLOCK_ID      BYTES     BLOCKS
------------------------------ ---------- ---------- ---------- ----------
T_ITDBA_1                              77       1024    1048576        128
T_ITDBA_1                              78       1152    1048576        128
T_ITDBA_1                              79       1280    8388608       1024
T_ITDBA_1                              80       2304    8388608       1024
T_ITDBA_1                              81       3328    8388608       1024
T_ITDBA_1                              82       4352    8388608       1024
T_ITDBA_1                              83       5376    8388608       1024

84 rows selected.

Elapsed: 00:00:00.02
SQL> 


这个时候发现会有很多空块

SQL> select segment_name, extent_id, block_id, bytes, blocks
  2    from dba_extents
  3   where segment_name = 'T_ITDBA_1'
  4     and block_id not in (select dbms_rowid.rowid_block_number(rowid) block_id
  5                            FROM T_ITDBA_1);

SEGMENT_NAME                    EXTENT_ID   BLOCK_ID      BYTES     BLOCKS
------------------------------ ---------- ---------- ---------- ----------
T_ITDBA_1                               0      18560      65536          8
T_ITDBA_1                               2      18576      65536          8
T_ITDBA_1                               4      18592      65536          8
T_ITDBA_1                               6      18608      65536          8
T_ITDBA_1                               8      18624      65536          8
T_ITDBA_1                              10      18640      65536          8
T_ITDBA_1                              12      18656      65536          8
T_ITDBA_1                              14      18672      65536          8
T_ITDBA_1                              16      18688    1048576        128
T_ITDBA_1                              17      18816    1048576        128
T_ITDBA_1                              18      18944    1048576        128

SEGMENT_NAME                    EXTENT_ID   BLOCK_ID      BYTES     BLOCKS
------------------------------ ---------- ---------- ---------- ----------
T_ITDBA_1                              19      19072    1048576        128
T_ITDBA_1                              20      19200    1048576        128
T_ITDBA_1                              21      19328    1048576        128
T_ITDBA_1                              22      19456    1048576        128

区为单位分区事务数据库空间是碎片产生的主要因素之一;

时间: 2024-10-10 22:06:39

验证:oracle delete 数据库空间是可以重新被使用的的相关文章

利用SHELL脚本来验证Oracle数据库RMAN备份集的有效性

利用SHELL脚本来验证Oracle数据库RMAN备份集的有效性 作者:赵全文  网名:guestart 我们生产环境的Oracle数据库都做了RMAN备份,是采用了一周的RMAN备份保留策略:除了使用RMAN备份以外,我们还使用了爱数(Eisoo)备份软件来进行备份,可以说是做到了有备无患.可是,如果有一天,Oracle数据库由于主机层面硬件原因或是数据库层面的原因不能对外提供高可用服务的时候,假设数据丢了一大部分,我们只有用RMAN备份来进行恢复,再如果发现,RMAN备份失效了,那就往地缝里

mysql delete删除记录数据库空间不减少问题解决方法

记得在中学时学计算机时老师就告诉我delete删除记录只是给数据库中的记录加一个删除标识了,这样数据库空间并不是减少了,当时没想这么多,昨天发现一个数据库利用delete 删除之后容量没变,后来百度了一下发现了下面一站长分享的文件,写得非常的不错,整理一下给各位参考. 今天空间商告诉我数据库空间满了,检查了一下,发现网站用户行为记录数据表竟然占了20多MB.积累了半年了,该删除释放一下空间了.果断delete之后发现数据库空间竟然没少,虽然数据记录数是零. 原来这是因为删除操作后在数据文件中留下

oracle 查询数据库表空间大小和剩余空间

dba_data_files:数据库数据文件信息表.可以统计表空间大小(总空间大小). dba_free_space:可以统计剩余表空间大小. 增加表空间即向表空间增加数据文件,表空间大小就是数据文件总大小. 检查Oracle各个表空间的增长情况(各表空间使用率) select A.tablespace_name,(1-(A.total)/B.total)*100 used_percent from (select tablespace_name,sum(bytes) total from db

oracle所在磁盘空间不足导致了数据库异常

oracle所在磁盘空间不足导致了数据库异常.需要减小数据文件的大小来解决. 1.检查数据文件的名称和编号 select file#,name from v$datafile; 2.看哪个数据文件所占的空间最大,根据该数据文件的编号查看该数据文件的最大数据块数 select max(block_id) from dba_extents where file_id=8; 查询结果 3.计算该表空间的实际占用空间.(不是物理文件的大小) 查看每个数据块的大小 show parameter db_bl

delete删除记录数据库空间大小不减少问题

记得在大学时学计算机时老师就告诉我delete删除记录只是给数据库中的记录加一个删除标识了,这样数据库空间并不是减少了,当时没想这么多,昨天发现一个数据库利用delete 删除之后容量没变,后来百度了一下发现了下面一站长分享的文件,写得非常的不错,整理一下给各位参考.今天空间商告诉我数据库空间满了,检查了一下,发现网站用户行为记录数据表竟然占了20多MB.积累了半年了,该删除释放一下空间了.果断delete之后发现数据库空间竟然没少,虽然数据记录数是零. 原来这是因为删除操作后在数据文件中留下碎

Oracle 11g数据库详解(2015-1-18更新)

Oracle 11g数据库详解 整理者:高压锅 QQ:280604597 Email:[email protected] 大家有什么不明白的地方,或者想要详细了解的地方可以联系我,我会认真回复的 1   简介 数据库操作主要有以下几步: 1.  启动.停止数据库 2.  连接.断开数据库 3.  创建.修改.删除数据库用户 4.  表空间 5.  新建.修改.删除表 6.  查询.插入.修改.删除表数据 7.  新建.修改.删除视图 8.  新建.修改.删除存储过程 9.  新建.修改.删除触发

Oracle 11g数据库详解(2015-02-28更新)

Oracle 11g数据库详解 整理者:高压锅 QQ:280604597 Email:[email protected] 大家有什么不明白的地方,或者想要详细了解的地方可以联系我,我会认真回复的 1   简介 数据库操作主要有以下几步: 1.  启动.停止数据库 2.  连接.断开数据库 3.  创建.修改.删除数据库用户 4.  表空间 5.  新建.修改.删除表 6.  查询.插入.修改.删除表数据 7.  新建.修改.删除视图 8.  新建.修改.删除存储过程 9.  新建.修改.删除触发

Oracle 10g数据库备份与恢复操作手册

Oracle 10g数据库备份与恢复操作手册 前言 文档目的 备份与恢复是数据库管理中最重要的方面之一.如果数据库崩溃却没有办法恢复它,那么对企业造成的毁灭性结果可能会是数据丢失.收入减少.客户不满等.不管公司是使用单个数据库还是多个数据库来存储数百  GB或    TB的数据,它们都有一个共同点,即需要制订一个备份与恢复方案来备份重要数据并使自身免于灾难.要制定一个适合自己公司情况的合理的备份与恢复方案,就必须熟悉备份与恢复的方法和操作. 为了给 Oracle DBA和相关技术人员提供一个参考

使用Navicat for Oracle新建表空间、用户及权限赋予---来自烂泥

Navicat for Oracle是有关Oracle数据库的客户端工具.通过这个客户端,我们可以图形方式对Oracle数据库进行操作. 说 明我们此次试验的Oracle数据库版本是Oracle 10G Express Edition,也即是我们平时所说的Oracle XE版本.此版本 对于,我们学习来说已经是足够了.我们只要知道一般我们使用的Oracle数据库版本是企业版就行了,因为Oracle 数据库的版本比较多在此我就不做 过多的介绍了. 有关Oracle XE数据库的安装,这次就不介绍了