oracle 如何查看表 高水位线

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了oracle 如何查看表 高水位线相关的知识,希望对你有一定的参考价值。

Oracle 表中有个高水位线,如何查看当前高水位线的值

参考技术A select blocks, empty_blocks from dba_tables where table_name='xxx' and owner='xx';
blocks就是已经分配的空间即HWM,实际分配的空间,不是实际大小本回答被提问者采纳

[ORACLE]oracle 如何解决高水平线问题

问题:删除表数据不会导致高水位线下降,不会使用查询效率,

模拟:

创建表,分析表

SQL> create table TEST as select * from USRBF2;

Table created.

SQL> EXEC DBMS_STATS.GATHER_TABLE_STATS(c##sapr3,tabname =>TEST,estimate_percent=>100,method_opt=>FOR ALL COLUMNS SIZE AUTO,degree=>4,cascade=>TRUE);

PL/SQL procedure successfully completed.

SQL> select num_rows,blocks,empty_blocks from dba_tables where table_name=TEST;

  NUM_ROWS     BLOCKS EMPTY_BLOCKS
---------- ---------- ------------
   1236277       6947            0

SQL> set autotrace traceonly

SQL> select * from TEST;

1236277 rows selected.


Execution Plan
----------------------------------------------------------
Plan hash value: 1357081020

--------------------------------------------------------------------------
| Id  | Operation         | Name | Rows  | Bytes | Cost (%CPU)| Time     |
--------------------------------------------------------------------------
|   0 | SELECT STATEMENT  |      |  1236K|    41M|  2235   (1)| 00:00:01 |
|   1 |  TABLE ACCESS FULL| TEST |  1236K|    41M|  2235   (1)| 00:00:01 |
--------------------------------------------------------------------------


Statistics
----------------------------------------------------------
          0  recursive calls
          0  db block gets
      88809  consistent gets
       6829  physical reads
          0  redo size
   43475416  bytes sent via SQL*Net to client
     906978  bytes received via SQL*Net from client
      82420  SQL*Net roundtrips to/from client
          0  sorts (memory)
          0  sorts (disk)
    1236277  rows processed
S
QL> set autotrace off

 删除部分数据:

SQL> DELETE from TEST where MANDT=000;

1113248 rows deleted.

SQL> commit;

Commit complete.

SQL> EXEC DBMS_STATS.GATHER_TABLE_STATS(c##sapr3,tabname =>TEST,estimate_percent=>100,method_opt=>FOR ALL COLUMNS SIZE AUTO,degree=>4,cascade=>TRUE);

PL/SQL procedure successfully completed.

SQL> select num_rows,blocks,empty_blocks from dba_tables where table_name=TEST;

  NUM_ROWS     BLOCKS EMPTY_BLOCKS
---------- ---------- ------------
    123029       6947            0

可以看到NUM_ROWS 减少,但BLOCKS仍然和原来的一样是6947

rows processed 1236277 -->123029
consistent gets 逻辑读 88809  -->14995

 

SQL> set autotrace traceonly
SQL> select * from TEST;

123029 rows selected.


Execution Plan
----------------------------------------------------------
Plan hash value: 1357081020

--------------------------------------------------------------------------
| Id  | Operation         | Name | Rows  | Bytes | Cost (%CPU)| Time     |
--------------------------------------------------------------------------
|   0 | SELECT STATEMENT  |      |   123K|  4325K|  2225   (1)| 00:00:01 |
|   1 |  TABLE ACCESS FULL| TEST |   123K|  4325K|  2225   (1)| 00:00:01 |
--------------------------------------------------------------------------


Statistics
----------------------------------------------------------
          0  recursive calls
          0  db block gets
      14995  consistent gets
          0  physical reads
          0  redo size
    3828471  bytes sent via SQL*Net to client
      90591  bytes received via SQL*Net from client
       8203  SQL*Net roundtrips to/from client
          0  sorts (memory)
          0  sorts (disk)
     123029  rows processed

SQL> set autotrace off

收缩表

SQL> alter table TEST enable row movement;

Table altered.

SQL> alter table TEST shrink space cascade;

Table altered.

SQL> EXEC DBMS_STATS.GATHER_TABLE_STATS(c##sapr3,tabname =>TEST,estimate_percent=>100,method_opt=>FOR ALL COLUMNS SIZE AUTO,degree=>4,cascade=>TRUE);

PL/SQL procedure successfully completed.

SQL> select num_rows,blocks,empty_blocks from dba_tables where table_name=TEST;

  NUM_ROWS     BLOCKS EMPTY_BLOCKS
---------- ---------- ------------
    123029        704            0

可以看到表中的BLOCKS由6947 减少到704

继续压缩

SQL> ALTER TABLE TEST move compress;

Table altered.

SQL> EXEC DBMS_STATS.GATHER_TABLE_STATS(c##sapr3,tabname =>TEST,estimate_percent=>100,method_opt=>FOR ALL COLUMNS SIZE AUTO,degree=>4,cascade=>TRUE);

PL/SQL procedure successfully completed.

SQL> select num_rows,blocks,empty_blocks from dba_tables where table_name=TEST;

  NUM_ROWS     BLOCKS EMPTY_BLOCKS
---------- ---------- ------------
    123029        289            0

可以看到表中的BLOCKS由704减少到289

再次进行查询

SQL> set autotrace traceonly
SQL> select * from TEST;

123029 rows selected.


Execution Plan
----------------------------------------------------------
Plan hash value: 1357081020

--------------------------------------------------------------------------
| Id  | Operation         | Name | Rows  | Bytes | Cost (%CPU)| Time     |
--------------------------------------------------------------------------
|   0 | SELECT STATEMENT  |      |   123K|  4325K|    95   (2)| 00:00:01 |
|   1 |  TABLE ACCESS FULL| TEST |   123K|  4325K|    95   (2)| 00:00:01 |
--------------------------------------------------------------------------


Statistics
----------------------------------------------------------
          1  recursive calls
          0  db block gets
       8465  consistent gets
          0  physical reads
          0  redo size
    3841745  bytes sent via SQL*Net to client
      90591  bytes received via SQL*Net from client
       8203  SQL*Net roundtrips to/from client
          0  sorts (memory)
          0  sorts (disk)
     123029  rows processed

可以看到 consistent 由 14995减少到 8465

 

以上是关于oracle 如何查看表 高水位线的主要内容,如果未能解决你的问题,请参考以下文章

oracle 分区表怎么回收高水位

什么是Oracle高水位线

[ORACLE]oracle 如何解决高水平线问题

oracle数据库表空间占用太大,如何在不删除表的情况下缩小占用空间

ORACLE:重置高水位线

降低Oracle高水位线的方法