db_files和maxdatafiles参数

ORACLE中控制datafile数量的有两个参数db_files和maxdatafiles,前者存在于spfile(pfile),后者则在控制文件中。


ORACLE官方文档里对两个参数的解释:

db_files:
DB_FILES specifies the maximum number of database files that can be opened for this database. The maximum valid value is the maximum number of files, subject to operating system constraint, that will ever be specified for the database, including files to be added by ADD DATAFILE statements.


maxdatafiles:
MAXDATAFILES specifies the maximum number of datafiles that can be open in the database. This number affects the initial sizing of the control file.

Note:
You can set several limits during database creation. Some of these limits are limited by and affected by operating system limits. For example, if you set MAXDATAFILES, Oracle Database allocates enough space in the control file to store MAXDATAFILES filenames, even if the database has only one datafile initially. However, because the maximum control file size is limited and operating system dependent, you might not be able to set all CREATE DATABASE parameters at their theoretical maximums.
For more information about setting limits during database creation, see the Oracle Database SQL Reference and your operating system specific Oracle documentation.


可见maxdatafiles主要控制的是controlfile中能够记录的datafile数量,而db_files实际控制datafile数量。


下面在CENTOS+ORACLE10.2.0.1.0上试验:

alter database backup controlfile to trace后查看控制文件

CREATE CONTROLFILE REUSE DATABASE "TEST" NORESETLOGS  NOARCHIVELOG
MAXLOGFILES 16
MAXLOGMEMBERS 3
MAXDATAFILES 8
MAXINSTANCES 8
MAXLOGHISTORY 292
LOGFILE
GROUP 1 '/home/oracle/10g/oradata/test/redo01.log'  SIZE 50M,
GROUP 2 '/home/oracle/10g/oradata/test/redo02.log'  SIZE 50M,
GROUP 3 '/home/oracle/10g/oradata/test/redo03.log'  SIZE 50M
-- STANDBY LOGFILE
DATAFILE
'/home/oracle/10g/oradata/test/system01.dbf',
'/home/oracle/10g/oradata/test/undotbs01.dbf',
'/home/oracle/10g/oradata/test/sysaux01.dbf',
'/home/oracle/10g/oradata/test/users01.dbf',
'/home/oracle/10g/oradata/test/example01.dbf'
CHARACTER SET WE8ISO8859P1
;
-- Commands to re-create incarnation table


查看db_files参数的设置
SQL> show parameter db_files;

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


SQL> select file_name from dba_data_files;

FILE_NAME
--------------------------------------------------------------------------------
/home/oracle/10g/oradata/test/users01.dbf
/home/oracle/10g/oradata/test/sysaux01.dbf
/home/oracle/10g/oradata/test/undotbs01.dbf
/home/oracle/10g/oradata/test/system01.dbf
/home/oracle/10g/oradata/test/example01.dbf
/home/oracle/10g/oradata/test/users02.dbf
/home/oracle/10g/oradata/test/users03.dbf
/home/oracle/10g/oradata/test/users04.dbf
/home/oracle/10g/oradata/test/users05.dbf
/home/oracle/10g/oradata/test/users06.dbf

10 rows selected.


修改db_files参数

SQL> alter system set db_files=11 scope=spfile;

System altered.

SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup
ORACLE instance started.


SQL> show parameter db_files;

NAME  TYPE  VALUE
------------------------------------ ----------- ------------------------------
db_files  integer  11


SQL> alter tablespace users add datafile '/home/oracle/10g/oradata/test/users07.dbf' size 1m;

Tablespace altered.

SQL> alter tablespace users add datafile '/home/oracle/10g/oradata/test/users08.dbf' size 1m;
alter tablespace users add datafile '/home/oracle/10g/oradata/test/users08.dbf' size 1m
*
ERROR at line 1:
ORA-00059: maximum number of DB_FILES exceeded


以上转自:http://blog.sina.com.cn/s/blog_70ca64640100vu4f.html 作者:hougoo


那么这两个参数有冲突时,谁起主导作用呢?


数据本版本11g,想测试一下如果参数这个db_files的限制会如何,而且controlfile中有个maxdatafiles的限制,不知道这两个限制到底谁是真正生效的

SQL> show parameter db_files;

NAME                             TYPE        VALUE

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

db_files                             integer     200

由于serverwindows的,先用linuxbash写个批量创建datafileshell吧,看来主机的知识可以帮助我们dba简化处理很多东西,当然小鱼在主机系统方面还是一个彻彻底底的小白,还需努力。

查看一下controlfilemaxdatafiles的参数,居然是100,感觉db_files才是主导datafiles数量的,controlfiles中的只是oracle在以前版本一个保留习惯而已。

CREATE CONTROLFILE REUSE DATABASE "XIAOYU" NORESETLOGS FORCE LOGGING ARCHIVELOG

   MAXLOGFILES 16

   MAXLOGMEMBERS 3

   MAXDATAFILES 100

   MAXINSTANCES 8

MAXLOGHISTORY 292

小鱼还是想做个test来彻底证实自己的结论。

[root@server119 ~]# vi /tmp/users.sh

# !/bin/bash

# echo "add tablespace"

for ((i=1;i<200;i++))

do

echo "alter tablespace users add datafile 'f:\app\oradata\xiaoyu\user${i}.dbf' size 1m;">>/tmp/test.txt

done

~

[root@server119 ~]# sh /tmp/users.sh

用生成的test.txt文件在server端批量加载datafile,达到db_files的限制后出现:

alter tablespace users add datafile 'f:\app\oradata\xiaoyu\user197.dbf' size 1m


ORA-00059: 超出 DB_FILES 的最大值

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


 COUNT(*)

----------

      200


SQL> alter system set db_files=300 scope=spfile;


System altered


重启数据库后

SQL> show parameter db_files;


NAME                                 TYPE        VALUE

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

db_files                             integer     300


SQL> alter tablespace users add datafile 'f:\app\oradata\xiaoyu\user197.dbf' size 1m;


Tablespace altered


真正起主导地位的是parameter的参数db_files,并不是controlfile中的maxdatafiles参数,而网络上有文章提到需要重建controlfile重置maxdatafiles大于db_files,而后修改db_files的方法是不可取的,小鱼也提醒大家对于网络上的文章还是需要用辨别的眼光去看,官方文档都可能有错误,套用某位大师的认知,不轻易相信任何人任何书籍的论点,必须要自己测试 推敲认知这个论点。



以上摘自:http://www.itpub.net/thread-1739233-1-1.html 作者:甲骨文小鱼


而“文本时代”大师在上贴中对此的进一步说明:

我原来也测过。只要db_files够,每当超过maxdatafiles,maxdatafiles会翻倍增加。
比如原来最大文件数是100,当创建101个文件时,最大文件数会变成200,当创建201个文件时,最大文件数变成400,然后是800、1600,等等。



相关的链接

ORACLE中数据文件大小及数量限制初探


你可能感兴趣的:(db_files,maxdatafiles)