重庆思庄Oracle、Redhat认证学习论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 2860|回复: 2
打印 上一主题 下一主题

[转载] Oracle下绝对文件号和相对文件号区别

[复制链接]
跳转到指定楼层
楼主
发表于 2016-8-20 10:36:30 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
一:Oracle官方给出的描述

Oracle Database assigns each datafile two associated file numbers, an absolute file
number and a relative file number, that are used to uniquely identify it


Absolute:Uniquely identifies a datafile in the database. This file number can be used in many SQL statements that reference datafiles in place of using the file name. The absolute file number can be found in the FILE# column of the V$DATAFILE or V$TEMPFILE view, or in the FILE_ID column of the DBA_DATA_FILES or DBA_TEMP_FILES  view


Relative:Uniquely identifies a datafile within a tablespace. For small and medium size databases, relative file numbers usually have the same value as the absolute file number. However, when the
number of datafiles in a database exceeds a threshold (typically 1023), the relative file number differs from the absolute file number. In a bigfile tablespace, the relative file number is always
1024 (4096 on OS/390 platform).

二:总结如下

总述:oracle数据库会给每一个新创建的datafile分配一个绝对文件号和相对文件号,两者都用于唯一性标识该数据文件,只不过标识范围不一样。

绝对文件号:

1 绝对文件号数据库范围内唯一标识一个数据文件

2 sql语句中常常用绝对文件号代替该数据文件名字。

3 绝对文件号可通过查询视图v$datafile|v$tempfile|dba_data_files|dba_temp_files相关字段file#|file_id 获得

例如:v$datafile 的file#字段

select file#,name,status from v$datafile

    FILE# NAME                                    STATUS

---------- ---------------------------------------- -------

        1 /oracle/CRM2/system1.dbf                SYSTEM

        2 /oracle/CRM2/zxb.dbf                    ONLINE

        3 /oracle/CRM2/CRM/sysaux01.dbf            ONLINE

        4 /oracle/CRM2/CRM/users01.dbf            ONLINE

        5 /oracle/CRM2/zxa.dbf                    ONLINE

        6 /oracle/CRM2/CRM/test1.dbf              ONLINE

        7 /oracle/CRM2/zxc.dbf                    ONLINE

        8 /oracle/CRM2/CRM/undotbs1.dbf            ONLINE

相当文件号:

1 相对文件号在表空间范围内唯一标识一个数据文件。

2 数据库内数据文件没有超过1023个,相对文件号和绝对文件号相等,反之则不同。

3 在大表空间中数据文件相对文件号总是1024

4 查询v$datafile|v$tempfile字段RFILE# ,dba_data_files|dba_temp_files字段RELATIVE_FNO等,可查出相对文件号。



例1如 v$datafile的字段rfile#

SQL> Select file#,rfile#,name,status from v$datafile;



    FILE#    RFILE#  NAME                                    STATUS

---------- ---------- ---------------------------------------- -------

        1          1  /oracle/CRM2/system1.dbf                SYSTEM

        2          2  /oracle/CRM2/zxb.dbf                    ONLINE

        3          3  /oracle/CRM2/CRM/sysaux01.dbf            ONLINE

        4          4  /oracle/CRM2/CRM/users01.dbf            ONLINE

        5          5  /oracle/CRM2/zxa.dbf                    ONLINE

        6          6  /oracle/CRM2/CRM/test1.dbf              ONLINE

        7          7  /oracle/CRM2/zxc.dbf                    ONLINE

        8          8  /oracle/CRM2/CRM/undotbs1.dbf            ONLINE



8 rows selected.

例2 大表空间绝对文件号和相对文件号情况



SQL> select file#,rfile#,name,status from v$datafile;



    FILE#    RFILE#  NAME                                    STATUS

---------- ---------- ---------------------------------------- -------

        1          1  /oracle/CRM2/system1.dbf                SYSTEM

        2          2  /oracle/CRM2/zxb.dbf                    ONLINE

        3          3  /oracle/CRM2/CRM/sysaux01.dbf            ONLINE

        4          4  /oracle/CRM2/CRM/users01.dbf            ONLINE

        5          5  /oracle/CRM2/zxa.dbf                    ONLINE

        6          6  /oracle/CRM2/CRM/test1.dbf              ONLINE

        7          7  /oracle/CRM2/zxc.dbf                      ONLINE

        8          8  /oracle/CRM2/CRM/undotbs1.dbf            ONLINE

        9      1024  /oracle/CRM2/CRM/zxbig.dbf              ONLINE



SQL>select file_id,relative_fno,file_name from dba_data_files order by 1

  FILE_ID RELATIVE_FNO  FILE_NAME

---------- ------------ ----------------------------------------

        1            1  /oracle/CRM2/system1.dbf

        2            2  /oracle/CRM2/zxb.dbf

        3            3  /oracle/CRM2/CRM/sysaux01.dbf

        4            4  /oracle/CRM2/CRM/users01.dbf

        5            5  /oracle/CRM2/zxa.dbf

        6            6  /oracle/CRM2/CRM/test1.dbf

        7            7  /oracle/CRM2/zxc.dbf

        8            8  /oracle/CRM2/CRM/undotbs1.dbf

        9        1024  /oracle/CRM2/CRM/zxbig.dbf

分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 支持支持 反对反对
回复

使用道具 举报

沙发
 楼主| 发表于 2016-8-20 10:41:36 | 只看该作者
模拟数据文件数超过1023个的情况:
--1.创建表空间
create tablespace ts_test datafile '/u01/app/oracle/oradata/sztech1/ts_test01.dbf' size 1m;

--2.修改最大文件数限制,否则,超过200就会报错
SQL> show parameter db_files

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
db_files                             integer     200

sql>alter system set db_files=5000 scope=spfile;

sql>startup force;

3.通过匿名块增加1020个数据文件.
begin
  for i in 1..1020 loop
    execute immediate 'alter tablespace ts_test add datafile ''/u01/app/oracle/oradata/sztech1/ts_test' || i || '.dbf'' size 1m';
  end loop;
end;

SQL> select count(*) from v$datafile;

  COUNT(*)
----------
      1026

4.察看相对文件号和绝对文件号,不一样了
SQL> col file_name for a50
SQL> select * from (select file_name,file_id,relative_fno from dba_data_files where tablespace_name='TS_TEST' order by file_id desc)
   where rownum<5
  

FILE_NAME                                             FILE_ID RELATIVE_FNO
-------------------------------------------------- ---------- ------------
/u01/app/oracle/oradata/sztech1/ts_test1020.dbf          1026            3
/u01/app/oracle/oradata/sztech1/ts_test1019.dbf          1025            2
/u01/app/oracle/oradata/sztech1/ts_test1018.dbf          1024            1
/u01/app/oracle/oradata/sztech1/ts_test1017.dbf          1023         1023
回复 支持 反对

使用道具 举报

板凳
 楼主| 发表于 2016-8-20 10:45:22 | 只看该作者
本帖最后由 郑全 于 2016-8-20 10:49 编辑

再增加表空间,大家看到,相对文件号和绝对文件号是不一样的:

SQL> create tablespace ts_bc datafile '/home/oracle/ts_bc001.dbf' size 1m;

Tablespace created.

SQL> select file_name,file_id,relative_fno from dba_data_files where tablespace_name='TS_BC';

FILE_NAME                                             FILE_ID RELATIVE_FNO
-------------------------------------------------- ---------- ------------
/home/oracle/ts_bc001.dbf                                1027            4

SQL>

因此,平时,如果在1023个文件之后,使用相对文件号,就会出现问题,建议使用绝对文件号.
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|手机版|小黑屋|重庆思庄Oracle、Redhat认证学习论坛 ( 渝ICP备12004239号-4 )

GMT+8, 2024-5-17 18:14 , Processed in 0.093552 second(s), 19 queries .

重庆思庄学习中心论坛-重庆思庄科技有限公司论坛

© 2001-2020

快速回复 返回顶部 返回列表