OS:Red Hat Linux As 5
DB:10.2.0.4
在全部控制文件丢失或损坏,而且没有备份的情况下,可以使用重建控制文件的办法打开数据库.以下模拟所有的控制文件丢失的情况下重建控制文件.
1.备份控制文件(数据库mount或是open状态)
SQL>select status from v$instance
STATUS
------------
OPEN
SQL>alter database backup controlfile to trace as '/u01/ftp/bak_controlfile'
2.删除控制文件
[oracle@hxl oracl]$ rm control01.ctl
rm: remove regular file `control01.ctl'? y
[oracle@hxl oracl]$ rm control02.ctl
rm: remove regular file `control02.ctl'? y
[oracle@hxl oracl]$ rm control03.ctl
rm: remove regular file `control03.ctl'? y
3.关闭数据库后尝试打开数据库
SQL>shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL>startup
ORACLE instance started.
Total System Global Area 734003200 bytes
Fixed Size 1221564 bytes
Variable Size 218106948 bytes
Database Buffers 511705088 bytes
Redo Buffers2969600 bytes
ORA-00205: error in identifying control file, check alert log for more info
这个时候数据无法打开,以为我们已经删除了控制文件.
4.查看备份控制文件的内容
[oracle@hxl ftp]$ more bak_controlfile
-- The following are current System-scope REDO Log Archival related
-- parameters and can be included in the database initialization file.
--
-- LOG_ARCHIVE_DEST=''
-- LOG_ARCHIVE_DUPLEX_DEST=''
--
-- LOG_ARCHIVE_FORMAT=%t_%s_%r.dbf
--
-- DB_UNIQUE_NAME="oracl"
--
-- LOG_ARCHIVE_CONFIG='SEND, RECEIVE, NODG_CONFIG'
-- LOG_ARCHIVE_MAX_PROCESSES=2
-- STANDBY_FILE_MANAGEMENT=MANUAL
-- STANDBY_ARCHIVE_DEST=?/dbs/arch
-- FAL_CLIENT=''
-- FAL_SERVER=''
--
-- LOG_ARCHIVE_DEST_10='LOCATION=USE_DB_RECOVERY_FILE_DEST'
-- LOG_ARCHIVE_DEST_10='OPTIONAL REOPEN=300 NODELAY'
-- LOG_ARCHIVE_DEST_10='ARCH NOAFFIRM NOEXPEDITE NOVERIFY SYNC'
-- LOG_ARCHIVE_DEST_10='REGISTER NOALTERNATE NODEPENDENCY'
-- LOG_ARCHIVE_DEST_10='NOMAX_FAILURE NOQUOTA_SIZE NOQUOTA_USED NODB_UNIQUE_NAME'
-- LOG_ARCHIVE_DEST_10='VALID_FOR=(PRIMARY_ROLE,ONLINE_LOGFILES)'
-- LOG_ARCHIVE_DEST_STATE_10=ENABLE
--
-- Below are two sets of SQL statements, each of which creates a new
-- control file and uses it to open the database. The first set opens
-- the database with the NORESETLOGS option and should be used only if
-- the current versions of all online logs are available. The second
-- set opens the database with the RESETLOGS option and should be used
-- if online logs are unavailable.
-- The appropriate set of statements can be copied from the trace into
-- a script file, edited as necessary, and executed when there is a
-- need to re-create the control file.
--
-- Set #1. NORESETLOGS case
--
-- The following commands will create a new control file and use it
-- to open the database.
-- Data used by Recovery Manager will be lost.
-- Additional logs may be required for media recovery of offline
-- Use this only if the current versions of all online logs are
-- available.
-- After mounting the created controlfile, the following SQL
-- statement will place the database in the appropriate
-- protection mode:
-- ALTER DATABASE SET STANDBY DATABASE TO MAXIMIZE PERFORMANCE
STARTUP NOMOUNT
CREATE CONTROLFILE REUSE DATABASE "ORACL" NORESETLOGS ARCHIVELOG
MAXLOGFILES 16
MAXLOGMEMBERS 3
MAXDATAFILES 100
MAXINSTANCES 8
MAXLOGHISTORY 292
LOGFILE
GROUP 1 '/u01/app/oracle/oradata/oracl/redo01.log' SIZE 50M,
GROUP 2 '/u01/app/oracle/oradata/oracl/redo02.log' SIZE 50M,
GROUP 3 '/u01/app/oracle/oradata/oracl/redo03.log' SIZE 50M
-- STANDBY LOGFILE
DATAFILE
'/u01/app/oracle/oradata/oracl/system01.dbf',
'/u01/app/oracle/oradata/oracl/undotbs01.dbf',
'/u01/app/oracle/oradata/oracl/sysaux01.dbf',
'/u01/app/oracle/oradata/oracl/users01.dbf'
CHARACTER SET WE8ISO8859P1
-- Commands to re-create incarnation table
-- Below log names MUST be changed to existing filenames on
-- disk. Any one log file from each branch can be used to
-- re-create incarnation records.
-- ALTER DATABASE REGISTER LOGFILE '/u01/app/oracle/flash_recovery_area/ORACL/archivelog/2012_06_12/o1_mf_1_1_%u_.arc'
-- ALTER DATABASE REGISTER LOGFILE '/u01/app/oracle/flash_recovery_area/ORACL/archivelog/2012_06_12/o1_mf_1_1_%u_.arc'
-- ALTER DATABASE REGISTER LOGFILE '/u01/app/oracle/flash_recovery_area/ORACL/archivelog/2012_06_12/o1_mf_1_1_%u_.arc'
-- ALTER DATABASE REGISTER LOGFILE '/u01/app/oracle/flash_recovery_area/ORACL/archivelog/2012_06_12/o1_mf_1_1_%u_.arc'
-- Recovery is required if any of the datafiles are restored backups,
-- or if the last shutdown was not normal or immediate.
RECOVER DATABASE
-- All logs need archiving and a log switch is needed.
ALTER SYSTEM ARCHIVE LOG ALL
-- Database can now be opened normally.
ALTER DATABASE OPEN
-- Commands to add tempfiles to temporary tablespaces.
-- Online tempfiles have complete space information.
-- Other tempfiles may require adjustment.
ALTER TABLESPACE TEMP ADD TEMPFILE '/u01/app/oracle/oradata/oracl/temp01.dbf'
SIZE 20971520 REUSE AUTOEXTEND ON NEXT 655360 MAXSIZE 32767M
-- End of tempfile additions.
--
-- Set #2. RESETLOGS case
--
-- The following commands will create a new control file and use it
-- to open the database.
-- Data used by Recovery Manager will be lost.
-- The contents of online logs will be lost and all backups will
-- be invalidated. Use this only if online logs are damaged.
-- After mounting the created controlfile, the following SQL
-- statement will place the database in the appropriate
-- protection mode:
-- ALTER DATABASE SET STANDBY DATABASE TO MAXIMIZE PERFORMANCE
STARTUP NOMOUNT
CREATE CONTROLFILE REUSE DATABASE "ORACL" RESETLOGS ARCHIVELOG
MAXLOGFILES 16
MAXLOGMEMBERS 3
MAXDATAFILES 100
MAXINSTANCES 8
MAXLOGHISTORY 292
LOGFILE
GROUP 1 '/u01/app/oracle/oradata/oracl/redo01.log' SIZE 50M,
GROUP 2 '/u01/app/oracle/oradata/oracl/redo02.log' SIZE 50M,
GROUP 3 '/u01/app/oracle/oradata/oracl/redo03.log' SIZE 50M
-- STANDBY LOGFILE
DATAFILE
'/u01/app/oracle/oradata/oracl/system01.dbf',
'/u01/app/oracle/oradata/oracl/undotbs01.dbf',
'/u01/app/oracle/oradata/oracl/sysaux01.dbf',
'/u01/app/oracle/oradata/oracl/users01.dbf'
CHARACTER SET WE8ISO8859P1
-- Commands to re-create incarnation table
-- Below log names MUST be changed to existing filenames on
-- disk. Any one log file from each branch can be used to
-- re-create incarnation records.
-- ALTER DATABASE REGISTER LOGFILE '/u01/app/oracle/flash_recovery_area/ORACL/archivelog/2012_06_12/o1_mf_1_1_%u_.arc'
-- ALTER DATABASE REGISTER LOGFILE '/u01/app/oracle/flash_recovery_area/ORACL/archivelog/2012_06_12/o1_mf_1_1_%u_.arc'
-- ALTER DATABASE REGISTER LOGFILE '/u01/app/oracle/flash_recovery_area/ORACL/archivelog/2012_06_12/o1_mf_1_1_%u_.arc'
-- ALTER DATABASE REGISTER LOGFILE '/u01/app/oracle/flash_recovery_area/ORACL/archivelog/2012_06_12/o1_mf_1_1_%u_.arc'
-- Recovery is required if any of the datafiles are restored backups,
-- or if the last shutdown was not normal or immediate.
RECOVER DATABASE USING BACKUP CONTROLFILE
-- Database can now be opened zeroing the online logs.
ALTER DATABASE OPEN RESETLOGS
-- Commands to add tempfiles to temporary tablespaces.
-- Online tempfiles have complete space information.
-- Other tempfiles may require adjustment.
ALTER TABLESPACE TEMP ADD TEMPFILE '/u01/app/oracle/oradata/oracl/temp01.dbf'
SIZE 20971520 REUSE AUTOEXTEND ON NEXT 655360 MAXSIZE 32767M
-- End of tempfile additions.
--
5.从备份控制文件中提取我们需要的部分,这里我们选择RESETLOGS,将如下内容保存文件为
create_confile.sql
CREATE CONTROLFILE REUSE DATABASE "ORACL" RESETLOGS ARCHIVELOG
MAXLOGFILES 16
MAXLOGMEMBERS 3
MAXDATAFILES 100
MAXINSTANCES 8
MAXLOGHISTORY 292
LOGFILE
GROUP 1 '/u01/app/oracle/oradata/oracl/redo01.log' SIZE 50M,
GROUP 2 '/u01/app/oracle/oradata/oracl/redo02.log' SIZE 50M,
GROUP 3 '/u01/app/oracle/oradata/oracl/redo03.log' SIZE 50M
-- STANDBY LOGFILE
DATAFILE
'/u01/app/oracle/oradata/oracl/system01.dbf',
'/u01/app/oracle/oradata/oracl/undotbs01.dbf',
'/u01/app/oracle/oradata/oracl/sysaux01.dbf',
'/u01/app/oracle/oradata/oracl/users01.dbf'
CHARACTER SET WE8ISO8859P1
6.执行create_confile.sql
SQL>set sqlblanklines on -- 因为文件中有空行,需要将该选项打开,否则执行的时候报语法错误
SQL>@/u01/ftp/create_confile.sql
SQL>alter database open resetlogs
Database altered.
说明:
重建控制文件后,若备份信息是存储在控制文件的,该信息会丢失.
甲骨文(Oracle)面试题目 这也许是你一直期待的文章,在关注这部分 技术 问题的同时,请务必阅读有关 面试 中有关个人的问题和解答。这里的回答并不是十分全面,这些问题可以通过多个角度来进行解释
,也许你不必在面试过程中给出完全详尽的答案,只需要通过你的解答使面试考官了解你
对ORACLE概念的熟悉程度。
1.解释冷备份和热备份的不同点以及各自的优点
解答:热备份针对归档模式的数据库,在数据库仍旧处于工作状态时进行备份。而冷
备份指在数据库关闭后,进行备份,适用于所有模式的数据库。热备份的优点在于当备份
时,数据库仍旧可以被使用并且可以将数据库恢复到任意一个 时间 点。冷备份的优点在于
它的备份和恢复 *** 作相当简单,并且由于冷备份的数据库可以工作在非归档模式下,数据库
性能会比归档模式稍好。(因为不必将archive log写入硬盘)
2.你必须利用备份恢复数据库,但是你没有控制文件,该如何解决问题呢?
解答:重建控制文件,用带backup control file 子句的recover 命令恢复数据库。
3.如何转换init.ora到spfile?
解答:使用create spfile from pfile 命令.
4.解释data block , extent 和 segment的区别(这里建议用英文术语)
解答:data block是数据库中最小的逻辑存储单元。当数据库的对象需要更多的物理
存储空间时,连续的data block就组成了extent . 一个数据库对象拥有的所有extents被
称为该对象的segment.
5.给出两个检查表结构的`方法
解答:1.DESCRIBE命令
2.DBMS_METADATA.GET_DDL 包
6.怎样查看数据库引擎的报错
解答:alert log.
7.比较truncate和delete 命令
解答:两者都可以用来删除表中所有的记录。区别在于:truncate是DDL *** 作,它移动
HWK,不需要rollback segment .而Delete是DML *** 作, 需要rollback segment 且花费较长
时间.
8.使用索引的理由
解答:快速访问表中的data block
9.给出在STAR SCHEMA中的两种表及它们分别含有的数据
解答:Fact tables 和dimension tables. fact table包含大量的主要的信息而dime
nsion tables 存放对fact table 某些属性描述的信息
10.FACT Table上需要建立何种索引?
解答:位图索引 (bitmap index)
11. 给出两种相关约束?
解答:主键和外键
12. 如何在不影响子表的前提下,重建一个母表
解答:子表的外键强制实效,重建母表,激活外键
13. 解释归档和非归档模式之间的不同和它们各自的优缺点
解答:归档模式是指你可以备份所有的数据库 transactions并恢复到任意一个时间点
。非归档模式则相反,不能恢复到任意一个时间点。但是非归档模式可以带来数据库性能
上的少许提高.
14. 如何建立一个备份控制文件?
解答:Alter database backup control file to trace.
15. 给出数据库正常启动所 经历 的几种状态 ?
解答:STARTUP NOMOUNT – 数据库实例启动
STARTUP MOUNT - 数据库装载
STARTUP OPEN – 数据库打开
16. 哪个column可以用来区别V$视图和GV$视图?
解答:INST_ID 指明集群环境中具体的 某个instance 。
17. 如何生成explain plan?
解答:运行utlxplan.sql. 建立plan 表
针对特定SQL语句,使用 explain plan set statement_id = 'tst1' into pl
an_table ,运行utlxplp.sql 或 utlxpls.sql察看explain plan
18. 如何增加buffer cache的命中率?
解答:在数据库较繁忙时,适用buffer cache advisory 工具,查询v$db_cache_adv
ice.如果有必要更改,可以使用 alter system set db_cache_size 命令
19. ORA-01555的应对方法?
解答:具体的出错信息是snapshot too old within rollback seg , 通常可以通过增
大rollback seg来解决问题。当然也需要察看一下具体造成错误的SQL文本
20. 解释$ORACLE_HOME和$ORACLE_BASE的区别?
解答:ORACLE_BASE是oracle的根目录,ORACLE_HOME是oracle产品的目录。
关于这个问题,要看损坏的是什么文件,以ORACLE数据库为例1控制文件,每个数据库默认有三个控制文件内容一样(比如CTRL01.DBF,CTRL02.DBF,CTRL03.DBF),损坏其中两个,只需把好的那个拷贝成另外两个的名称即可。如果所有控制文件都坏了,需要启动实例到nomount状态重建控制文件,前提是之前最好做过alterdatabasebackupcontrolfiletotrace会得到一个重建控制文件的脚本2在线日志(redolog),如果每个日志组(group)的member(成员)不止一个,同一组内的在线日志只要有一个完好,同样可以通过拷贝方式(停止数据库后)恢复。3TEMP表空间数据文件,可以理解为数据库用的临时文件,损坏后基本无数据损失,可以通过重建temp表空间恢复4.SYSTEM系统表空间,这个挂了基本上必须靠恢复了,前提是要有备份4.其它数据表空间4.1.有备份,可以恢复,但可能丢失数据4.2.未备份,无法恢复该表空间数据,可以选择使该表空间离线(offline),恢复其它数据欢迎分享,转载请注明来源:内存溢出
评论列表(0条)