Oracle中相对文件号(RFN)和绝对文件号(AFN)的示例分析-成都快上网建站

Oracle中相对文件号(RFN)和绝对文件号(AFN)的示例分析

Oracle中相对文件号(RFN)和绝对文件号(AFN)的示例分析,相信很多没有经验的人对此束手无策,为此本文总结了问题出现的原因和解决方法,通过这篇文章希望你能解决这个问题。

创新互联为企业级客户提高一站式互联网+设计服务,主要包括网站制作、成都网站制作App定制开发小程序开发、宣传片制作、LOGO设计等,帮助客户快速提升营销能力和企业形象,创新互联各部门都有经验丰富的经验,可以确保每一个作品的质量和创作周期,同时每年都有很多新员工加入,为我们带来大量新的创意。 

大家都知道从Oracle8开始,Oracle开始使用“相对文件号”,使原来一个数据库最多只能有1023个文件,扩展为一个表空间最多可以有1023个文件,每个库最多可以有65534个文件。

绝对文件号相对于整个数据库是唯一的,每个库最多可以有65534个文件。

相对文件号则相对于表空间是唯一的,就是说每个表空间都有自己的相对文件号,每个表空间的最大文件数为1023,相对文件号对于整个数据库来说是不唯一的;


查询:
SQL> select TS#,FILE#,name from v$datafile order by 1,2;

       TS#      FILE# NAME
---------- ---------- ------------------------------------------------------------
         0          1 /u01/app/oracle/oradata/DBdb/system01.dbf
         1          2 /u01/app/oracle/oradata/DBdb/sysaux01.dbf
         2          3 /u01/app/oracle/oradata/DBdb/undotbs01.dbf
         4          4 /u01/app/oracle/oradata/DBdb/users01.dbf
         4          7 /u01/app/oracle/oradata/DBdb/users02.dbf
         4          9 /u01/app/oracle/oradata/DBdb/users03.dbf
         6          5 /u01/app/oracle/oradata/DBdb/example01.dbf
         7          6 /u01/app/oracle/oradata/DBdb/test.dbf
         7          8 /u01/app/oracle/oradata/DBdb/test02.DBF

9 rows selected.
查询v$datafile此视图缺少tmp临时表空间信息,同时包含出tmp临时表空间之外的所有表空间下的所有数据文件

SQL> select TS#,FILE#,NAME,BYTES/1024/1024 size_m from v$tempfile;

       TS#      FILE# NAME                                                             SIZE_M
---------- ---------- ------------------------------------------------------------ ----------
         3          1 /u01/app/oracle/oradata/DBdb/temp01.dbf                             179

file#绝对文件号



SQL> select TS#,NAME,BIGFILE from v$tablespace order by 1;

       TS# NAME                                                         BIG
---------- ------------------------------------------------------------ ---
         0 SYSTEM                                                       NO
         1 SYSAUX                                                       NO
         2 UNDOTBS1                                                     NO
         3 TEMP                                                         NO
         4 USERS                                                        NO
         6 EXAMPLE                                                      NO
         7 TEST                                                         NO

7 rows selected.


SQL> select TABLESPACE_NAME,FILE_ID,FILE_NAME,BYTES/1024/1024 size_m,STATUS from dba_data_files order by 2;

TABLESPACE_NAME                   FILE_ID FILE_NAME                                                        SIZE_M STATUS
------------------------------ ---------- ------------------------------------------------------------ ---------- ---------
SYSTEM                                  1 /u01/app/oracle/oradata/DBdb/system01.dbf                          2800 AVAILABLE
SYSAUX                                  2 /u01/app/oracle/oradata/DBdb/sysaux01.dbf                           720 AVAILABLE
UNDOTBS1                                3 /u01/app/oracle/oradata/DBdb/undotbs01.dbf                         2585 AVAILABLE
USERS                                   4 /u01/app/oracle/oradata/DBdb/users01.dbf                        3058.75 AVAILABLE
EXAMPLE                                 5 /u01/app/oracle/oradata/DBdb/example01.dbf                       338.75 AVAILABLE
TEST                                    6 /u01/app/oracle/oradata/DBdb/test.dbf                                10 AVAILABLE
USERS                                   7 /u01/app/oracle/oradata/DBdb/users02.dbf                             10 AVAILABLE
TEST                                    8 /u01/app/oracle/oradata/DBdb/test02.DBF                              10 AVAILABLE
USERS                                   9 /u01/app/oracle/oradata/DBdb/users03.dbf                             10 AVAILABLE

9 rows selected.

查询得包含表空间下的所有数据文件

SQL> select TABLESPACE_NAME,STATUS,CONTENTS,FORCE_LOGGING,EXTENT_MANAGEMENT,SEGMENT_SPACE_MANAGEMENT,ALLOCATION_TYPE,RETENTION,BIGFILE from dba_tablespaces;

TABLESPACE_NAME                STATUS    CONTENTS  FOR EXTENT_MAN SEGMEN ALLOCATIO RETENTION   BIG
------------------------------ --------- --------- --- ---------- ------ --------- ----------- ---
SYSTEM                         ONLINE    PERMANENT NO  LOCAL      MANUAL SYSTEM    NOT APPLY   NO
SYSAUX                         ONLINE    PERMANENT NO  LOCAL      AUTO   SYSTEM    NOT APPLY   NO
UNDOTBS1                       ONLINE    UNDO      NO  LOCAL      MANUAL SYSTEM    NOGUARANTEE NO
TEMP                           ONLINE    TEMPORARY NO  LOCAL      MANUAL UNIFORM   NOT APPLY   NO
USERS                          ONLINE    PERMANENT NO  LOCAL      AUTO   SYSTEM    NOT APPLY   NO
EXAMPLE                        ONLINE    PERMANENT NO  LOCAL      AUTO   SYSTEM    NOT APPLY   NO
TEST                           ONLINE    PERMANENT NO  LOCAL      AUTO   SYSTEM    NOT APPLY   NO

7 rows selected.

实验开始:

SQL> create tablespace test_mf datafile '/u01/app/oracle/oradata/DBdb/m1.dbf' size 100k reuse;

Tablespace created.

SQL> alter tablespace test_mf add datafile '/u01/app/oracle/oradata/DBdb/m2.dbf' size 88k;

Tablespace altered.

SQL> show parameter db_files

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
db_files                             integer     2000
SQL>
SQL> begin
      for i in 3..1025 loop
       execute immediate'alter tablespace test_mf add datafile ''/u01/app/oracle/oradata/DBdb/m_' || i ||''' size 88k';
      end loop;
      end;
      /

 begin
*
ERROR at line 1:
ORA-01686: max # files (1023) reached for the tablespace TEST_MF
ORA-06512: at line 3


SQL> select count(*) from dba_data_files where tablespace_name='TEST_MF';

  COUNT(*)
----------
      1023

可以看到表空间TEST_MF的文件数为1023个,最多也只能为1023个。

SQL>  select count(*) from dba_data_files where tablespace_name='TEST_MF';

  COUNT(*)
----------
      1023

SQL>  select ts# from v$tablespace where name='TEST_MF';

       TS#
----------
         9

--查询表空间test_mf的相对文件号、绝对文件号:
select file_id,relative_fno,TABLESPACE_NAME,FILE_NAME from dba_data_files where tablespace_name='TEST_MF';

或者

select file#,rfile#,name from v$datafile where ts#=9;

SQL> select file#,rfile#,name from v$datafile where ts#=9;

     FILE#     RFILE# NAME
---------- ---------- ------------------------------------------------------------
        10         10 /u01/app/oracle/oradata/DBdb/m1.dbf
        11         11 /u01/app/oracle/oradata/DBdb/m2.dbf
        12         12 /u01/app/oracle/oradata/DBdb/m_3
        13         13 /u01/app/oracle/oradata/DBdb/m_4
        14         14 /u01/app/oracle/oradata/DBdb/m_5
        15         15 /u01/app/oracle/oradata/DBdb/m_6
        16         16 /u01/app/oracle/oradata/DBdb/m_7
        17         17 /u01/app/oracle/oradata/DBdb/m_8
        18         18 /u01/app/oracle/oradata/DBdb/m_9
省略....................................................................
     FILE#     RFILE# NAME
---------- ---------- ------------------------------------------------------------
      1011       1011 /u01/app/oracle/oradata/DBdb/m_1002
      1012       1012 /u01/app/oracle/oradata/DBdb/m_1003
      1013       1013 /u01/app/oracle/oradata/DBdb/m_1004
      1014       1014 /u01/app/oracle/oradata/DBdb/m_1005
      1015       1015 /u01/app/oracle/oradata/DBdb/m_1006
      1016       1016 /u01/app/oracle/oradata/DBdb/m_1007
      1017       1017 /u01/app/oracle/oradata/DBdb/m_1008
      1018       1018 /u01/app/oracle/oradata/DBdb/m_1009
      1019       1019 /u01/app/oracle/oradata/DBdb/m_1010
      1020       1020 /u01/app/oracle/oradata/DBdb/m_1011
      1021       1021 /u01/app/oracle/oradata/DBdb/m_1012

     FILE#     RFILE# NAME
---------- ---------- ------------------------------------------------------------
      1022       1022 /u01/app/oracle/oradata/DBdb/m_1013
      1023       1023 /u01/app/oracle/oradata/DBdb/m_1014
      1024          1 /u01/app/oracle/oradata/DBdb/m_1015
      1025          2 /u01/app/oracle/oradata/DBdb/m_1016
      1026          3 /u01/app/oracle/oradata/DBdb/m_1017
      1027          4 /u01/app/oracle/oradata/DBdb/m_1018
      1028          5 /u01/app/oracle/oradata/DBdb/m_1019
      1029          6 /u01/app/oracle/oradata/DBdb/m_1020
      1030          7 /u01/app/oracle/oradata/DBdb/m_1021
      1031          8 /u01/app/oracle/oradata/DBdb/m_1022
      1032          9 /u01/app/oracle/oradata/DBdb/m_1023

1023 rows selected.

SQL>                                          

从上面的数据可以看出,当绝对文件号小于等于1023,相对文件号与绝对文件号一样。相对文件号大于1023之后,又从1开始循环。


SQL> create tablespace test_lf datafile '/u01/app/oracle/oradata/DBdb/TEST_LF.dbf' size 1m;

Tablespace created.

SQL> select ts# from v$tablespace where name='TEST_LF';

       TS#
----------
        10

SQL> select file#,rfile#,name from v$datafile where ts#=10;

     FILE#     RFILE# NAME
---------- ---------- ------------------------------------------------------------
      1033         10 /u01/app/oracle/oradata/DBdb/TEST_LF.dbf

从上面的数据可以看出,一个表空间的数据文件,其相对文件号并不是从1开始的,而依然是从上一个用过的最后一个相对文件号继续,及file#号从上面的1032增加到1033,而RFILE#从9增加到10。

--接着增加新表空间ORA
SQL> create tablespace ORA datafile '/u01/app/oracle/oradata/DBdb/ora.dbf' size 1m;

Tablespace created.

SQL>
SQL> alter tablespace ORA  add datafile '/u01/app/oracle/oradata/DBdb/ora02.dbf' size 1m;

Tablespace altered.

SQL> select file_id,relative_fno,TABLESPACE_NAME,FILE_NAME from dba_data_files where tablespace_name='ORA';  

   FILE_ID RELATIVE_FNO TABLESPACE_NAME                FILE_NAME
---------- ------------ ------------------------------ ------------------------------------------------------------
      1034           11 ORA                            /u01/app/oracle/oradata/DBdb/ora.dbf
      1035           12 ORA                            /u01/app/oracle/oradata/DBdb/ora02.dbf

从上查询得,FILE_ID绝对文件号以创建表空间或给表空间添加数据文件的形式递进增加,而RELATIVE_FNO(rfile#)相对文件号相对于表空间而言,一个表空间的数据文件熟练小于等于1023个。

--接着查询
SQL> select OBJ#,OWNER# from obj$ where name='EMP';

      OBJ#     OWNER#
---------- ----------
     87108         83

SQL> select object_id from dba_objects where OWNER='SCOTT' and object_name='EMP' and object_type='TABLE';

 OBJECT_ID
----------
     87108

SQL> select obj#,dataobj#,ts#,file# from tab$ where obj#=87108;

      OBJ#   DATAOBJ#        TS#      FILE#
---------- ---------- ---------- ----------
     87108      87108          4          4

SQL> select SEGMENT_NAME,HEADER_FILE,HEADER_BLOCK,RELATIVE_FNO,TABLESPACE_NAME from dba_segments where SEGMENT_NAME='EMP' and SEGMENT_TYPE='TABLE';

SEGMENT_NAME    HEADER_FILE HEADER_BLOCK RELATIVE_FNO TABLESPACE_NAME
--------------- ----------- ------------ ------------ ------------------------------
EMP                       4          146            4 USERS

在DBA_SEGMENTS视图里面,可以查到段头的相对文件号和绝对文件号。(这个视图最终是从file$、seg$等字典表里面取得数据)

看完上述内容,你们掌握Oracle中相对文件号(RFN)和绝对文件号(AFN)的示例分析的方法了吗?如果还想学到更多技能或想了解更多相关内容,欢迎关注创新互联行业资讯频道,感谢各位的阅读!


网站标题:Oracle中相对文件号(RFN)和绝对文件号(AFN)的示例分析
URL链接:http://kswjz.com/article/gjegjh.html
扫二维码与项目经理沟通

我们在微信上24小时期待你的声音

解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流