Backup Controlfile to Trace

A Simple Fact:

可以通过 ALTER DATABASE BACKUP CONTROLFILE TO TRACE来备份控制文件,产生的trace 文件中包含了用来创建控制文件的文本内容,不是二进制形式的,产生的trace文件默认是放在udump目录下的。

但是很不幸的是,我尝试了很多次这个命令,但是在udump下愣是没有找到任何trace文件! 如下....

-- Check the trace file in the directory udump
[oracle@ora10g udump]$ pwd
/u01/app/oracle/admin/orcl/udump
[oracle@ora10g udump]$ ls
orcl_ora_12361.trc orcl_ora_15074.trc orcl_ora_18777.trc orcl_ora_18885.trc
[oracle@ora10g udump]$
SQL> show user
USER is "SYS"
SQL
> alter database backup controlfile to trace;

Database altered.

SQL
>
-- remove all the trace file in directory udump to help identify newly created trace file
[oracle@ora10g udump]$ rm *.trc
[oracle
@ora10g udump]$ ls
[oracle
@ora10g udump]$

现在来执行backup controlfile的命令...

SQL> alter database backup controlfile to trace;

Database altered.

SQL
> alter database backup controlfile to trace;

Database altered.

SQL
> /

Database altered.

SQL
> /

Database altered.

SQL
>

虽然执行了很多次backup controlfile to trace的命令,但是udump目录下任何trace 文件都没有产生!

[oracle@ora10g udump]$ ls
[oracle
@ora10g udump]$ ls
[oracle
@ora10g udump]$ ls
[oracle
@ora10g udump]$ ls -l
total
0
[oracle
@ora10g udump]$

后来发现,同一个session只会生成一次trace文件,我刚开始删掉了udump下面所有的trace文件,其中就包括了之前那个session对应的trace文件。因此无论我后来执行了多少次的backup control file to trace的命令,udump下面也不会产生trace文件。解决方法就是先断掉之前的那个session,重新连接数据库再执行命令,如下,

SQL> exit
Disconnected
from Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
[oracle@ora10g ~]$ sqlplus / as sysdba

SQL
*Plus: Release 10.2.0.1.0 - Production on Wed Jan 19 17:52:47 2011

Copyright (c)
1982, 2005, Oracle. All rights reserved.


Connected
to:
Oracle
Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options

SQL
> alter database backup controlfile to trace;

Database altered.

SQL
>

现在再到udump目录下看看有没有trace文件生成....

[oracle@ora10g udump]$ ls
orcl_ora_20382.trc
[oracle
@ora10g udump]$

现在看到生成了一个新的trace文件。看看trace文件的内容...

[oracle@ora10g udump]$ cat orcl_ora_20382.trc
/u01/app/oracle/admin/orcl/udump/orcl_ora_20382.trc
Oracle
Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
ORACLE_HOME
= /u01/app/oracle/product/10.2.0/db_1
System name: Linux
Node name: ora10g
Release:
2.6.18-194.el5
Version: #
1 SMP Mon Mar 29 20:06:41 EDT 2010
Machine: i686
Instance name: orcl
Redo thread mounted
by this instance: 1
Oracle process
number: 17
Unix process pid:
20382, image: oracle@ora10g (TNS V1-V3)

*** SERVICE NAME:(SYS$USERS) 2011-01-19 17:52:57.438
*** SESSION ID:(140.24) 2011-01-19 17:52:57.438
*** 2011-01-19 17:52:57.438
-- 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="orcl"
--
--
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 "ORCL" NORESETLOGS ARCHIVELOG
MAXLOGFILES
16
MAXLOGMEMBERS
3
MAXDATAFILES
100
MAXINSTANCES
8
MAXLOGHISTORY
292
LOGFILE
GROUP 1 (
'/u01/app/oracle/oradata/orcl/redo01.log',
'/u01/app/oracle/oradata/orcl/redo01b.log'
) SIZE 50M,
GROUP 2 (
'/u01/app/oracle/oradata/orcl/redo02.log',
'/u01/app/oracle/oradata/orcl/redo02b.log'
) SIZE 50M,
GROUP 3 (
'/u01/app/oracle/oradata/orcl/redo03.log',
'/u01/app/oracle/oradata/orcl/redo03b.log'
) SIZE 50M
-- STANDBY LOGFILE
DATAFILE
'/u01/app/oracle/oradata/orcl/system01.dbf',
'/u01/app/oracle/oradata/orcl/undotbs01.dbf',
'/u01/app/oracle/oradata/orcl/sysaux01.dbf',
'/u01/app/oracle/oradata/orcl/users01.dbf',
'/u01/app/oracle/oradata/orcl/example01.dbf'
CHARACTER SET AL32UTF8
;
-- Configure RMAN configuration record 1
VARIABLE RECNO NUMBER;
EXECUTE :RECNO := SYS.DBMS_BACKUP_RESTORE.SETCONFIG('CONTROLFILE AUTOBACKUP','ON');
-- 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/ORCL/archivelog/2011_01_19/o1_mf_1_1_%u_.arc';
--
ALTER DATABASE REGISTER LOGFILE '/u01/app/oracle/flash_recovery_area/ORCL/archivelog/2011_01_19/o1_mf_1_1_%u_.arc';
--
ALTER DATABASE REGISTER LOGFILE '/u01/app/oracle/flash_recovery_area/ORCL/archivelog/2011_01_19/o1_mf_1_1_%u_.arc';
--
ALTER DATABASE REGISTER LOGFILE '/u01/app/oracle/flash_recovery_area/ORCL/archivelog/2011_01_19/o1_mf_1_1_%u_.arc';
--
ALTER DATABASE REGISTER LOGFILE '/u01/app/oracle/flash_recovery_area/ORCL/archivelog/2011_01_19/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/orcl/temp02.dbf'
SIZE
26214400 REUSE AUTOEXTEND ON NEXT 5242880 MAXSIZE 104857600 ;
-- 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 "ORCL" RESETLOGS ARCHIVELOG
MAXLOGFILES
16
MAXLOGMEMBERS
3
MAXDATAFILES
100
MAXINSTANCES
8
MAXLOGHISTORY
292
LOGFILE
GROUP 1 (
'/u01/app/oracle/oradata/orcl/redo01.log',
'/u01/app/oracle/oradata/orcl/redo01b.log'
) SIZE 50M,
GROUP 2 (
'/u01/app/oracle/oradata/orcl/redo02.log',
'/u01/app/oracle/oradata/orcl/redo02b.log'
) SIZE 50M,
GROUP 3 (
'/u01/app/oracle/oradata/orcl/redo03.log',
'/u01/app/oracle/oradata/orcl/redo03b.log'
) SIZE 50M
-- STANDBY LOGFILE
DATAFILE
'/u01/app/oracle/oradata/orcl/system01.dbf',
'/u01/app/oracle/oradata/orcl/undotbs01.dbf',
'/u01/app/oracle/oradata/orcl/sysaux01.dbf',
'/u01/app/oracle/oradata/orcl/users01.dbf',
'/u01/app/oracle/oradata/orcl/example01.dbf'
CHARACTER SET AL32UTF8
;
-- Configure RMAN configuration record 1
VARIABLE RECNO NUMBER;
EXECUTE :RECNO := SYS.DBMS_BACKUP_RESTORE.SETCONFIG('CONTROLFILE AUTOBACKUP','ON');
-- 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/ORCL/archivelog/2011_01_19/o1_mf_1_1_%u_.arc';
--
ALTER DATABASE REGISTER LOGFILE '/u01/app/oracle/flash_recovery_area/ORCL/archivelog/2011_01_19/o1_mf_1_1_%u_.arc';
--
ALTER DATABASE REGISTER LOGFILE '/u01/app/oracle/flash_recovery_area/ORCL/archivelog/2011_01_19/o1_mf_1_1_%u_.arc';
--
ALTER DATABASE REGISTER LOGFILE '/u01/app/oracle/flash_recovery_area/ORCL/archivelog/2011_01_19/o1_mf_1_1_%u_.arc';
--
ALTER DATABASE REGISTER LOGFILE '/u01/app/oracle/flash_recovery_area/ORCL/archivelog/2011_01_19/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/orcl/temp02.dbf'
SIZE
26214400 REUSE AUTOEXTEND ON NEXT 5242880 MAXSIZE 104857600 ;
-- End of tempfile additions.
--
[oracle@ora10g udump]$

问题虽然解决了,但是为了避免每次都要去判断哪个trace文件才对应backup controlfile命令,有没有一种方法可以指定生成trace文件的路径信息呢?Oracle自然应该支持这个很朴素的想法需求的。

可以通过如下的命令来备份控制文件到指定的trace文件中...

--Backing it up in a binary format:
alter database backup controlfile to '/some/arbitrary/path';
alter database backup controlfile to '/some/arbitrary/path' reuse;


--Backing it up in a human readable format:
alter database backup controlfile to trace as '/some/arbitrary/path';
alter database backup controlfile to trace as '/some/arbitrary/path' reuse;

来测试下...

SQL> alter database backup controlfile to trace
2 as '/u01/app/oracle/admin/orcl/test_controlbackup.trc';

Database altered.

SQL
>

来看看trace文件/u01/app/oracle/admin/orcl/test_controlbackup.trc有没有生成,

[oracle@ora10g orcl]$ pwd
/u01/app/oracle/admin/orcl
[oracle
@ora10g orcl]$ ls
adump bdump cdump dpdump pfile test_controlbackup.trc udump
[oracle
@ora10g orcl]$
[oracle@ora10g orcl]$ cat test_controlbackup.trc
-- 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="orcl"
--
-- 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
"ORCL" NORESETLOGS ARCHIVELOG
MAXLOGFILES
16
MAXLOGMEMBERS
3
MAXDATAFILES
100
MAXINSTANCES
8
MAXLOGHISTORY
292
LOGFILE
GROUP
1 (
'
/u01/app/oracle/oradata/orcl/redo01.log',
'
/u01/app/oracle/oradata/orcl/redo01b.log'
) SIZE 50M,
GROUP
2 (
'
/u01/app/oracle/oradata/orcl/redo02.log',
'
/u01/app/oracle/oradata/orcl/redo02b.log'
) SIZE 50M,
GROUP
3 (
'
/u01/app/oracle/oradata/orcl/redo03.log',
'
/u01/app/oracle/oradata/orcl/redo03b.log'
) SIZE 50M
-- STANDBY LOGFILE

DATAFILE
'
/u01/app/oracle/oradata/orcl/system01.dbf',
'
/u01/app/oracle/oradata/orcl/undotbs01.dbf',
'
/u01/app/oracle/oradata/orcl/sysaux01.dbf',
'
/u01/app/oracle/oradata/orcl/users01.dbf',
'
/u01/app/oracle/oradata/orcl/example01.dbf'
CHARACTER SET AL32UTF8
;

-- Configure RMAN configuration record 1
VARIABLE RECNO NUMBER;
EXECUTE :RECNO :
= SYS.DBMS_BACKUP_RESTORE.SETCONFIG('CONTROLFILE AUTOBACKUP','ON');
-- 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/ORCL/archivelog/2011_01_19/o1_mf_1_1_%u_.arc';
-- ALTER DATABASE REGISTER LOGFILE '/u01/app/oracle/flash_recovery_area/ORCL/archivelog/2011_01_19/o1_mf_1_1_%u_.arc';
-- ALTER DATABASE REGISTER LOGFILE '/u01/app/oracle/flash_recovery_area/ORCL/archivelog/2011_01_19/o1_mf_1_1_%u_.arc';
-- ALTER DATABASE REGISTER LOGFILE '/u01/app/oracle/flash_recovery_area/ORCL/archivelog/2011_01_19/o1_mf_1_1_%u_.arc';
-- ALTER DATABASE REGISTER LOGFILE '/u01/app/oracle/flash_recovery_area/ORCL/archivelog/2011_01_19/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/orcl/temp02.dbf'
SIZE
26214400 REUSE AUTOEXTEND ON NEXT 5242880 MAXSIZE 104857600 ;
-- 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
"ORCL" RESETLOGS ARCHIVELOG
MAXLOGFILES
16
MAXLOGMEMBERS
3
MAXDATAFILES
100
MAXINSTANCES
8
MAXLOGHISTORY
292
LOGFILE
GROUP
1 (
'
/u01/app/oracle/oradata/orcl/redo01.log',
'
/u01/app/oracle/oradata/orcl/redo01b.log'
) SIZE 50M,
GROUP
2 (
'
/u01/app/oracle/oradata/orcl/redo02.log',
'
/u01/app/oracle/oradata/orcl/redo02b.log'
) SIZE 50M,
GROUP
3 (
'
/u01/app/oracle/oradata/orcl/redo03.log',
'
/u01/app/oracle/oradata/orcl/redo03b.log'
) SIZE 50M
-- STANDBY LOGFILE

DATAFILE
'
/u01/app/oracle/oradata/orcl/system01.dbf',
'
/u01/app/oracle/oradata/orcl/undotbs01.dbf',
'
/u01/app/oracle/oradata/orcl/sysaux01.dbf',
'
/u01/app/oracle/oradata/orcl/users01.dbf',
'
/u01/app/oracle/oradata/orcl/example01.dbf'
CHARACTER SET AL32UTF8
;

-- Configure RMAN configuration record 1
VARIABLE RECNO NUMBER;
EXECUTE :RECNO :
= SYS.DBMS_BACKUP_RESTORE.SETCONFIG('CONTROLFILE AUTOBACKUP','ON');
-- 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/ORCL/archivelog/2011_01_19/o1_mf_1_1_%u_.arc';
-- ALTER DATABASE REGISTER LOGFILE '/u01/app/oracle/flash_recovery_area/ORCL/archivelog/2011_01_19/o1_mf_1_1_%u_.arc';
-- ALTER DATABASE REGISTER LOGFILE '/u01/app/oracle/flash_recovery_area/ORCL/archivelog/2011_01_19/o1_mf_1_1_%u_.arc';
-- ALTER DATABASE REGISTER LOGFILE '/u01/app/oracle/flash_recovery_area/ORCL/archivelog/2011_01_19/o1_mf_1_1_%u_.arc';
-- ALTER DATABASE REGISTER LOGFILE '/u01/app/oracle/flash_recovery_area/ORCL/archivelog/2011_01_19/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/orcl/temp02.dbf'
SIZE
26214400 REUSE AUTOEXTEND ON NEXT 5242880 MAXSIZE 104857600 ;
-- End of tempfile additions.
--
[oracle
@ora10g orcl]$



--------------------------------------
Regards,
FangwenYu
原文地址:https://www.cnblogs.com/fangwenyu/p/1939516.html