心海恋歌 发表于 2018-9-26 09:58:34

oracle high water mark-ciscoandlinux

oracle 高水位线的一些知识
  学习oracle已经有一段时间了,现在把一些知识点写出来,方便以后自己再复习。
  The high water mark is the boundary betweenused and unused space in a segment(高水位线是段中已用和未用空间的边界)。
  --下面通过做一个实验来验证高水位线:

  SQL> create user hwmuser>
  SQL> create tablespace hwmt datafile '/u01/app/oracle/oradata/jacky/hwm01.dbf'>
  SQL>>  SQL> grant dba to hwmuser;#给hwmuser用户授权
  SQL> conn hwmuser/hwmuser; #连接hwmuser
  --以上都是准备工作,下面正式进入高水位线的实验
  SQL> create table hwmtest as select * from dba_objects where 2=3;#建表hwmtest
  SQL> select segment_name,segment_type,blocks,extents from user_segments where segment_name='HWMTEST';         #查看表中分配块和区的大小
  SEGMENT_NAME                                                                      SEGMENT_TYPE         BLOCKS    EXTENTS
  --------------------------------------------------------------------------------- ------------------ ---------- ----------
  HWMTEST                                                                           TABLE                     8          1
SQL> analyze table hwmtest estimate statistics; #分析表hwmtestTable analyzed.--下面一条命令即是查询表的高水位线: SQL> select num_rows,blocks,empty_blocks from user_tables where table_name='HWMTEST'; #查表hwmtest的高水位线blocks--已占用的数据块数(高水位线),empty_blocks--空闲的数据块数   NUM_ROWS   BLOCKS EMPTY_BLOCKS---------- ---------- ------------         0          0            8--表hwmtest无数据,所以表的高水位线就是零,下面插入数据: SQL> insert into hwmtest select * from dba_objects;#向表hwmtest插入数据 50354 rows created. SQL> commit; Commit complete.--再次分析表 SQL> analyze table hwmtest estimate statistics; Table analyzed.--再次查看表中块,区的分配情况SQL> select segment_name,segment_type,blocks,extents from user_segments where segment_name='HWMTEST'; SEGMENT_NAME                                                                      SEGMENT_TYPE         BLOCKS    EXTENTS--------------------------------------------------------------------------------- ------------------ ---------- ----------HWMTEST                                                                           TABLE                     768         21此时oracle已经给表hwmtest分配了768个数据块,21个区--再次查看表hwmtest的高水位线 SQL> select num_rows,blocks,empty_blocks from user_tables where table_name='HWMTEST';   NUM_ROWS   BLOCKS EMPTY_BLOCKS---------- ---------- ------------   52980      748         20blocks(高水位)已经增长到了748,empty_blocks(空闲块)还有20 ,748+20=768--下面步骤为删除表的数据后再次查看高水位SQL> select to_char(sysdate,'yyyymmdd hh24:mi:ss') from dual; TO_CHAR(SYSDATE,'-----------------20121017 09:56:07SQL>>Table>SQL> delete from hwmtest;50354 rows deleted. SQL> commit; Commit complete. SQL> analyze table hwmtest estimate statistics; Table analyzed.SQL> select num_rows,blocks,empty_blocks from user_tables where table_name='HWMTEST';   NUM_ROWS   BLOCKS EMPTY_BLOCKS---------- ---------- ------------         0      748         20此时发现高水位并未减少,说明delete只是删除表中数据块的记录,但不会使水位下降,当对表再次查询时可能还是很慢,进行全表扫描的时候,高水位线下的数据都会进行扫描。--下面用trncate命令来删除表的数据,并对高水位进行查询SQL> flashback table hwmtest to timestamp to_date('20121017 09:56:07','yyyymmdd hh24:mi:ss'); Flashback complete. SQL> select count(*) from hwmtest;   COUNT(*)----------   50354SQL> truncate table hwmtest; Table truncated. SQL> analyze table hwmtest estimate statistics; Table analyzed. SQL> select num_rows,blocks,empty_blocks from user_tables where table_name='HWMTEST';   NUM_ROWS   BLOCKS EMPTY_BLOCKS---------- ---------- ------------         0          0            8现在高水位已经回到零了。
页: [1]
查看完整版本: oracle high water mark-ciscoandlinux