• 表空间的空间管理算法


    存储结构

     逻辑结构              物理结构

    database

    tablespace       --> datafile

    segment

    extent

    oracle             --> os block

    block

    表空间的空间管理:

    DMT(dictionary management tablespace):

    LMT(local management tablespace):

    1. SQL>
    2. SQL> select name from v$datafile;
    3. NAME
    4. --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    5. /u02/oradata/CDB1/system01.dbf
    6. /u02/oradata/CDB1/sysaux01.dbf
    7. /u02/oradata/CDB1/undotbs01.dbf
    8. /u02/oradata/CDB1/pdbseed/system01.dbf
    9. /u02/oradata/CDB1/pdbseed/sysaux01.dbf
    10. /u02/oradata/CDB1/users01.dbf
    11. /u02/oradata/CDB1/pdbseed/undotbs01.dbf
    12. /u02/oradata/CDB1/pdb1/system01.dbf
    13. /u02/oradata/CDB1/pdb1/sysaux01.dbf
    14. /u02/oradata/CDB1/pdb1/undotbs01.dbf
    15. /u02/oradata/CDB1/pdb1/users01.dbf
    16. 11 rows selected.
    17. SQL> select tablespace_name,extent_management from dba_tablespaces;
    18. TABLESPACE_NAME EXTENT_MAN
    19. ------------------------------ ----------
    20. SYSTEM LOCAL
    21. SYSAUX LOCAL
    22. UNDOTBS1 LOCAL
    23. TEMP01 LOCAL
    24. USERS LOCAL
    25. SQL>

    1. SQL> column FILE_ID default
    2. SQL> select file_id,file_name from dba_data_files;
    3. FILE_ID FILE_NAME
    4. ---------- ------------------------------------------------------------
    5. 7 /u02/oradata/CDB1/users01.dbf
    6. 4 /u02/oradata/CDB1/undotbs01.dbf
    7. 1 /u02/oradata/CDB1/system01.dbf
    8. 3 /u02/oradata/CDB1/sysaux01.dbf
    9. 15 /u02/oradata/CDB1/data01.dbf
    10. SQL>
    1. SQL>
    2. SQL> select name from v$datafile;
    3. NAME
    4. --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    5. /u02/oradata/CDB1/system01.dbf
    6. /u02/oradata/CDB1/sysaux01.dbf
    7. /u02/oradata/CDB1/undotbs01.dbf
    8. /u02/oradata/CDB1/pdbseed/system01.dbf
    9. /u02/oradata/CDB1/pdbseed/sysaux01.dbf
    10. /u02/oradata/CDB1/users01.dbf
    11. /u02/oradata/CDB1/pdbseed/undotbs01.dbf
    12. /u02/oradata/CDB1/pdb1/system01.dbf
    13. /u02/oradata/CDB1/pdb1/sysaux01.dbf
    14. /u02/oradata/CDB1/pdb1/undotbs01.dbf
    15. /u02/oradata/CDB1/pdb1/users01.dbf
    16. 11 rows selected.
    17. SQL> select tablespace_name,extent_management from dba_tablespaces;
    18. TABLESPACE_NAME EXTENT_MAN
    19. ------------------------------ ----------
    20. SYSTEM LOCAL
    21. SYSAUX LOCAL
    22. UNDOTBS1 LOCAL
    23. TEMP01 LOCAL
    24. USERS LOCAL
    25. SQL> create tablespace data01 datafile '/u02/oradata/CDB1/data01.dbf' size 88k;
    26. Tablespace created.
    27. SQL>
    28. SQL> column FILE_NAME for a60
    29. SQL>
    30. SQL> column FILE_ID default
    31. SQL> select file_id,file_name from dba_data_files;
    32. FILE_ID FILE_NAME
    33. ---------- ------------------------------------------------------------
    34. 7 /u02/oradata/CDB1/users01.dbf
    35. 4 /u02/oradata/CDB1/undotbs01.dbf
    36. 1 /u02/oradata/CDB1/system01.dbf
    37. 3 /u02/oradata/CDB1/sysaux01.dbf
    38. 15 /u02/oradata/CDB1/data01.dbf
    39. SQL> select name from v$datafile;
    40. NAME
    41. --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    42. /u02/oradata/CDB1/system01.dbf
    43. /u02/oradata/CDB1/sysaux01.dbf
    44. /u02/oradata/CDB1/undotbs01.dbf
    45. /u02/oradata/CDB1/pdbseed/system01.dbf
    46. /u02/oradata/CDB1/pdbseed/sysaux01.dbf
    47. /u02/oradata/CDB1/users01.dbf
    48. /u02/oradata/CDB1/pdbseed/undotbs01.dbf
    49. /u02/oradata/CDB1/pdb1/system01.dbf
    50. /u02/oradata/CDB1/pdb1/sysaux01.dbf
    51. /u02/oradata/CDB1/pdb1/undotbs01.dbf
    52. /u02/oradata/CDB1/pdb1/users01.dbf
    53. /u02/oradata/CDB1/data01.dbf
    54. 12 rows selected.
    55. SQL> !ls -lk /u02/oradata/CDB1/data01.dbf
    56. -rw-r-----. 1 oracle oinstall 98304 Nov 24 14:10 /u02/oradata/CDB1/data01.dbf
    57. SQL> alter system dump datafile 6 block min 1 block max 11;
    58. System altered.
    59. SQL> show user
    60. USER is "SYS"
    61. SQL> show parameter background;
    62. NAME TYPE VALUE
    63. ------------------------------------ ----------- ------------------------------
    64. background_core_dump string partial
    65. background_dump_dest string /u01/app/oracle/product/19.3.0
    66. /dbhome_1/rdbms/log
    67. SQL

    段(segment)空间管理模式:

    段所拥有的数据块中空闲块如何管理

    1. SQL>
    2. SQL> select tablespace_name,segment_space_management from dba_tablespaces;
    3. TABLESPACE_NAME SEGMEN
    4. ------------------------------ ------
    5. SYSTEM MANUAL
    6. SYSAUX AUTO
    7. UNDOTBS1 MANUAL
    8. TEMP01 MANUAL
    9. USERS AUTO
    10. DATA01 AUTO
    11. 6 rows selected.
    12. SQL>

    段内空闲空间的手工管理:使用空闲列表管理段内的空闲块(可以做insert的块)。空闲列表记录在段头,空闲列表指向段内空闲块的地址。

    1. SQL> show con_name;
    2. CON_NAME
    3. ------------------------------
    4. CDB$ROOT
    5. SQL> alter session set container=PDB1;
    6. Session altered.
    7. SQL> drop table scott.t01 purge;
    8. Table dropped.
    9. SQL>
    10. SQL> create table scott.t01 (x int,y varchar2(20)) tablespace system;
    11. Table created.
    12. SQL>

    查询哪些块属于t01段:

    select file_id,block_id,blocks from dba_extents where segment_name='T01';

     查询空闲列表的数量:

     

     

    查看t01的段头块:

    1. SQL> select header_file,header_block from dba_segments where segment_name='T01';

     

    将segment header 的数据转储到用户进程的跟踪文件:

    alter system dump datafile 1 block 94664

     

     在表中插入数据之后,重新转储段头块

     

  • 相关阅读:
    Java智能教育平台源码基于 SpringBoot + Mybatis + Shiro + mysql + redis构建,前后端分离。
    C++字符串比较的踩坑/详解
    数字藏品:重塑艺术与科技的新媒介
    git 问题 之 git add 后直接git commit --amend导致合入了上一笔提交的解决办法
    【开发小记】vuex存储用户信息
    反沙箱技术
    景联文科技:一文读懂火爆全网的AIGC和背后的数据标注技术!
    大数据Hadoop入门教程 | (一)概论
    ATtiny88初体验(三):串口
    判断素数/质数的快速算法
  • 原文地址:https://blog.csdn.net/u011868279/article/details/128016830