Oracle数据文件大小的限制

联系:手机(13429648788)  QQ(107644445)

链接:https://www.orasos.com/oracle%e6%95%b0%e6%8d%ae%e6%96%87%e4%bb%b6%e5%a4%a7%e5%b0%8f%e7%9a%84%e9%99%90%e5%88%b6.html

标题:Oracle数据文件大小的限制

作者:惜分飞©版权所有[文章允许转载,但必须以链接方式注明源地址,否则追究法律责任.]

如果你比较细心,会注意到两件事情:
1、添加一个32g的数据文件会报错
SQL> alter tablespace users add datafile ‘/opt/oracle/oradata/test/user32g.dbf’ size 32g;
alter tablespace users add datafile ‘/opt/oracle/oradata/test/user32g.dbf’ size 32g
*
ERROR at line 1:
ORA-01144: File size (4194304 blocks) exceeds maximum of 4194303 blocks

SQL> !oerr ora 1144
01144, 00000, “File size (%s blocks) exceeds maximum of %s blocks”
// *Cause: Specified file size is larger than maximum allowable size value.
// *Action: Specify a smaller size.

2、添加一个maxsize为unlimited的数据文件
SQL> alter tablespace users add datafile ‘/opt/oracle/oradata/test/user32g.dbf’ size 10M AUTOEXTEND ON maxsize unlimited;

Tablespace altered.

SQL> select MAXBYTES/1024/1024/1024 from dba_data_files where file_name=’/opt/oracle/oradata/test/user32g.dbf’;

MAXBYTES/1024/1024/1024
———————–
31.9999847

你是不是有疑惑,为什么我添加32g的数据文件报错,为什么我添加一个数据文件maxsize设置为unlimited了,还是没有突破32g这个坎

原因分析:
由于Oracle的Rowid中使用22位来代表Block号,这22位最多只能代表2^22-1(4194303)个数据块,而在我们一般情况下使用的数据块大小为8k,所以数据文件的理论大小最大为: 31.9999924G
至于maxsize为unlimited时候,数据文件的大小为什么只有31.9999847G(blocks:4194301.99),比最大块数(4194303)少了一块,也许是和数据库和系统之间的衔接原因导致。
由上面的分析我们可以知道,数据文件大小和db_block_size有关,那我们可以得到这样的数据文件最大理论值

数据块 数据文件
2KB 8GB
4KB 16GB
8KB 32GB
16KB 64GB
32KB 128GB

注:以上规则适用于smallfile tablespace 下的数据文件,bigfile tablespace 下的数据文件不受此限制

2 thoughts on “Oracle数据文件大小的限制

  1. 操作系统显示的文件大小还要包含一个OS块
    [root@db2server ~]# ls -ltr /u01/app/oracle/oradata/tom/tom01.dbf
    -rw-r–r– 1 oracle oinstall 60620800 08-14 11:52 /u01/app/oracle/oradata/tom/tom01.dbf

    主要验证文件头与实际文件对比

    数据文件的第一个BLOCK的偏移量44记录了文件的大小
    BBED> p offset 44
    kcvfh.kcvfhhdr.kccfhfsz
    ———————–
    ub4 kccfhfsz @44 0x00001ce7
    SQL> select to_number(‘1ce7′,’xxxx’) from dual;

    TO_NUMBER(‘1CE7′,’XXXX’)
    ————————
    7399
    SQL> select 60620800/8192 from dual;

    60620800/8192
    ————-
    7400

Comments are closed.