前段时间碰到一个数据库的数据文件数(200)达到了数据库定义的参数db_files的值,而原本需要使用alter system可以修改这个参数,但是因为限制该参数的maxdatafiles值(由控制文件定义)仪200,故要想改大db_files参数值,需要重建控制文件,下面是我个人根据实验总结的操作过程。
一、参数察看
$sqlplus /nolog
conn / as sysdba
SQL> show parameter db_files;
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
db_files integer 200
由此可看出db_files值为200,如果数据库中数据文件数达到或超过200,就需要更改该参数了。
更改db_files有两种情况:
1, 如果控制文件中定义的maxdatafiles以及系统允许打开的文件数值大于200,则可以通过alter方式来修改db_files的值
2, 如果控制文件中maxdatafiles值等于200,则需要重建控制文件来修改maxdatafiles值。
察看maxdatafiles方法
SQL>alter database backup controlfile to trace;
到$ORACLE_BASE/admin/db_name/udump下面查找最新生成的trc文件
$grep –i MAXDATAFILES boss_ora_4310.trc
MAXDATAFILES 200
MAXDATAFILES 200
系统允许打开文件数可用ulimit –a察看
$ulimit –a
open files (-n) 1024
二、修改步骤
1,生成控制文件创建脚本
SQL>alter database backup controlfile to trace;
在$ORACLE_BASE/admin/db_name/udump目下新生成的trc文件oracle/admin/boss/udump/boss_ora_4310.trc
根据上述文件创建控制文件生成脚本recreate_control.sql
STARTUP NOMOUNT
CREATE CONTROLFILE REUSE DATABASE "BOSS" NORESETLOGS NOARCHIVELOG
MAXLOGFILES 16
MAXLOGMEMBERS 3
MAXDATAFILES 300 修改MAXDATAFILES值
MAXINSTANCES 8
MAXLOGHISTORY 292
LOGFILE
GROUP 1 '/oracle/oradata/boss/redo01.log' SIZE 50M,
GROUP 2 '/oracle/oradata/boss/redo02.log' SIZE 50M,
GROUP 3 '/oracle/oradata/boss/redo03.log' SIZE 50M
-- STANDBY LOGFILE
DATAFILE
'/oracle/oradata/boss/system01.dbf',
'/oracle/oradata/boss/undotbs01.dbf',
'/oracle/oradata/boss/sysaux01.dbf',
'/oracle/oradata/boss/users01.dbf',
'/oracle/oradata/boss/example01.dbf'
CHARACTER SET ZHS16GBK
;
2,关闭数据库
SQL>shutdown
3, 备份原有控制文件,删除原有控制文件
备份控制文件
cd /oracle/oradata/boss/
cp control01.ctl control01.ctl.0520
cp control02.ctl control02.ctl.0520
cp control03.ctl control03.ctl.0520
删除控制文件
rm control0*.ctl
4, 创建新的控制文件
$sqlplus /nolog
SQL>conn / as sysdba
SQL>@ oracle/admin/boss/udump/recreate_control.sql
ORACLE instance started.
Total System Global Area 268435456 bytes
Fixed Size 1218892 bytes
Variable Size 75499188 bytes
Database Buffers 188743680 bytes
Redo Buffers 2973696 bytes
Control file created.
5,使用控制文件恢复
SQL> RECOVER DATABASE USING BACKUP CONTROLFILE
ORA-00279: change 567684 generated at 05/15/2010 00:19:32 needed for thread 1
ORA-00289: suggestion :
/oracle/flash_recovery_area/BOSS/archivelog/2010_05_15/o1_mf_1_3_%u_.arc
ORA-00280: change 567684 for thread 1 is in sequence #3
Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
/oracle/oradata/boss/redo01.log
ORA-00310: archived log contains sequence 2; sequence 3 required
ORA-00334: archived log: '/oracle/oradata/boss/redo01.log'
SQL> RECOVER DATABASE USING BACKUP CONTROLFILE
ORA-00279: change 567684 generated at 05/15/2010 00:19:32 needed for thread 1
ORA-00289: suggestion :
/oracle/flash_recovery_area/BOSS/archivelog/2010_05_15/o1_mf_1_3_%u_.arc
ORA-00280: change 567684 for thread 1 is in sequence #3
Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
/oracle/oradata/boss/redo02.log
Log applied.
Media recovery complete.
这里恢复要使用redo在线日志,需要逐个尝试,直到介质恢复成功。
6,resetlogs方式启动数据库
SQL> ALTER DATABASE OPEN RESETLOGS;
Database altered
7,恢复临时表空间
SQL> ALTER TABLESPACE TEMP ADD TEMPFILE '/oracle/oradata/boss/temp01.dbf'
2 SIZE 20971520 REUSE AUTOEXTEND ON NEXT 655360 MAXSIZE 32767M;
Tablespace altered.
8,修改参数
SQL> show parameter db_files;
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
db_files integer 200
SQL> alter system set db_files=250 scope=spfile;
System altered.
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup
ORACLE instance started.
Total System Global Area 268435456 bytes
Fixed Size 1218892 bytes
Variable Size 75499188 bytes
Database Buffers 188743680 bytes
Redo Buffers 2973696 bytes
Database mounted.
Database opened.
SQL>show parameter db_files
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
db_files integer 250
SQL> exit
至此db_files参数修改工作完成
当然,如果控制文件损坏或丢失,也可以使用这种方法来恢复数据库。