RMAN表空间按时间点恢复(四)

使用镜像副本提高RMAN TSPITR的性能
在执行TSPITR时,通过让RMAN使用磁盘上已经存在的恢复集和辅助集数据文件镜像副本,而不是从备份中还原它们将会显著提高TSPITR的性能。可以使用configure auxname命令来使用恢复集数据文件或辅助集数据文件的镜像副本或者使用set newname命令使用辅助集数据文件镜像副本,来告诉RMAN可能存在数据文件的镜像副本。

具体的详细细节依赖于使用的命令和文件是否是辅助集或恢复集文件,通常来说,在指定目录中存在合适的镜像副本,那么在执行TSPITR时,RMAN会从目标实例中RMAN档案库中注消镜像副本并将其登记到辅助实例的控制文件中。辅助实例将使用镜像副本来执行按时间点恢复。

使用configure auxname来使用恢复集镜像副本执行TSPITR
在执行TSPIRT时,RMAN在指定的AUXNAME目录查找数据文件,使用比目标时间还早的检查点SCN来查看是否存在数据文件的镜像备份。如果找到了镜像备份,将会被TSPITR使用。否则,数据文件会被还原和恢复到原始目录中,通过auxname指定目录中的任何文件都不会被改变或删除。

SQL> truncate table tspitr;

Table truncated.

SQL> select count(*) from tspitr;

  COUNT(*)
----------
         0

执行恢复命令

RMAN> run
2> {
3> configure auxname for datafile '/u01/app/oracle/oradata/test/tspitr01.dbf' to '/u01/app/oracle/oradata/auxiliary/tspitr01.dbf';
4> recover tablespace tspitr until logseq 32 auxiliary destination '/u01/app/oracle/oradata/auxiliary';
5> }

auxiliary name for datafile 6 set to: /u01/app/oracle/oradata/auxiliary/tspitr01.dbf
new RMAN configuration parameters are successfully stored
starting full resync of recovery catalog
full resync complete

Starting recover at 2015-03-16 21:11:05
using channel ORA_DISK_1

Creating automatic instance, with SID='okpE'

initialization parameters used for automatic instance:
db_name=TEST
compatible=10.2.0.5.0
db_block_size=8192
db_files=200
db_unique_name=tspitr_TEST_okpE
sga_target=180M
processes=50
#No auxiliary parameter file used
db_create_file_dest=/u01/app/oracle/oradata/auxiliary
control_files=/u01/app/oracle/oradata/auxiliary/cntrl_tspitr_TEST_okpE.f


starting up automatic instance TEST

Oracle instance started

Total System Global Area     188743680 bytes

Fixed Size                     1272720 bytes
Variable Size                 62915696 bytes
Database Buffers             121634816 bytes
Redo Buffers                   2920448 bytes
Automatic instance created

contents of Memory Script:
{
# set the until clause
set until  logseq 32 thread 1;
# restore the controlfile
restore clone controlfile;
# mount the controlfile
sql clone 'alter database mount clone database';
# archive current online log for tspitr to a resent until time
sql 'alter system archive log current';
# avoid unnecessary autobackups for structural changes during TSPITR
sql 'begin dbms_backup_restore.AutoBackupFlag(FALSE); end;';
# resync catalog after controlfile restore
resync catalog;
}
executing Memory Script

executing command: SET until clause

Starting restore at 2015-03-16 21:11:10
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: sid=47 devtype=DISK

channel ORA_AUX_DISK_1: starting datafile backupset restore
channel ORA_AUX_DISK_1: restoring control file
channel ORA_AUX_DISK_1: reading from backup piece /u01/app/oracle/flash_recovery_area/TEST/autobackup/2015_03_16/o1_mf_s_874492659_bjdjhno1_.bkp
channel ORA_AUX_DISK_1: restored backup piece 1
piece handle=/u01/app/oracle/flash_recovery_area/TEST/autobackup/2015_03_16/o1_mf_s_874492659_bjdjhno1_.bkp tag=TAG20150316T103739
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:02
output filename=/u01/app/oracle/oradata/auxiliary/cntrl_tspitr_TEST_okpE.f
Finished restore at 2015-03-16 21:11:13

sql statement: alter database mount clone database

sql statement: alter system archive log current

sql statement: begin dbms_backup_restore.AutoBackupFlag(FALSE); end;

starting full resync of recovery catalog
full resync complete

contents of Memory Script:
{
# generated tablespace point-in-time recovery script
# set the until clause
set until  logseq 32 thread 1;
plsql < <<-- tspitr_2
declare
  sqlstatement       varchar2(512);
  offline_not_needed exception;
  pragma exception_init(offline_not_needed, -01539);
begin
  sqlstatement := 'alter tablespace '||  'TSPITR' ||' offline for recover';
  krmicd.writeMsg(6162, sqlstatement);
  krmicd.execSql(sqlstatement);
exception
  when offline_not_needed then
    null;
end; >>>;
# set an omf destination filename for restore
set newname for clone datafile  1 to new;
# set an omf destination filename for restore
set newname for clone datafile  2 to new;
# set an omf destination tempfile
set newname for clone tempfile  1 to new;
# set a destination filename for restore
set newname for datafile  6 to
 "/u01/app/oracle/oradata/test/tspitr01.dbf";
# rename all tempfiles
switch clone tempfile all;
# restore the tablespaces in the recovery set plus the auxilliary tablespaces
restore clone datafile  1, 2, 6;
switch clone datafile all;
#online the datafiles restored or flipped
sql clone "alter database datafile  1 online";
#online the datafiles restored or flipped
sql clone "alter database datafile  2 online";
#online the datafiles restored or flipped
sql clone "alter database datafile  6 online";
# make the controlfile point at the restored datafiles, then recover them
recover clone database tablespace  "TSPITR", "SYSTEM", "UNDOTBS1" delete archivelog;
alter clone database open resetlogs;
# PLUG HERE the creation of a temporary tablespace if export fails due to lack
# of temporary space.
# For example in Unix these two lines would do that:
#sql clone "create tablespace aux_tspitr_tmp
#           datafile ''/tmp/aux_tspitr_tmp.dbf'' size 500K";
}
executing Memory Script

executing command: SET until clause

sql statement: alter tablespace TSPITR offline for recover

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

renamed temporary file 1 to /u01/app/oracle/oradata/auxiliary/TSPITR_TEST_OKPE/datafile/o1_mf_temp_%u_.tmp in control file

Starting restore at 2015-03-16 21:11:21
using channel ORA_AUX_DISK_1

channel ORA_AUX_DISK_1: starting datafile backupset restore
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
restoring datafile 00001 to /u01/app/oracle/oradata/auxiliary/TSPITR_TEST_OKPE/datafile/o1_mf_system_%u_.dbf
restoring datafile 00002 to /u01/app/oracle/oradata/auxiliary/TSPITR_TEST_OKPE/datafile/o1_mf_undotbs1_%u_.dbf
restoring datafile 00006 to /u01/app/oracle/oradata/test/tspitr01.dbf
channel ORA_AUX_DISK_1: reading from backup piece /u02/ora_test874492578_361
channel ORA_AUX_DISK_1: restored backup piece 1
piece handle=/u02/ora_test874492578_361 tag=TAG20150316T103617
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:55
Finished restore at 2015-03-16 21:12:17

datafile 1 switched to datafile copy
input datafile copy recid=20 stamp=874530737 filename=/u01/app/oracle/oradata/auxiliary/TSPITR_TEST_OKPE/datafile/o1_mf_system_bjfomtoh_.dbf
datafile 2 switched to datafile copy
input datafile copy recid=21 stamp=874530737 filename=/u01/app/oracle/oradata/auxiliary/TSPITR_TEST_OKPE/datafile/o1_mf_undotbs1_bjfomttc_.dbf

sql statement: alter database datafile  1 online

sql statement: alter database datafile  2 online

sql statement: alter database datafile  6 online

Starting recover at 2015-03-16 21:12:17
using channel ORA_AUX_DISK_1

starting media recovery

archive log thread 1 sequence 31 is already on disk as file /u02/1_31_870806981.dbf
channel ORA_AUX_DISK_1: starting archive log restore to default destination
channel ORA_AUX_DISK_1: restoring archive log
archive log thread=1 sequence=30
channel ORA_AUX_DISK_1: reading from backup piece /u02/ora_test874492656_371
channel ORA_AUX_DISK_1: restored backup piece 1
piece handle=/u02/ora_test874492656_371 tag=TAG20150316T103735
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:02
archive log filename=/u01/app/oracle/10.2.0/db/dbs/arch1_30_870806981.dbf thread=1 sequence=30
channel clone_default: deleting archive log(s)
archive log filename=/u01/app/oracle/10.2.0/db/dbs/arch1_30_870806981.dbf recid=38 stamp=874530741
archive log filename=/u02/1_31_870806981.dbf thread=1 sequence=31
media recovery complete, elapsed time: 00:00:01
Finished recover at 2015-03-16 21:12:23

database opened

contents of Memory Script:
{
# export the tablespaces in the recovery set
host 'exp userid =\"/@\(DESCRIPTION=\(ADDRESS=\(PROTOCOL=beq\)\(PROGRAM=/u01/app/oracle/10.2.0/db/bin/oracle\)\(ARGV0=oracleokpE\)\(ARGS=^'\(DESCRIPTION=\(LOCAL=YES\)\(ADDRESS=\(PROTOCOL=beq\)\)\)^'\)\(ENVS=^'ORACLE_SID=okpE^'\)\)\(CONNECT_DATA=\(SID=okpE\)\)\) as sysdba\" point_in_time_recover=y tablespaces=
 TSPITR file=
tspitr_a.dmp';
# shutdown clone before import
shutdown clone immediate
# import the tablespaces in the recovery set
host 'imp userid =\"sys/zzh_2046@test as sysdba\" point_in_time_recover=y file=
tspitr_a.dmp';
# online/offline the tablespace imported
sql "alter tablespace TSPITR online";
sql "alter tablespace  TSPITR offline";
# enable autobackups in case user does open resetlogs from RMAN after TSPITR
sql 'begin dbms_backup_restore.AutoBackupFlag(TRUE); end;';
# resync catalog after tspitr finished
resync catalog;
}
executing Memory Script


Export: Release 10.2.0.5.0 - Production on Mon Mar 16 21:12:50 2015

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


Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Export done in ZHS16GBK character set and AL16UTF16 NCHAR character set
Note: table data (rows) will not be exported

About to export Tablespace Point-in-time Recovery objects...
For tablespace TSPITR ...
. exporting cluster definitions
. exporting table definitions
. . exporting table                         TSPITR
. exporting referential integrity constraints
. exporting triggers
. end point-in-time recovery
Export terminated successfully without warnings.
host command complete

database closed
database dismounted
Oracle instance shut down


Import: Release 10.2.0.5.0 - Production on Mon Mar 16 21:13:12 2015

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


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

Export file created by EXPORT:V10.02.01 via conventional path
About to import Tablespace Point-in-time Recovery objects...
import done in ZHS16GBK character set and AL16UTF16 NCHAR character set
. importing SYS's objects into SYS
. importing TSPITR's objects into TSPITR
. . importing table                       "TSPITR"
. importing SYS's objects into SYS
Import terminated successfully without warnings.
host command complete

sql statement: alter tablespace TSPITR online

sql statement: alter tablespace  TSPITR offline

sql statement: begin dbms_backup_restore.AutoBackupFlag(TRUE); end;

starting full resync of recovery catalog
full resync complete

Removing automatic instance
Automatic instance removed
auxiliary instance file /u01/app/oracle/oradata/auxiliary/cntrl_tspitr_TEST_okpE.f deleted
auxiliary instance file /u01/app/oracle/oradata/auxiliary/TSPITR_TEST_OKPE/datafile/o1_mf_system_bjfomtoh_.dbf deleted
auxiliary instance file /u01/app/oracle/oradata/auxiliary/TSPITR_TEST_OKPE/datafile/o1_mf_undotbs1_bjfomttc_.dbf deleted
auxiliary instance file /u01/app/oracle/oradata/auxiliary/TSPITR_TEST_OKPE/datafile/o1_mf_temp_bjfop5sn_.tmp deleted
auxiliary instance file /u01/app/oracle/oradata/auxiliary/TSPITR_TEST_OKPE/onlinelog/o1_mf_1_bjfooq75_.log deleted
auxiliary instance file /u01/app/oracle/oradata/auxiliary/TSPITR_TEST_OKPE/onlinelog/o1_mf_2_bjfootjb_.log deleted
auxiliary instance file /u01/app/oracle/oradata/auxiliary/TSPITR_TEST_OKPE/onlinelog/o1_mf_3_bjfooxd8_.log deleted
Finished recover at 2015-03-16 21:13:17

从上面的auxiliary name for datafile 6 set to: /u01/app/oracle/oradata/auxiliary/tspitr01.dbf
信息可以看到确实为恢复集数据文件使用了镜像副本来执行tspitr。

SQL> select tablespace_name,status from dba_tablespaces;

TABLESPACE_NAME                STATUS
------------------------------ ---------
SYSTEM                         ONLINE
UNDOTBS1                       ONLINE
SYSAUX                         ONLINE
TEMP                           ONLINE
USERS                          ONLINE
EXAMPLE                        ONLINE
TSPITR                         OFFLINE

7 rows selected.

RMAN> sql 'alter tablespace tspitr online';

sql statement: alter tablespace tspitr online
starting full resync of recovery catalog
full resync complete

SQL> select tablespace_name,status from dba_tablespaces;

TABLESPACE_NAME                STATUS
------------------------------ ---------
SYSTEM                         ONLINE
UNDOTBS1                       ONLINE
SYSAUX                         ONLINE
TEMP                           ONLINE
USERS                          ONLINE
EXAMPLE                        ONLINE
TSPITR                         ONLINE

7 rows selected.

SQL> select count(*) from tspitr;

  COUNT(*)
----------
     50678

configure auxname的主要作用是一种基本技术通过消除还原时间来提高TSPITR的性能。如果有预计要执行TSPITR操作的表空间,可以在备份程序中维护一组表空间相关数据文件的镜像副本,并定期将镜像副本更新到TSPITR所要恢复到的目标时间之前的时间点:
1.当设置这种策略时,为文件配置一次auxname
2.定期执行 backup as copy datafile n format auxname来维护镜像副本的更新,或者为了更好的性能使用增量更新备份策略。
3.当需要执行TSPITR时,指定自上次更新镜像副本之后的一个目标时间。

在计划使用镜像副本执行TSPIRT时,记住你不可能提前知道表空间将要使用的镜像副本。在要执行TSPITR的表空间和其它表空间之间存在关联时,要将相关的表空间加入到最终的恢复集中并且其它表空间可能存在于辅助集中。应该为每个数据文件配置一个auxname让其成为恢复集中的一部分并经常更新所有数据文件的镜像副本。

如果没有正确的估计恢复集所包含的表空间或者因为开销原因不想对恢复集中所有表空间维护镜像副本,可以使用只维护所有数据文件的一个子集的策略。如果只准备了所有数据文件的一个子集所对应的镜像副本,TSPITR的处理仍然相同。这个处理过程时间会变长,因为RMAN必须将没有镜像副本的恢复集中的数据文件恢复到它们原来的目录中。

当使用configure auxname来重命名恢复集文件时重命名方法的优先级仍然是要遵守的。对于相同文件的set newname命令将会覆盖configure auxname命令行为。

执行set newname和configure auxname来使用辅助集镜像副本执行TSPITR与恢复集数据文件一样,configure auxname命令给辅助集数据文件镜像副本设置一个永久的替代目录,
set newname在RUN块中设置替代目录。然而,RMAN对辅助集数据文件的处理不同于恢复集数据文件。

如果使用set newname来给辅助集数据文件指定新目录并且在这个目录中存在镜像副本且镜像副本的SCN是可以用来执行TSPITR操作,那么镜像副本会被使用。如果在指定的新目录中没有可用的镜像副本,那么RMAN会从备份中还原一个可用的副本(如果存在的镜像副本的SCN号在TSPITR的目标时间之后,那么会使用还原的文件覆盖存在数据文件)。

如果使用configure auxname来给辅助集数据文件指定新目录并且这个目录中存在镜像副本且镜像副本的SCN可以用来执行TSPITR操作,那么镜像副本会被使用。如果在指定的新目录中没有可用的镜像副本,那么RMAN会从备份中还原数据文件。

不管镜像副本是在执行TSPITR之前被创建,还是在执行TSPITR时从备份中还原生成,与所有辅助集文件一样,在TSPITR成功执行完后会被删除或者当TSPITR失败后保留用来进行诊断。

RMAN表空间按时间点恢复(三)

重命名TSPITR辅助集数据文件
不像恢复集数据文件通常会被存储在它们原始目录中,辅助集数据文件不能覆盖目标数据库中相关文件。如果不对辅助集文件指定一个新目录而是使用原始目录,那么当RMAN试图覆盖原始目录中的相关文件时,会发现这些文件正在使用,那么TSPITR操作会失败。

为辅助集数据文件指定目录最简单的方法是为TSPITR指定一个辅助目录。然而RMAN支持两种方法来控制辅助集数据文件的目录:一是使用set newname来对单个文件指定新文件名,二是使用db_file_name_convert参数提将目标数据库中的数据文件名转换为辅助数据库中的数据文件名。

尽管你打算使用这些方法来给特定文件指定目录,仍然建议你给recover tablespace命令使用auxliary destination参数。如果你忽略了重命名一些辅助集数据文件,这将确保TSPITR操作仍然执行成功。存储在辅助目录中的任何文件不会被重命名。

使用set newname来重命名TSPITR辅助集数据文件
为了使用set newname命令来为辅助集数据文件指定新的文件名,在RUN块中使用recover tablespace命令,并且使用set newname命令来重命名文件。例如,下面我们对表空间tspitr执行tspitr将表空间恢复到logseq=32的时间点,并使用set newname将辅助集中的数据文件’ /u01/app/oracle/oradata/test/system01.dbf’重命名为’ /u01/app/oracle/oradata/auxiliary/system01.dbf’:

再次对表tspitr执行truncate操作:

SQL> truncate table tspitr;

Table truncated.

SQL> select count(*) from tspitr;

  COUNT(*)
----------
         0

执行恢复命令

RMAN> run
2> {
3> set newname for datafile '/u01/app/oracle/oradata/test/system01.dbf' to '/u01/app/oracle/oradata/auxiliary/system01.dbf';
4> recover tablespace tspitr until logseq 32 auxiliary destination '/u01/app/oracle/oradata/auxiliary';
5> }

executing command: SET NEWNAME

Starting recover at 2015-03-16 19:34:58
using channel ORA_DISK_1

Creating automatic instance, with SID='pqny'

initialization parameters used for automatic instance:
db_name=TEST
compatible=10.2.0.5.0
db_block_size=8192
db_files=200
db_unique_name=tspitr_TEST_pqny
sga_target=180M
processes=50
#No auxiliary parameter file used
db_create_file_dest=/u01/app/oracle/oradata/auxiliary
control_files=/u01/app/oracle/oradata/auxiliary/cntrl_tspitr_TEST_pqny.f


starting up automatic instance TEST

Oracle instance started

Total System Global Area     188743680 bytes

Fixed Size                     1272720 bytes
Variable Size                 62915696 bytes
Database Buffers             121634816 bytes
Redo Buffers                   2920448 bytes
Automatic instance created

contents of Memory Script:
{
# set the until clause
set until  logseq 32 thread 1;
# restore the controlfile
restore clone controlfile;
# mount the controlfile
sql clone 'alter database mount clone database';
# archive current online log for tspitr to a resent until time
sql 'alter system archive log current';
# avoid unnecessary autobackups for structural changes during TSPITR
sql 'begin dbms_backup_restore.AutoBackupFlag(FALSE); end;';
# resync catalog after controlfile restore
resync catalog;
}
executing Memory Script

executing command: SET until clause

Starting restore at 2015-03-16 19:34:59
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: sid=47 devtype=DISK

channel ORA_AUX_DISK_1: starting datafile backupset restore
channel ORA_AUX_DISK_1: restoring control file
channel ORA_AUX_DISK_1: reading from backup piece /u01/app/oracle/flash_recovery_area/TEST/autobackup/2015_03_16/o1_mf_s_874492659_bjdjhno1_.bkp
channel ORA_AUX_DISK_1: restored backup piece 1
piece handle=/u01/app/oracle/flash_recovery_area/TEST/autobackup/2015_03_16/o1_mf_s_874492659_bjdjhno1_.bkp tag=TAG20150316T103739
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:02
output filename=/u01/app/oracle/oradata/auxiliary/cntrl_tspitr_TEST_pqny.f
Finished restore at 2015-03-16 19:35:02

sql statement: alter database mount clone database

sql statement: alter system archive log current

sql statement: begin dbms_backup_restore.AutoBackupFlag(FALSE); end;

starting full resync of recovery catalog
full resync complete

contents of Memory Script:
{
# generated tablespace point-in-time recovery script
# set the until clause
set until  logseq 32 thread 1;
# set a destination filename for restore
set newname for datafile  1 to
 "/u01/app/oracle/oradata/auxiliary/system01.dbf";
# set an omf destination filename for restore
set newname for clone datafile  2 to new;
# set an omf destination tempfile
set newname for clone tempfile  1 to new;
# set a destination filename for restore
set newname for datafile  6 to
 "/u01/app/oracle/oradata/test/tspitr01.dbf";
# rename all tempfiles
switch clone tempfile all;
# restore the tablespaces in the recovery set plus the auxilliary tablespaces
restore clone datafile  1, 2, 6;
switch clone datafile all;
#online the datafiles restored or flipped
sql clone "alter database datafile  1 online";
#online the datafiles restored or flipped
sql clone "alter database datafile  2 online";
#online the datafiles restored or flipped
sql clone "alter database datafile  6 online";
# make the controlfile point at the restored datafiles, then recover them
recover clone database tablespace  "TSPITR", "SYSTEM", "UNDOTBS1" delete archivelog;
alter clone database open resetlogs;
# PLUG HERE the creation of a temporary tablespace if export fails due to lack
# of temporary space.
# For example in Unix these two lines would do that:
#sql clone "create tablespace aux_tspitr_tmp
#           datafile ''/tmp/aux_tspitr_tmp.dbf'' size 500K";
}
executing Memory Script

executing command: SET until clause

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

renamed temporary file 1 to /u01/app/oracle/oradata/auxiliary/TSPITR_TEST_PQNY/datafile/o1_mf_temp_%u_.tmp in control file

Starting restore at 2015-03-16 19:35:09
using channel ORA_AUX_DISK_1

channel ORA_AUX_DISK_1: starting datafile backupset restore
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
restoring datafile 00001 to /u01/app/oracle/oradata/auxiliary/system01.dbf
restoring datafile 00002 to /u01/app/oracle/oradata/auxiliary/TSPITR_TEST_PQNY/datafile/o1_mf_undotbs1_%u_.dbf
restoring datafile 00006 to /u01/app/oracle/oradata/test/tspitr01.dbf
channel ORA_AUX_DISK_1: reading from backup piece /u02/ora_test874492578_361
channel ORA_AUX_DISK_1: restored backup piece 1
piece handle=/u02/ora_test874492578_361 tag=TAG20150316T103617
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:01:07
Finished restore at 2015-03-16 19:36:18

datafile 1 switched to datafile copy
input datafile copy recid=19 stamp=874524979 filename=/u01/app/oracle/oradata/auxiliary/system01.dbf
datafile 2 switched to datafile copy
input datafile copy recid=20 stamp=874524979 filename=/u01/app/oracle/oradata/auxiliary/TSPITR_TEST_PQNY/datafile/o1_mf_undotbs1_bjfhzg5k_.dbf

sql statement: alter database datafile  1 online

sql statement: alter database datafile  2 online

sql statement: alter database datafile  6 online

Starting recover at 2015-03-16 19:36:21
using channel ORA_AUX_DISK_1

starting media recovery

archive log thread 1 sequence 31 is already on disk as file /u02/1_31_870806981.dbf
channel ORA_AUX_DISK_1: starting archive log restore to default destination
channel ORA_AUX_DISK_1: restoring archive log
archive log thread=1 sequence=30
channel ORA_AUX_DISK_1: reading from backup piece /u02/ora_test874492656_371
channel ORA_AUX_DISK_1: restored backup piece 1
piece handle=/u02/ora_test874492656_371 tag=TAG20150316T103735
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:02
archive log filename=/u01/app/oracle/10.2.0/db/dbs/arch1_30_870806981.dbf thread=1 sequence=30
channel clone_default: deleting archive log(s)
archive log filename=/u01/app/oracle/10.2.0/db/dbs/arch1_30_870806981.dbf recid=38 stamp=874524983
archive log filename=/u02/1_31_870806981.dbf thread=1 sequence=31
media recovery complete, elapsed time: 00:00:03
Finished recover at 2015-03-16 19:36:27

database opened

contents of Memory Script:
{
# export the tablespaces in the recovery set
host 'exp userid =\"/@\(DESCRIPTION=\(ADDRESS=\(PROTOCOL=beq\)\(PROGRAM=/u01/app/oracle/10.2.0/db/bin/oracle\)\(ARGV0=oraclepqny\)\(ARGS=^'\(DESCRIPTION=\(LOCAL=YES\)\(ADDRESS=\(PROTOCOL=beq\)\)\)^'\)\(ENVS=^'ORACLE_SID=pqny^'\)\)\(CONNECT_DATA=\(SID=pqny\)\)\) as sysdba\" point_in_time_recover=y tablespaces=
 TSPITR file=
tspitr_a.dmp';
# shutdown clone before import
shutdown clone immediate
# import the tablespaces in the recovery set
host 'imp userid =\"sys/zzh_2046@test as sysdba\" point_in_time_recover=y file=
tspitr_a.dmp';
# online/offline the tablespace imported
sql "alter tablespace TSPITR online";
sql "alter tablespace  TSPITR offline";
# enable autobackups in case user does open resetlogs from RMAN after TSPITR
sql 'begin dbms_backup_restore.AutoBackupFlag(TRUE); end;';
# resync catalog after tspitr finished
resync catalog;
}
executing Memory Script


Export: Release 10.2.0.5.0 - Production on Mon Mar 16 19:36:56 2015

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


Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Export done in ZHS16GBK character set and AL16UTF16 NCHAR character set
Note: table data (rows) will not be exported

About to export Tablespace Point-in-time Recovery objects...
For tablespace TSPITR ...
. exporting cluster definitions
. exporting table definitions
. . exporting table                         TSPITR
. exporting referential integrity constraints
. exporting triggers
. end point-in-time recovery
Export terminated successfully without warnings.
host command complete

database closed
database dismounted
Oracle instance shut down


Import: Release 10.2.0.5.0 - Production on Mon Mar 16 19:37:17 2015

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


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

Export file created by EXPORT:V10.02.01 via conventional path
About to import Tablespace Point-in-time Recovery objects...
import done in ZHS16GBK character set and AL16UTF16 NCHAR character set
. importing SYS's objects into SYS
. importing TSPITR's objects into TSPITR
. . importing table                       "TSPITR"
. importing SYS's objects into SYS
Import terminated successfully without warnings.
host command complete

sql statement: alter tablespace TSPITR online

sql statement: alter tablespace  TSPITR offline

sql statement: begin dbms_backup_restore.AutoBackupFlag(TRUE); end;

starting full resync of recovery catalog
full resync complete

Removing automatic instance
Automatic instance removed
auxiliary instance file /u01/app/oracle/oradata/auxiliary/cntrl_tspitr_TEST_pqny.f deleted
auxiliary instance file /u01/app/oracle/oradata/auxiliary/system01.dbf deleted
auxiliary instance file /u01/app/oracle/oradata/auxiliary/TSPITR_TEST_PQNY/datafile/o1_mf_undotbs1_bjfhzg5k_.dbf deleted
auxiliary instance file /u01/app/oracle/oradata/auxiliary/TSPITR_TEST_PQNY/datafile/o1_mf_temp_bjfj2d21_.tmp deleted
auxiliary instance file /u01/app/oracle/oradata/auxiliary/TSPITR_TEST_PQNY/onlinelog/o1_mf_1_bjfj1w22_.log deleted
auxiliary instance file /u01/app/oracle/oradata/auxiliary/TSPITR_TEST_PQNY/onlinelog/o1_mf_2_bjfj1z44_.log deleted
auxiliary instance file /u01/app/oracle/oradata/auxiliary/TSPITR_TEST_PQNY/onlinelog/o1_mf_3_bjfj249p_.log deleted
Finished recover at 2015-03-16 19:37:26

SQL> select tablespace_name,status from dba_tablespaces;

TABLESPACE_NAME                STATUS
------------------------------ ---------
SYSTEM                         ONLINE
UNDOTBS1                       ONLINE
SYSAUX                         ONLINE
TEMP                           ONLINE
USERS                          ONLINE
EXAMPLE                        ONLINE
TSPITR                         OFFLINE

7 rows selected.

RMAN> sql 'alter tablespace tspitr online';

sql statement: alter tablespace tspitr online
starting full resync of recovery catalog
full resync complete

SQL> select tablespace_name,status from dba_tablespaces;

TABLESPACE_NAME                STATUS
------------------------------ ---------
SYSTEM                         ONLINE
UNDOTBS1                       ONLINE
SYSAUX                         ONLINE
TEMP                           ONLINE
USERS                          ONLINE
EXAMPLE                        ONLINE
TSPITR                         ONLINE

7 rows selected.

SQL> select count(*) from tspitr;

  COUNT(*)
----------
     50678

从上面的结果可以看到对表空间tspitr恢复成功。

使用db_file_name_convert来重命名辅助集数据文件
如果不想对所有辅助集数据文件使用一个辅助目录,但也不想为每个文件单独命名,可以在辅助实例中设置db_file_name_convert参数。只有在以下两种情况下使用这个参数:
1.如果会为RMAN自动管理辅助实例创建自己的参数文件。
2.如果将要创建单独的辅助实例。
在辅助实例中的db_file_name_convert参数的作用是用来根据目标实例相关文件的原始文件名在辅助实例中生成相应的文件名。这个参数值由字符对列表组成。
例如,假设目标实例包含以下文件:
.system表空间中的/u01/app/oracle/oradata/test/system01.dbf
.undotbs表空间中的/u01/app/oracle/oradata/test/undotbs01.dbf

并且想将这些相关文件重新存储在辅助实例的’/u01/app/oracle/oradata/auxiliary ‘目录中,那么在辅助实例参数文件中增加以下记录:
DB_FILE_NAME_CONVERT=(‘/u01/app/oracle/oradata/test/ ‘, ‘/u01/app/oracle/oradata/auxiliary ‘)

在辅助实例中相关文件的新文件名就是如下形式:
/u01/app/oracle/oradata/auxiliary /system01.dbf和/u01/app/oracle/oradata/auxiliary /undotbs01.dbf

最重要的是要记住db_file_name_convert参数必须在辅助实例参数文件中进行设置。

如果辅助实例是手动创建的,将db_file_name_convert参数加入到辅助实例参数文件中。

注意仍然可以使用set newname或configure auxname来重命名单个辅助集数据文件。如果文件不匹配由db_file_name_convert参数所提供的匹配模式,那么文件是不会被重命名的。可以使用有auxiliary destination参数的recover tablespace命令来确保所有辅助集数据文件被发送到指定目录中。如果没有对辅助实例中的文件提供新文件名的命名方法,那么执行TSPITR将会失败。

使用db_file_name_convert重命名ASM OMF数据文件
当目标实例使用OMF管理数据文件对于辅助实例使用db_file_name_convert参数不能被用来控制文件的新文件名。当目标实例使用OMF管理数据文件时,通过替目标实例OMF文件名的相应字符串不能在辅助实例上生成有效的OMF文件名。当使用ASM OMF管理数据文件时,RMAN会将这些无效的文件名转换为有效的文件名。

为了避免这个问题,使用其它的支持选项来为OMF文件生成新文件名(包括存储在ASM中的数据文件):
1.使用辅助目录
2.在辅助实例中使用db_create_file_dest参数来为没有使用set newname或configure auxname指定新文件名的所有辅助实例文件指定目录
3.对于ASM文件,可以使用set newname为单个文件指定辅助实例可以访问的磁盘组(并允许数据库使用指定的磁盘组生成文件名)。例如:

RUN {
SET NEWNAME FOR DATAFILE 1 TO "+DISK2";
SET NEWNAME FOR DATAFILE 2 TO "+DISK3";
RECOVER TABLESPACE users, tools
UNTIL LOGSEQ 1300 THREAD 1
AUXILIARY DESTINATION '/disk1/auxdest';
}

执行TSPITR时重命名临时文件
临时文件被认为数据库辅助集的一部分。当创建辅助实例时,可以使用set newname for tempfile,db_file_name_convert或auxiliary destination来重命名临时文件。当打开辅助数据库时,会使用适用的重命名规则来创建临时文件。当清除辅助实例时,临时文件会和其它的辅助实例文件一起被删除。

TSPITR文件重命名方法之间的优先顺序
不同的重命名文件方法遵守以下的优先顺序:
1.set newname
2.configure auxname
3.db_file_name_convert
4.recover tablespace命令中的auxiliary destination参数

在同时使用几种重命名文件方法时,优先级高的会覆盖优先级低的重命名方法(例如,在目标数据库上执行recover tablespace … auxiliary destination时,也使用configure auxname为一些辅助集数据文件重命名文件名时,configure auxname会覆盖recover tablespace … auxiliary destination)。
可以使用show auxname命令来查看任何当前的configure auxname设置。

设置辅助实例控制文件目录
如果使用客户端参数文件可以为辅助实例设置控制文件目录。可以设置control_files参数来指定你要存储控制文件的目录。

如果没有为控制文件显式地指定目录,如果在执行TSPITR时使用了auxiliary destination参数,RMAN将会把控制文件存放在辅助目录中。如果在执行TSPITR时没有使用auxiliary destination参数,辅助实例控制文件将会存储在操作系统特定目录中(在Unix中,ORACLE_HOME/rdbms/admin/params_auxinit.ora)

不管将辅助实例控制文件存储在什么目录中,在TSPITR操作成功执行完后都是会被删除的。因为控制文件相对较小,RMAN在创建辅助控制文件遇到错误的概率是很小的,但如果创建控制文件的目录没有足够的空间,TSPITR操作将会失败。

设置辅助实例联机重做日志目录
如果在辅助实例参数文件中设置了log_file_name_convert参数,这个参数将会决定联机重做日志文件的存储目录。否则,如果RMAN正使用辅助目录和管理辅助实例,将会在辅助目录中创建联机重做日志文件。
注意,如果没有使用log_file_name_convert或auxiliary destination来指定联机重做日志文件目录,在试图创建联机重做日志文件时TSPITR操作会失败。即使在参数文件中设置了db_file_create_dest或者log_file_create_dest参数,在执行TSPITR时也不会对辅助实例创建联机重做日志文件。

使用log_file_name_convert重命名ASM OMF重做日志文件
当目标实例使用OMF时,在辅助实例中设置log_file_name_convert参数不能用来为重做日志文件生成新文件名。当目标实例使用OMF时,不能通过替换目标实例OMF文件名中的相关字符串来为辅助实例生成有效的OMF文件名。当使用ASM OMF时,RMAN在指定磁盘组中使用模式匹配的磁盘组名来生成有效的文件名。

为了避免这种问题,可以使用其它支持的方法为OMF重做日志文件生成新文件名(包括存储在ASM中的文件):
1.使用辅助目录
2.在辅助实例中设置db_create_file_dest,db_recovery_file_dest或db_create_online_log_dest_n参数来指定目录

RMAN表空间按时间点恢复(二)

使用自定义自动辅助实例执行TSPITR
1.重命名或重新放置恢复集的数据文件,因此在TSPITR执行完成后,被恢复表空间所包含的数据文件将不会存储在其原始位置(例如当包含表空间的原始磁盘不可使用时)。
2.对一些或所有的辅助数据文件指定辅助目录之外的目录。如果在单个磁盘上没有足够的空间来处理所有辅助集文件时可以这样做。
3.提前设置镜像副本备份数据文件,来避免从备份中还原而提高TSPITR的速度。
4.对辅助实例使用不同的通道配置
5.为RMAN管理的辅助实例指定不同的初始化参数

使用set newname来重命名TSPITR恢复集中的数据文件
如果不想恢复集中的数据文件被还原和恢复到它们原来的目录中,在RUN块中使用set newname命令来为从备份中还原和恢复的数据文件指定新的存储目录。

例如下面我们将为恢复集中表空间tspitr的数据文件‘/u01/app/oracle/oradata/test/tspitr01.dbf’重命名为
’ /u01/app/oracle/oradata/auxiliary/tspitr01.dbf’

再次执行truncate table tspitr操作:

SQL> truncate table tspitr;

Table truncated.

SQL> select count(*) from tspitr;

  COUNT(*)
----------
         0

下面再次将表空间tspitr恢复到logseq=32的时间点,我这里因为使用了恢复目录,在第一次执行tspitr后,可以再次恢复到logseq=32这个时间点。

RMAN> run
2> {
3> set newname for datafile '/u01/app/oracle/oradata/test/tspitr01.dbf' to ' /u01/app/oracle/oradata/auxiliary/tspitr01.dbf';
4> recover tablespace tspitr until logseq 32 auxiliary destination '/u01/app/oracle/oradata/auxiliary';
5> }

executing command: SET NEWNAME

Starting recover at 2015-03-16 17:42:10
using channel ORA_DISK_1

Creating automatic instance, with SID='pjzc'

initialization parameters used for automatic instance:
db_name=TEST
compatible=10.2.0.5.0
db_block_size=8192
db_files=200
db_unique_name=tspitr_TEST_pjzc
sga_target=180M
processes=50
#No auxiliary parameter file used
db_create_file_dest=/u01/app/oracle/oradata/auxiliary
control_files=/u01/app/oracle/oradata/auxiliary/cntrl_tspitr_TEST_pjzc.f


starting up automatic instance TEST

Oracle instance started

Total System Global Area     188743680 bytes

Fixed Size                     1272720 bytes
Variable Size                 62915696 bytes
Database Buffers             121634816 bytes
Redo Buffers                   2920448 bytes
Automatic instance created

contents of Memory Script:
{
# set the until clause
set until  logseq 32 thread 1;
# restore the controlfile
restore clone controlfile;
# mount the controlfile
sql clone 'alter database mount clone database';
# archive current online log for tspitr to a resent until time
sql 'alter system archive log current';
# avoid unnecessary autobackups for structural changes during TSPITR
sql 'begin dbms_backup_restore.AutoBackupFlag(FALSE); end;';
# resync catalog after controlfile restore
resync catalog;
}
executing Memory Script

executing command: SET until clause

Starting restore at 2015-03-16 17:42:11
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: sid=47 devtype=DISK

channel ORA_AUX_DISK_1: starting datafile backupset restore
channel ORA_AUX_DISK_1: restoring control file
channel ORA_AUX_DISK_1: reading from backup piece /u01/app/oracle/flash_recovery_area/TEST/autobackup/2015_03_16/o1_mf_s_874492659_bjdjhno1_.bkp
channel ORA_AUX_DISK_1: restored backup piece 1
piece handle=/u01/app/oracle/flash_recovery_area/TEST/autobackup/2015_03_16/o1_mf_s_874492659_bjdjhno1_.bkp tag=TAG20150316T103739
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:02
output filename=/u01/app/oracle/oradata/auxiliary/cntrl_tspitr_TEST_pjzc.f
Finished restore at 2015-03-16 17:42:15

sql statement: alter database mount clone database

sql statement: alter system archive log current

sql statement: begin dbms_backup_restore.AutoBackupFlag(FALSE); end;

starting full resync of recovery catalog
full resync complete

contents of Memory Script:
{
# generated tablespace point-in-time recovery script
# set the until clause
set until  logseq 32 thread 1;
plsql < <<-- tspitr_2
declare
  sqlstatement       varchar2(512);
  offline_not_needed exception;
  pragma exception_init(offline_not_needed, -01539);
begin
  sqlstatement := 'alter tablespace '||  'TSPITR' ||' offline for recover';
  krmicd.writeMsg(6162, sqlstatement);
  krmicd.execSql(sqlstatement);
exception
  when offline_not_needed then
    null;
end; >>>;
# set an omf destination filename for restore
set newname for clone datafile  1 to new;
# set an omf destination filename for restore
set newname for clone datafile  2 to new;
# set an omf destination tempfile
set newname for clone tempfile  1 to new;
# set a destination filename for restore
set newname for datafile  6 to
 "/u01/app/oracle/oradata/test/tspitr01.dbf";
# rename all tempfiles
switch clone tempfile all;
# restore the tablespaces in the recovery set plus the auxilliary tablespaces
restore clone datafile  1, 2, 6;
switch clone datafile all;
#online the datafiles restored or flipped
sql clone "alter database datafile  1 online";
#online the datafiles restored or flipped
sql clone "alter database datafile  2 online";
#online the datafiles restored or flipped
sql clone "alter database datafile  6 online";
# make the controlfile point at the restored datafiles, then recover them
recover clone database tablespace  "TSPITR", "SYSTEM", "UNDOTBS1" delete archivelog;
alter clone database open resetlogs;
# PLUG HERE the creation of a temporary tablespace if export fails due to lack
# of temporary space.
# For example in Unix these two lines would do that:
#sql clone "create tablespace aux_tspitr_tmp
#           datafile ''/tmp/aux_tspitr_tmp.dbf'' size 500K";
}
executing Memory Script

executing command: SET until clause

sql statement: alter tablespace TSPITR offline for recover

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

renamed temporary file 1 to /u01/app/oracle/oradata/auxiliary/TSPITR_TEST_PJZC/datafile/o1_mf_temp_%u_.tmp in control file

Starting restore at 2015-03-16 17:42:23
using channel ORA_AUX_DISK_1

channel ORA_AUX_DISK_1: starting datafile backupset restore
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
restoring datafile 00001 to /u01/app/oracle/oradata/auxiliary/TSPITR_TEST_PJZC/datafile/o1_mf_system_%u_.dbf
restoring datafile 00002 to /u01/app/oracle/oradata/auxiliary/TSPITR_TEST_PJZC/datafile/o1_mf_undotbs1_%u_.dbf
restoring datafile 00006 to /u01/app/oracle/oradata/test/tspitr01.dbf
channel ORA_AUX_DISK_1: reading from backup piece /u02/ora_test874492578_361
channel ORA_AUX_DISK_1: restored backup piece 1
piece handle=/u02/ora_test874492578_361 tag=TAG20150316T103617
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:56
Finished restore at 2015-03-16 17:43:21

datafile 1 switched to datafile copy
input datafile copy recid=19 stamp=874518201 filename=/u01/app/oracle/oradata/auxiliary/TSPITR_TEST_PJZC/datafile/o1_mf_system_bjf9d12k_.dbf
datafile 2 switched to datafile copy
input datafile copy recid=20 stamp=874518201 filename=/u01/app/oracle/oradata/auxiliary/TSPITR_TEST_PJZC/datafile/o1_mf_undotbs1_bjf9d14c_.dbf

sql statement: alter database datafile  1 online

sql statement: alter database datafile  2 online

sql statement: alter database datafile  6 online

Starting recover at 2015-03-16 17:43:22
using channel ORA_AUX_DISK_1

starting media recovery

archive log thread 1 sequence 31 is already on disk as file /u02/1_31_870806981.dbf
channel ORA_AUX_DISK_1: starting archive log restore to default destination
channel ORA_AUX_DISK_1: restoring archive log
archive log thread=1 sequence=30
channel ORA_AUX_DISK_1: reading from backup piece /u02/ora_test874492656_371
channel ORA_AUX_DISK_1: restored backup piece 1
piece handle=/u02/ora_test874492656_371 tag=TAG20150316T103735
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:02
archive log filename=/u01/app/oracle/10.2.0/db/dbs/arch1_30_870806981.dbf thread=1 sequence=30
channel clone_default: deleting archive log(s)
archive log filename=/u01/app/oracle/10.2.0/db/dbs/arch1_30_870806981.dbf recid=38 stamp=874518204
archive log filename=/u02/1_31_870806981.dbf thread=1 sequence=31
media recovery complete, elapsed time: 00:00:02
Finished recover at 2015-03-16 17:43:27

database opened

contents of Memory Script:
{
# export the tablespaces in the recovery set
host 'exp userid =\"/@\(DESCRIPTION=\(ADDRESS=\(PROTOCOL=beq\)\(PROGRAM=/u01/app/oracle/10.2.0/db/bin/oracle\)\(ARGV0=oraclepjzc\)\(ARGS=^'\(DESCRIPTION=\(LOCAL=YES\)\(ADDRESS=\(PROTOCOL=beq\)\)\)^'\)\(ENVS=^'ORACLE_SID=pjzc^'\)\)\(CONNECT_DATA=\(SID=pjzc\)\)\) as sysdba\" point_in_time_recover=y tablespaces=
 TSPITR file=
tspitr_a.dmp';
# shutdown clone before import
shutdown clone immediate
# import the tablespaces in the recovery set
host 'imp userid =\"sys/zzh_2046@test as sysdba\" point_in_time_recover=y file=
tspitr_a.dmp';
# online/offline the tablespace imported
sql "alter tablespace TSPITR online";
sql "alter tablespace  TSPITR offline";
# enable autobackups in case user does open resetlogs from RMAN after TSPITR
sql 'begin dbms_backup_restore.AutoBackupFlag(TRUE); end;';
# resync catalog after tspitr finished
resync catalog;
}
executing Memory Script


Export: Release 10.2.0.5.0 - Production on Mon Mar 16 17:43:51 2015

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


Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Export done in ZHS16GBK character set and AL16UTF16 NCHAR character set
Note: table data (rows) will not be exported

About to export Tablespace Point-in-time Recovery objects...
For tablespace TSPITR ...
. exporting cluster definitions
. exporting table definitions
. . exporting table                         TSPITR
. exporting referential integrity constraints
. exporting triggers
. end point-in-time recovery
Export terminated successfully without warnings.
host command complete

database closed
database dismounted
Oracle instance shut down


Import: Release 10.2.0.5.0 - Production on Mon Mar 16 17:44:12 2015

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


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

Export file created by EXPORT:V10.02.01 via conventional path
About to import Tablespace Point-in-time Recovery objects...
import done in ZHS16GBK character set and AL16UTF16 NCHAR character set
. importing SYS's objects into SYS
. importing TSPITR's objects into TSPITR
. . importing table                       "TSPITR"
. importing SYS's objects into SYS
Import terminated successfully without warnings.
host command complete

sql statement: alter tablespace TSPITR online

sql statement: alter tablespace  TSPITR offline

sql statement: begin dbms_backup_restore.AutoBackupFlag(TRUE); end;

starting full resync of recovery catalog
full resync complete

Removing automatic instance
Automatic instance removed
auxiliary instance file /u01/app/oracle/oradata/auxiliary/cntrl_tspitr_TEST_pjzc.f deleted
auxiliary instance file /u01/app/oracle/oradata/auxiliary/TSPITR_TEST_PJZC/datafile/o1_mf_system_bjf9d12k_.dbf deleted
auxiliary instance file /u01/app/oracle/oradata/auxiliary/TSPITR_TEST_PJZC/datafile/o1_mf_undotbs1_bjf9d14c_.dbf deleted
auxiliary instance file /u01/app/oracle/oradata/auxiliary/TSPITR_TEST_PJZC/datafile/o1_mf_temp_bjf9gdqh_.tmp deleted
auxiliary instance file /u01/app/oracle/oradata/auxiliary/TSPITR_TEST_PJZC/onlinelog/o1_mf_1_bjf9fz9y_.log deleted
auxiliary instance file /u01/app/oracle/oradata/auxiliary/TSPITR_TEST_PJZC/onlinelog/o1_mf_2_bjf9g25c_.log deleted
auxiliary instance file /u01/app/oracle/oradata/auxiliary/TSPITR_TEST_PJZC/onlinelog/o1_mf_3_bjf9g4yj_.log deleted
Finished recover at 2015-03-16 17:44:21

SQL> select tablespace_name,status from dba_tablespaces;

TABLESPACE_NAME                STATUS
------------------------------ ---------
SYSTEM                         ONLINE
UNDOTBS1                       ONLINE
SYSAUX                         ONLINE
TEMP                           ONLINE
USERS                          ONLINE
EXAMPLE                        ONLINE
TSPITR                         OFFLINE

7 rows selected.

将表空间tspitr联机

SQL> select tablespace_name,status from dba_tablespaces;

TABLESPACE_NAME                STATUS
------------------------------ ---------
SYSTEM                         ONLINE
UNDOTBS1                       ONLINE
SYSAUX                         ONLINE
TEMP                           ONLINE
USERS                          ONLINE
EXAMPLE                        ONLINE
TSPITR                         ONLINE

7 rows selected.

SQL> select count(*) from tspitr;

  COUNT(*)
----------
     50678

如果set newname命令指定的数据文件名与目标数据库中的有效数据文件名存在冲突,那么RMAN在执行recover命令时没返回错误信息。有效的数据文件不会被覆盖。

注意直到真实执行recover tablespace … until操作为止,RMAN不会检测使用set newname所设置的文件名与当前数据文件名之间的冲突。在真实执行recover tablespace … until操作时会检测这种冲突。

RMAN表空间按时间点恢复(一)

一.表空间按时间点恢复
RMAN的自动表空间按时间点恢复(TSPITR)能让你将数据库中的一个或多个表空间快速恢复到之前的某个时间点,而不会影响数据库中的其它表空间和对象。

为了有效地使用表空间按时间点恢复(TSPITR),需要理解你需要解决的问题是什么,使用TSPITR的主要原因是什么,在执行TSPITR时RMAN将会执行那些操作,何时以及如何使用TSPITR,使用TSPITR有那些限制。

二.执行TSPITR的操作步骤
为了使用RMAN和自动辅助实例来对恢复集执行TSPITR,需要对TSPITR进行一些准备工作,然后执行recover tablespace命令来指定要恢复的表空间和按时间点恢复的目标时间和辅助目标(如果需要的话)。
执行TSPITR,RMAN将会执行以下步骤:
1.如果没有连接到辅助实例,RMAN将创建一个辅助实例,启动并连接到辅助实例。
2.在目标数据库中将要被恢复的表空间置于脱机状态。
3.对辅助实例使用恢复目标时间之前的控制文件备份来还原控制文件。
4.从恢复集和辅助集中将数据文件还原到辅助实例。还原的数据文件可以存储在你指定的目录中或者是文件的原始目录中(对于恢复集文件)或者在辅助目录中(对于辅助集文件,如果你使用了有auxliary destination参数的recover tablespace命令)。
5.在辅助实例中将数据文件还原和恢复到指定的目标时间点。
6.使用resetlogs选项将辅助实例打开
7.导出目标数据库中要恢复表空间的数据字典元数据
8.关闭辅助实例
9.在目标数据库中执行switch命令,因为目标数据库的控制文件现在指示的是在辅助实例中被恢复的恢复集中的数据文件
10.将辅助数据库实的数据字典元数据导入到目标数据库中让恢复的对象可以被访问。
11.删除所有辅助集数据文件

执行完以上步骤,TSPITR处理就已经完成了。对于目标数据库恢复集中的数据文件已经被返回到指定的恢复目标时间点。

三.TSPITR的执行方式
选择好要恢复的表空间和恢复目标时间后,就可以执行RMAN的TSPITR。在执行TSPITR时可以有以下不同的选择:
1.完全自动执行TSPITR–在指定辅助目录后就可以让RMAN来管理TSPITR的所有方面。这是执行TSPITR最简单的方式,除非你需要在执行TSPITR后更好的控制恢复集文件的目录或者在执行TSPITR时控制辅助集文件或者控制通道配置或者控制辅助实例的一些其它方面,否则建议使用这种方式来执行TSPITR。
2.使用自定义自动辅助实例执行TSPITR–在完全自动TSPITR的基础上,自定义一个或多个方面的RMAN行为,比如辅助集目录或者恢复集文件,或者指定初始化参数或者辅助实例的通道配置等。
3.使用自己的辅助实例执行TSPITR–在这种情况下要手动设置,启动,停止和清除辅助实例,也可以使用自动辅助实例自定义TSPITR中的一些方法来管理TSPITR。

完全自动执行TSPITR
当完全自动执行TSPITR时,让RMAN来管理整个过程,并且有两个条件:
1.必须给RMAN指定辅助目录让辅助实例的辅助集数据文件和其它文件使用。
2.必须在目标实例上配置任何需要的通道(当目标实例执行TSPITR时,辅助实例使用相同的通道配置)。
对于TSPITR的基础配置在目标数据库上进行。当执行TSPITR时,恢复集数据文件会被写到目标数据库的当前目录。当从备份中还原文件时在目标数据库上有效的相同配置通道将被辅助实例所用。辅助集数据文件和其它辅助实例文件,会被存储在辅助目录中。
自动TSPITR的辅助目录
oracle建议在使用辅助实例时使用辅助目录。即使你使用其它的方法来重命名一些或者所有的辅助集数据文件,通过设置auxliary destination参数来为没有指定名称的辅助集数据文件提供一个默认的目录。为了指定辅助目录,在磁盘上找到有足够空间的目录来处理辅助集数据文件。在recover tablespace命令中使用auxliary destination参数来指定辅助目录。
这里我使用oracle 10g进行完全自动执行TSPITR的实验,下面来准备实验环境:

SQL> select * from v$version;

BANNER
----------------------------------------------------------------
Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - Prod
PL/SQL Release 10.2.0.5.0 - Production
CORE    10.2.0.5.0      Production
TNS for Linux: Version 10.2.0.5.0 - Production
NLSRTL Version 10.2.0.5.0 - Production

SQL> select log_mode from v$database;

LOG_MODE
------------
ARCHIVELOG

创建实验表空间tspitr,用户tspitr,实验表tspitr:

SQL> create tablespace   tspitr datafile '/u01/app/oracle/oradata/test/tspitr01.dbf' size 100M autoextend off extent management local segment space management auto;

Tablespace created.

SQL> create user tspitr identified by "tspitr" default tablespace tspitr temporary tablespace temp;

User created.

SQL> grant connect,resource to tspitr;

Grant succeeded.

这里为了实例的方便使用给tspitr用户授予了DBA权限

SQL> grant dba to tspitr;

Grant succeeded.

SQL> conn tspitr/tspitr
Connected.
SQL> create table tspitr as select * from dba_objects;

Table created.
SQL> select count(*) from tspitr;

  COUNT(*)
----------
     50678

SQL> select sequence#, status from v$log;

 SEQUENCE# STATUS
---------- ----------------
        28 INACTIVE
        29 CURRENT
        27 INACTIVE

在创建完实验表tspitr后,记录一下当前的logseq号为29。并对数据库进行一次全备份。

[root@oracle11g ~]# su - oracle
[oracle@oracle11g ~]$ export NLS_DATE_FORMAT='YYYY-MM-DD HH24:MI:SS'
[oracle@oracle11g ~]$ rman target sys/zzh_2046@test catalog rman/rman@jy

Recovery Manager: Release 10.2.0.5.0 - Production on Mon Mar 16 10:34:12 2015

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

connected to target database: TEST (DBID=2168949517)
connected to recovery catalog database

RMAN> backup as backupset database plus archivelog delete all input;


Starting backup at 16-MAR-15
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting archive log backupset
channel ORA_DISK_1: specifying archive log(s) in backup set
input archive log thread=1 sequence=13 recid=20 stamp=872692763
input archive log thread=1 sequence=14 recid=21 stamp=873390068
input archive log thread=1 sequence=15 recid=22 stamp=873477705
input archive log thread=1 sequence=16 recid=23 stamp=873557208
input archive log thread=1 sequence=17 recid=24 stamp=873628193
input archive log thread=1 sequence=18 recid=25 stamp=873881475
input archive log thread=1 sequence=19 recid=26 stamp=873882506
input archive log thread=1 sequence=20 recid=27 stamp=873886639
input archive log thread=1 sequence=21 recid=28 stamp=873886719
input archive log thread=1 sequence=22 recid=29 stamp=873969562
input archive log thread=1 sequence=23 recid=30 stamp=873969604
input archive log thread=1 sequence=24 recid=31 stamp=873974555
input archive log thread=1 sequence=25 recid=32 stamp=873974650
input archive log thread=1 sequence=26 recid=33 stamp=874234950
input archive log thread=1 sequence=27 recid=34 stamp=874315417
input archive log thread=1 sequence=28 recid=35 stamp=874486326
input archive log thread=1 sequence=29 recid=36 stamp=874492547
channel ORA_DISK_1: starting piece 1 at 16-MAR-15
channel ORA_DISK_1: finished piece 1 at 16-MAR-15
piece handle=/u02/ora_test874492549_351 tag=TAG20150316T103548 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:26
channel ORA_DISK_1: deleting archive log(s)
archive log filename=/u02/1_13_870806981.dbf recid=20 stamp=872692763
archive log filename=/u02/1_14_870806981.dbf recid=21 stamp=873390068
archive log filename=/u02/1_15_870806981.dbf recid=22 stamp=873477705
archive log filename=/u02/1_16_870806981.dbf recid=23 stamp=873557208
archive log filename=/u02/1_17_870806981.dbf recid=24 stamp=873628193
archive log filename=/u02/1_18_870806981.dbf recid=25 stamp=873881475
archive log filename=/u02/1_19_870806981.dbf recid=26 stamp=873882506
archive log filename=/u02/1_20_870806981.dbf recid=27 stamp=873886639
archive log filename=/u02/1_21_870806981.dbf recid=28 stamp=873886719
archive log filename=/u02/1_22_870806981.dbf recid=29 stamp=873969562
archive log filename=/u02/1_23_870806981.dbf recid=30 stamp=873969604
archive log filename=/u02/1_24_870806981.dbf recid=31 stamp=873974555
archive log filename=/u02/1_25_870806981.dbf recid=32 stamp=873974650
archive log filename=/u02/1_26_870806981.dbf recid=33 stamp=874234950
archive log filename=/u02/1_27_870806981.dbf recid=34 stamp=874315417
archive log filename=/u02/1_28_870806981.dbf recid=35 stamp=874486326
archive log filename=/u02/1_29_870806981.dbf recid=36 stamp=874492547
Finished backup at 16-MAR-15

Starting backup at 16-MAR-15
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
input datafile fno=00001 name=/u01/app/oracle/oradata/test/system01.dbf
input datafile fno=00003 name=/u01/app/oracle/oradata/test/sysaux01.dbf
input datafile fno=00005 name=/u01/app/oracle/oradata/test/example01.dbf
input datafile fno=00006 name=/u01/app/oracle/oradata/test/tspitr01.dbf
input datafile fno=00002 name=/u01/app/oracle/oradata/test/undotbs01.dbf
input datafile fno=00004 name=/u01/app/oracle/oradata/test/users01.dbf
channel ORA_DISK_1: starting piece 1 at 16-MAR-15
channel ORA_DISK_1: finished piece 1 at 16-MAR-15
piece handle=/u02/ora_test874492578_361 tag=TAG20150316T103617 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:01:15
Finished backup at 16-MAR-15

Starting backup at 16-MAR-15
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting archive log backupset
channel ORA_DISK_1: specifying archive log(s) in backup set
input archive log thread=1 sequence=30 recid=37 stamp=874492654
channel ORA_DISK_1: starting piece 1 at 16-MAR-15
channel ORA_DISK_1: finished piece 1 at 16-MAR-15
piece handle=/u02/ora_test874492656_371 tag=TAG20150316T103735 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:02
channel ORA_DISK_1: deleting archive log(s)
archive log filename=/u02/1_30_870806981.dbf recid=37 stamp=874492654
Finished backup at 16-MAR-15

Starting Control File and SPFILE Autobackup at 16-MAR-15
piece handle=/u01/app/oracle/flash_recovery_area/TEST/autobackup/2015_03_16/o1_mf_s_874492659_bjdjhno1_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 16-MAR-15

RMAN> list backup ;


List of Backup Sets
===================

BS Key  Size       Device Type Elapsed Time Completion Time
------- ---------- ----------- ------------ -------------------
1197    106.98M    DISK        00:00:23     2015-03-16 10:36:12
        BP Key: 1198   Status: AVAILABLE  Compressed: NO  Tag: TAG20150316T103548
        Piece Name: /u02/ora_test874492549_351

  List of Archived Logs in backup set 1197
  Thrd Seq     Low SCN    Low Time            Next SCN   Next Time
  ---- ------- ---------- ------------------- ---------- ---------
  1    13      479270     2015-02-13 11:15:05 507890     2015-02-26 14:39:21
  1    14      507890     2015-02-26 14:39:21 537468     2015-03-03 16:21:06
  1    15      537468     2015-03-03 16:21:06 565660     2015-03-04 16:41:41
  1    16      565660     2015-03-04 16:41:41 597853     2015-03-05 14:46:22
  1    17      597853     2015-03-05 14:46:22 627695     2015-03-06 10:29:51
  1    18      627695     2015-03-06 10:29:51 662451     2015-03-09 08:51:08
  1    19      662451     2015-03-09 08:51:08 663522     2015-03-09 09:08:25
  1    20      663522     2015-03-09 09:08:25 666107     2015-03-09 10:17:18
  1    21      666107     2015-03-09 10:17:18 666153     2015-03-09 10:18:39
  1    22      666153     2015-03-09 10:18:39 692585     2015-03-10 09:19:20
  1    23      692585     2015-03-10 09:19:20 692853     2015-03-10 09:20:04
  1    24      692853     2015-03-10 09:20:04 695060     2015-03-10 10:42:34
  1    25      695060     2015-03-10 10:42:34 695112     2015-03-10 10:44:09
  1    26      695112     2015-03-10 10:44:09 726710     2015-03-13 11:02:26
  1    27      726710     2015-03-13 11:02:26 759353     2015-03-14 09:23:34
  1    28      759353     2015-03-14 09:23:34 786212     2015-03-16 08:52:00
  1    29      786212     2015-03-16 08:52:00 789814     2015-03-16 10:35:43

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ -------------------
1226    Full    612.91M    DISK        00:01:14     2015-03-16 10:37:32
        BP Key: 1244   Status: AVAILABLE  Compressed: NO  Tag: TAG20150316T103617
        Piece Name: /u02/ora_test874492578_361
  List of Datafiles in backup set 1226
  File LV Type Ckp SCN    Ckp Time            Name
  ---- -- ---- ---------- ------------------- ----
  1       Full 789843     2015-03-16 10:36:18 /u01/app/oracle/oradata/test/system01.dbf
  2       Full 789843     2015-03-16 10:36:18 /u01/app/oracle/oradata/test/undotbs01.dbf
  3       Full 789843     2015-03-16 10:36:18 /u01/app/oracle/oradata/test/sysaux01.dbf
  4       Full 789843     2015-03-16 10:36:18 /u01/app/oracle/oradata/test/users01.dbf
  5       Full 789843     2015-03-16 10:36:18 /u01/app/oracle/oradata/test/example01.dbf
  6       Full 789843     2015-03-16 10:36:18 /u01/app/oracle/oradata/test/tspitr01.dbf

BS Key  Size       Device Type Elapsed Time Completion Time
------- ---------- ----------- ------------ -------------------
1268    2.50K      DISK        00:00:01     2015-03-16 10:37:37
        BP Key: 1275   Status: AVAILABLE  Compressed: NO  Tag: TAG20150316T103735
        Piece Name: /u02/ora_test874492656_371

  List of Archived Logs in backup set 1268
  Thrd Seq     Low SCN    Low Time            Next SCN   Next Time
  ---- ------- ---------- ------------------- ---------- ---------
  1    30      789814     2015-03-16 10:35:43 789871     2015-03-16 10:37:33

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ -------------------
1286    Full    6.80M      DISK        00:00:01     2015-03-16 10:37:40
        BP Key: 1288   Status: AVAILABLE  Compressed: NO  Tag: TAG20150316T103739
        Piece Name: /u01/app/oracle/flash_recovery_area/TEST/autobackup/2015_03_16/o1_mf_s_874492659_bjdjhno1_.bkp
  Control File Included: Ckp SCN: 789893       Ckp time: 2015-03-16 10:37:39
  SPFILE Included: Modification time: 2015-03-16 08:52:02


模拟误操作:
记录当前时间点的logseq号为31

SQL> select sequence#, status from v$log;

 SEQUENCE# STATUS
---------- ----------------
        31 CURRENT
        29 INACTIVE
        30 INACTIVE

进行日志切换,记录truncate操作之前的logseq号为32,并执行truncate操作

SQL> alter system switch logfile;

System altered.

SQL> select sequence#, status from v$log;

 SEQUENCE# STATUS
---------- ----------------
        31 ACTIVE
        32 CURRENT
        30 INACTIVE

SQL> truncate table tspitr;

Table truncated.

SQL> alter system switch logfile;

System altered.

SQL> select sequence#, status from v$log;

 SEQUENCE# STATUS
---------- ----------------
        31 ACTIVE
        32 ACTIVE
        33 CURRENT

在执行truncate table tspitr操作之后,进行日志切换,并记录truncate操作之后的当前logseq号为33。我们这里的恢复目标是将表空间tspitr恢复到logseq=32的时间点。为了执行自动RMAN TSPITR,启动RMAN客户端,连接到目标数据库和恢复目录(如果有的话)。注意,为了使用自动TSPITR在启动RMAN客户端时不要连接到辅助实例。如果在执行recover tablespace命令时,RMAN连接到一个辅助实例,RMAN会假设你将试管理自己单独的辅助实例。

创建辅助目录:

[oracle@oracle11g oradata]$ mkdir auxiliary
[oracle@oracle11g oradata]$ ls -lrt
total 8
drwxr-x--- 2 oracle oinstall 4096 Mar 16 10:22 test
drwxr-xr-x 2 oracle oinstall 4096 Mar 16 10:55 auxiliary

如果已经配置了通道,RMAN可以在主实例上从备份中执行还原,那么通过执行recover tablespace …until …命令就能执行TSPITR了。这里使用目标数据库中的缺省磁盘通道。

执行下面的命令将表空间tspitr恢复到logseq=32的时间点:

RMAN> recover tablespace tspitr until logseq 32 auxiliary destination '/u01/app/oracle/oradata/auxiliary';

Starting recover at 2015-03-16 11:27:37
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=143 devtype=DISK

Creating automatic instance, with SID='hswB'

initialization parameters used for automatic instance:
db_name=TEST
compatible=10.2.0.5.0
db_block_size=8192
db_files=200
db_unique_name=tspitr_TEST_hswB
sga_target=180M
processes=50
#No auxiliary parameter file used
db_create_file_dest=/u01/app/oracle/oradata/auxiliary
control_files=/u01/app/oracle/oradata/auxiliary/cntrl_tspitr_TEST_hswB.f


starting up automatic instance TEST

Oracle instance started

Total System Global Area     188743680 bytes

Fixed Size                     1272720 bytes
Variable Size                 62915696 bytes
Database Buffers             121634816 bytes
Redo Buffers                   2920448 bytes
Automatic instance created

contents of Memory Script:
{
# set the until clause
set until  logseq 32 thread 1;
# restore the controlfile
restore clone controlfile;
# mount the controlfile
sql clone 'alter database mount clone database';
# archive current online log for tspitr to a resent until time
sql 'alter system archive log current';
# avoid unnecessary autobackups for structural changes during TSPITR
sql 'begin dbms_backup_restore.AutoBackupFlag(FALSE); end;';
# resync catalog after controlfile restore
resync catalog;
}
executing Memory Script

executing command: SET until clause

Starting restore at 2015-03-16 11:27:38
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: sid=47 devtype=DISK

channel ORA_AUX_DISK_1: starting datafile backupset restore
channel ORA_AUX_DISK_1: restoring control file
channel ORA_AUX_DISK_1: reading from backup piece /u01/app/oracle/flash_recovery_area/TEST/autobackup/2015_03_16/o1_mf_s_874492659_bjdjhno1_.bkp
channel ORA_AUX_DISK_1: restored backup piece 1
piece handle=/u01/app/oracle/flash_recovery_area/TEST/autobackup/2015_03_16/o1_mf_s_874492659_bjdjhno1_.bkp tag=TAG20150316T103739
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:02
output filename=/u01/app/oracle/oradata/auxiliary/cntrl_tspitr_TEST_hswB.f
Finished restore at 2015-03-16 11:27:41

sql statement: alter database mount clone database

sql statement: alter system archive log current

sql statement: begin dbms_backup_restore.AutoBackupFlag(FALSE); end;

starting full resync of recovery catalog
full resync complete

contents of Memory Script:
{
# generated tablespace point-in-time recovery script
# set the until clause
set until  logseq 32 thread 1;
plsql < <<-- tspitr_2
declare
  sqlstatement       varchar2(512);
  offline_not_needed exception;
  pragma exception_init(offline_not_needed, -01539);
begin
  sqlstatement := 'alter tablespace '||  'TSPITR' ||' offline for recover';
  krmicd.writeMsg(6162, sqlstatement);
  krmicd.execSql(sqlstatement);
exception
  when offline_not_needed then
    null;
end; >>>;
# set an omf destination filename for restore
set newname for clone datafile  1 to new;
# set an omf destination filename for restore
set newname for clone datafile  2 to new;
# set an omf destination tempfile
set newname for clone tempfile  1 to new;
# set a destination filename for restore
set newname for datafile  6 to
 "/u01/app/oracle/oradata/test/tspitr01.dbf";
# rename all tempfiles
switch clone tempfile all;
# restore the tablespaces in the recovery set plus the auxilliary tablespaces
restore clone datafile  1, 2, 6;
switch clone datafile all;
#online the datafiles restored or flipped
sql clone "alter database datafile  1 online";
#online the datafiles restored or flipped
sql clone "alter database datafile  2 online";
#online the datafiles restored or flipped
sql clone "alter database datafile  6 online";
# make the controlfile point at the restored datafiles, then recover them
recover clone database tablespace  "TSPITR", "SYSTEM", "UNDOTBS1" delete archivelog;
alter clone database open resetlogs;
# PLUG HERE the creation of a temporary tablespace if export fails due to lack
# of temporary space.
# For example in Unix these two lines would do that:
#sql clone "create tablespace aux_tspitr_tmp
#           datafile ''/tmp/aux_tspitr_tmp.dbf'' size 500K";
}
executing Memory Script

executing command: SET until clause

sql statement: alter tablespace TSPITR offline for recover

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

renamed temporary file 1 to /u01/app/oracle/oradata/auxiliary/TSPITR_TEST_HSWB/datafile/o1_mf_temp_%u_.tmp in control file

Starting restore at 2015-03-16 11:27:54
using channel ORA_AUX_DISK_1

channel ORA_AUX_DISK_1: starting datafile backupset restore
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
restoring datafile 00001 to /u01/app/oracle/oradata/auxiliary/TSPITR_TEST_HSWB/datafile/o1_mf_system_%u_.dbf
restoring datafile 00002 to /u01/app/oracle/oradata/auxiliary/TSPITR_TEST_HSWB/datafile/o1_mf_undotbs1_%u_.dbf
restoring datafile 00006 to /u01/app/oracle/oradata/test/tspitr01.dbf
channel ORA_AUX_DISK_1: reading from backup piece /u02/ora_test874492578_361
channel ORA_AUX_DISK_1: restored backup piece 1
piece handle=/u02/ora_test874492578_361 tag=TAG20150316T103617
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:01:05
Finished restore at 2015-03-16 11:29:00

datafile 1 switched to datafile copy
input datafile copy recid=19 stamp=874495741 filename=/u01/app/oracle/oradata/auxiliary/TSPITR_TEST_HSWB/datafile/o1_mf_system_bjdmfw0k_.dbf
datafile 2 switched to datafile copy
input datafile copy recid=20 stamp=874495741 filename=/u01/app/oracle/oradata/auxiliary/TSPITR_TEST_HSWB/datafile/o1_mf_undotbs1_bjdmfw23_.dbf

sql statement: alter database datafile  1 online

sql statement: alter database datafile  2 online

sql statement: alter database datafile  6 online

Starting recover at 2015-03-16 11:29:01
using channel ORA_AUX_DISK_1

starting media recovery

archive log thread 1 sequence 31 is already on disk as file /u02/1_31_870806981.dbf
channel ORA_AUX_DISK_1: starting archive log restore to default destination
channel ORA_AUX_DISK_1: restoring archive log
archive log thread=1 sequence=30
channel ORA_AUX_DISK_1: reading from backup piece /u02/ora_test874492656_371
channel ORA_AUX_DISK_1: restored backup piece 1
piece handle=/u02/ora_test874492656_371 tag=TAG20150316T103735
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:02
archive log filename=/u01/app/oracle/10.2.0/db/dbs/arch1_30_870806981.dbf thread=1 sequence=30
channel clone_default: deleting archive log(s)
archive log filename=/u01/app/oracle/10.2.0/db/dbs/arch1_30_870806981.dbf recid=38 stamp=874495743
archive log filename=/u02/1_31_870806981.dbf thread=1 sequence=31
media recovery complete, elapsed time: 00:00:01
Finished recover at 2015-03-16 11:29:05

database opened

contents of Memory Script:
{
# export the tablespaces in the recovery set
host 'exp userid =\"/@\(DESCRIPTION=\(ADDRESS=\(PROTOCOL=beq\)\(PROGRAM=/u01/app/oracle/10.2.0/db/bin/oracle\)\(ARGV0=oraclehswB\)\(ARGS=^'\(DESCRIPTION=\(LOCAL=YES\)\(ADDRESS=\(PROTOCOL=beq\)\)\)^'\)\(ENVS=^'ORACLE_SID=hswB^'\)\)\(CONNECT_DATA=\(SID=hswB\)\)\) as sysdba\" point_in_time_recover=y tablespaces=
 TSPITR file=
tspitr_a.dmp';
# shutdown clone before import
shutdown clone immediate
# import the tablespaces in the recovery set
host 'imp userid =\"sys/zzh_2046@test as sysdba\" point_in_time_recover=y file=
tspitr_a.dmp';
# online/offline the tablespace imported
sql "alter tablespace TSPITR online";
sql "alter tablespace  TSPITR offline";
# enable autobackups in case user does open resetlogs from RMAN after TSPITR
sql 'begin dbms_backup_restore.AutoBackupFlag(TRUE); end;';
# resync catalog after tspitr finished
resync catalog;
}
executing Memory Script


Export: Release 10.2.0.5.0 - Production on Mon Mar 16 11:29:30 2015

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


Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Export done in ZHS16GBK character set and AL16UTF16 NCHAR character set
Note: table data (rows) will not be exported

About to export Tablespace Point-in-time Recovery objects...
For tablespace TSPITR ...
. exporting cluster definitions
. exporting table definitions
. . exporting table                         TSPITR
. exporting referential integrity constraints
. exporting triggers
. end point-in-time recovery
Export terminated successfully without warnings.
host command complete

database closed
database dismounted
Oracle instance shut down


Import: Release 10.2.0.5.0 - Production on Mon Mar 16 11:29:46 2015

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


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

Export file created by EXPORT:V10.02.01 via conventional path
About to import Tablespace Point-in-time Recovery objects...
import done in ZHS16GBK character set and AL16UTF16 NCHAR character set
. importing SYS's objects into SYS
. importing TSPITR's objects into TSPITR
. . importing table                       "TSPITR"
. importing SYS's objects into SYS
Import terminated successfully without warnings.
host command complete

sql statement: alter tablespace TSPITR online

sql statement: alter tablespace  TSPITR offline

sql statement: begin dbms_backup_restore.AutoBackupFlag(TRUE); end;

starting full resync of recovery catalog
full resync complete

Removing automatic instance
Automatic instance removed
auxiliary instance file /u01/app/oracle/oradata/auxiliary/cntrl_tspitr_TEST_hswB.f deleted
auxiliary instance file /u01/app/oracle/oradata/auxiliary/TSPITR_TEST_HSWB/datafile/o1_mf_system_bjdmfw0k_.dbf deleted
auxiliary instance file /u01/app/oracle/oradata/auxiliary/TSPITR_TEST_HSWB/datafile/o1_mf_undotbs1_bjdmfw23_.dbf deleted
auxiliary instance file /u01/app/oracle/oradata/auxiliary/TSPITR_TEST_HSWB/datafile/o1_mf_temp_bjdmjfov_.tmp deleted
auxiliary instance file /u01/app/oracle/oradata/auxiliary/TSPITR_TEST_HSWB/onlinelog/o1_mf_1_bjdmj1o6_.log deleted
auxiliary instance file /u01/app/oracle/oradata/auxiliary/TSPITR_TEST_HSWB/onlinelog/o1_mf_2_bjdmj44r_.log deleted
auxiliary instance file /u01/app/oracle/oradata/auxiliary/TSPITR_TEST_HSWB/onlinelog/o1_mf_3_bjdmj6f1_.log deleted
Finished recover at 2015-03-16 11:29:59

SQL> select tablespace_name,status from dba_tablespaces;

TABLESPACE_NAME                STATUS
------------------------------ ---------
SYSTEM                         ONLINE
UNDOTBS1                       ONLINE
SYSAUX                         ONLINE
TEMP                           ONLINE
USERS                          ONLINE
EXAMPLE                        ONLINE
TSPITR                         OFFLINE

7 rows selected.

TSPITR成功执行完成,RMAN会将表空间脱机,从备份中还原并在辅助实例中将表空间恢复到指定的目标时间点。在整个过程执行完成后,表空间仍然是脱机状态。所有的辅助集数据文件和其它的辅助实例文件会从辅助目录中删除。

TSPITR执行成功后需要执行的操作:
1.必须要备份恢复的表空间然后将表空间置于联机状态。
2.在TSPITR执行成功后立即备份恢复成功的表空间是非常重要的。在对表空间执行TSPITR后,在TSPITR恢复目标时间之前的表空间备份将不能再使用。如果不对恢复的表空间进行备份就开始使用,你将在没有这些表空间备份的情况下运行数据库。对于这个例子,执行以下命令来备份tspitr表空间或者对整个数据库进行备份:

RMAN> backup tablespace tspitr;

Starting backup at 2015-03-16 11:40:53
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
input datafile fno=00006 name=/u01/app/oracle/oradata/test/tspitr01.dbf
channel ORA_DISK_1: starting piece 1 at 2015-03-16 11:40:54
channel ORA_DISK_1: finished piece 1 at 2015-03-16 11:40:55
piece handle=/u02/ora_test874496454_391 tag=TAG20150316T114053 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 2015-03-16 11:40:55

Starting Control File and SPFILE Autobackup at 2015-03-16 11:40:55
piece handle=/u01/app/oracle/flash_recovery_area/TEST/autobackup/2015_03_16/o1_mf_s_874496456_bjdn69mh_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 2015-03-16 11:40:59

然后可以安全的将表空间置于联机状态:


RMAN> sql 'alter tablespace tspitr online';

sql statement: alter tablespace tspitr online
starting full resync of recovery catalog
full resync complete

现在恢复的表空间就可以供用户使用了。

SQL> select tablespace_name,status from dba_tablespaces;

TABLESPACE_NAME                STATUS
------------------------------ ---------
SYSTEM                         ONLINE
UNDOTBS1                       ONLINE
SYSAUX                         ONLINE
TEMP                           ONLINE
USERS                          ONLINE
EXAMPLE                        ONLINE
TSPITR                         ONLINE

7 rows selected.

SQL> show user
USER is "TSPITR"
SQL> select count(*) from tspitr;

  COUNT(*)
----------
     50678

Redhat Linux两台主机之间设置NFS挂载的步骤

为了测试Oracle RMAN使用PFILE参数文件在异机上执行duplicate命令,需要将辅助实例pfile参数文件通过NFS来让执行RMAN命令的主机应访问,所以需要配置NFS,这里只介绍了最基本的配置方法。
一、安装nfs
一般redhat是默认安装了nfs服务的,如果非默认安装且取消勾选nfs的话,需要挂载iso或下载安装包手动安装来进行安装,这里不再赘述。

二、在被共享目录所在主机配置/etc/exports
nfs允许挂载的目录及权限需在文件/etc/exports中进行定义。例如,我们要将参数文件所在目录/u01/app/oracle/product/10.2.0/db/dbs共享出来,那么我们需要编辑/etc/exports文件,追加一行/u01/app/oracle/product/10.2.0/db/dbs *(rw,sync):

[root@jingyong1 /]# vi /etc/exports


/u01/app/oracle/product/10.2.0/db/dbs *(rw,sync)

其中
/u01/app/oracle/product/10.2.0/db/dbs是要共享的目录;
* 代表允许所有的网络段访问(仅测试中使用,实际使用应该做严格的IP限制);
rw开启共享目录的可读写权限;
sync是资料同步写入内存和硬盘;
其他更多参数说明:
ro 只读访问
rw 读写访问sync 所有数据在请求时写入共享
async nfs在写入数据前可以响应请求
secure nfs通过1024以下的安全TCP/IP端口发送
insecure nfs通过1024以上的端口发送
wdelay 如果多个用户要写入nfs目录,则归组写入(默认)
no_wdelay 如果多个用户要写入nfs目录,则立即写入,当使用async时,无需此设置。
hide 在nfs共享目录中不共享其子目录
no_hide 共享nfs目录的子目录
subtree_check 如果共享/usr/bin之类的子目录时,强制nfs检查父目录的权限(默认)
no_subtree_check 和上面相对,不检查父目录权限
all_squash 共享文件的UID和GID映射匿名用户anonymous,适合公用目录。
no_all_squash 保留共享文件的UID和GID(默认)
root_squash root用户的所有请求映射成如anonymous用户一样的权限(默认)
no_root_squas root用户具有根目录的完全管理访问权限
anonuid=xxx 指定nfs服务器/etc/passwd文件中匿名用户的UID
anongid=xxx 指定nfs服务器/etc/passwd文件中匿名用户的GID

三、启动nfs服务
在启动nfs之前需要先启动portmap服务,否则如下报错:

[root@jingyong1 /]# service nfs start
Starting NFS services:                                     [  OK  ]
Starting NFS quotas: Cannot register service: RPC: Unable to receive; errno = Connection refused
rpc.rquotad: unable to register (RQUOTAPROG, RQUOTAVERS, udp).
                                                           [FAILED]
Starting NFS daemon:

正确方法先启动portmap再启动nfs,如下:
service portmap start
service nfs start
或
/etc/init.d/portmap start
/etc/init.d/nfs start


[root@jingyong1 /]# service portmap start
Starting portmap: [  OK  ]

[root@jingyong1 /]# service nfs start
Starting NFS services:  [  OK  ]
Starting NFS quotas: [  OK  ]
Starting NFS daemon: [  OK  ]
Starting NFS mountd: [  OK  ]

四、在客户端主机上挂载共享目录
1、挂载之前同样需要先启动portmap服务

[root@oracle11g /]# service portmap start
Starting portmap: [  OK  ]

2、在客户端使用showmount -e IP 查看nfs主机共享情况:

[root@oracle11g /]# showmount -e 192.168.56.11
Export list for 192.168.56.11:
/u01/app/oracle/product/10.2.0/db/dbs *

3、在客户端建立jingyong1文件夹,并使用mount挂载命令:

[root@oracle11g net]# mkdir /jingyong1
[root@oracle11g /]# chown -R oracle:oinstall jingyong1
[root@oracle11g /]# chmod -R 777 jingyong1

[root@oracle11g /]# mount -t nfs 192.168.56.11:/u01/app/oracle/product/10.2.0/db/dbs /jingyong1

4、若无报错,则可使用df -h 查看到挂载情况:

[root@oracle11g /]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda1              23G   12G  9.6G  55% /
/dev/sdb1             9.9G  5.6G  3.9G  60% /u02
tmpfs                 252M     0  252M   0% /dev/shm
192.168.56.11:/u01/app/oracle/product/10.2.0/db/dbs
                       17G   14G  2.3G  86% /jingyong1

五、在客户端卸载已挂载的目录

[root@oracle11g /]# umount /jingyong1

rman duplicate target database RMAN-03002 RMAN-03015 RMAN-06136

通过RMAN的duplicate命令将目标数据库在另一主机上复制一个副本数据库时报以下错误信息:

RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of Duplicate Db command at 03/24/2015 18:28:32
RMAN-03015: error occurred in stored script Memory Script
RMAN-06136: ORACLE error from auxiliary database: ORA-01013: user requested

目标数据库与复制的副本数据库在不同主机上,但有相同的目录结构,复制命令如下:

[oracle@oracle11g admin]$ rman target sys/zzh_2046@test auxiliary sys/oracle@dup catalog rman/rman@jy

Recovery Manager: Release 10.2.0.5.0 - Production on Tue Mar 24 17:26:51 2015

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

connected to target database: TEST (DBID=2168949517)
connected to recovery catalog database
connected to auxiliary database: DUP (not mounted)

RMAN> duplicate target database to dup nofilenamecheck;

Starting Duplicate Db at 2015-03-24 17:27:06
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: sid=35 devtype=DISK

contents of Memory Script:
{
   set until scn  1009334;
   set newname for datafile  1 to
 "/u01/app/oracle/oradata/test/system01.dbf";
   set newname for datafile  2 to
 "/u01/app/oracle/oradata/test/undotbs01.dbf";
   set newname for datafile  3 to
 "/u01/app/oracle/oradata/test/sysaux01.dbf";
   set newname for datafile  4 to
 "/u01/app/oracle/oradata/test/users01.dbf";
   set newname for datafile  5 to
 "/u01/app/oracle/oradata/test/example01.dbf";
   set newname for datafile  6 to
 "/u01/app/oracle/oradata/test/tspitr01.dbf";
   restore
   check readonly
   clone database
   ;
}
executing Memory Script

executing command: SET until clause

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

Starting restore at 2015-03-24 17:27:07
using channel ORA_AUX_DISK_1

channel ORA_AUX_DISK_1: starting datafile backupset restore
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
restoring datafile 00001 to /u01/app/oracle/oradata/test/system01.dbf
restoring datafile 00002 to /u01/app/oracle/oradata/test/undotbs01.dbf
restoring datafile 00003 to /u01/app/oracle/oradata/test/sysaux01.dbf
restoring datafile 00004 to /u01/app/oracle/oradata/test/users01.dbf
restoring datafile 00005 to /u01/app/oracle/oradata/test/example01.dbf
restoring datafile 00006 to /u01/app/oracle/oradata/test/tspitr01.dbf
channel ORA_AUX_DISK_1: reading from backup piece /u02/ora_test875200761_721
channel ORA_AUX_DISK_1: restored backup piece 1
piece handle=/u02/ora_test875200761_721 tag=TAG20150324T151920
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:01:05
Finished restore at 2015-03-24 17:28:12
sql statement: CREATE CONTROLFILE REUSE SET DATABASE "DUP" RESETLOGS ARCHIVELOG
  MAXLOGFILES     16
  MAXLOGMEMBERS      3
  MAXDATAFILES      100
  MAXINSTANCES     8
  MAXLOGHISTORY      292
 LOGFILE
  GROUP  1 ( '/u01/app/oracle/oradata/test/redo01.log' ) SIZE 50 M  REUSE,
  GROUP  2 ( '/u01/app/oracle/oradata/test/redo02.log' ) SIZE 50 M  REUSE,
  GROUP  3 ( '/u01/app/oracle/oradata/test/redo03.log' ) SIZE 50 M  REUSE
 DATAFILE
  '/u01/app/oracle/oradata/test/system01.dbf'
 CHARACTER SET ZHS16GBK


contents of Memory Script:
{
   switch clone datafile all;
}
executing Memory Script

datafile 2 switched to datafile copy
input datafile copy recid=1 stamp=875208502 filename=/u01/app/oracle/oradata/test/undotbs01.dbf
datafile 3 switched to datafile copy
input datafile copy recid=2 stamp=875208502 filename=/u01/app/oracle/oradata/test/sysaux01.dbf
datafile 4 switched to datafile copy
input datafile copy recid=3 stamp=875208502 filename=/u01/app/oracle/oradata/test/users01.dbf
datafile 5 switched to datafile copy
input datafile copy recid=4 stamp=875208502 filename=/u01/app/oracle/oradata/test/example01.dbf
datafile 6 switched to datafile copy
input datafile copy recid=5 stamp=875208502 filename=/u01/app/oracle/oradata/test/tspitr01.dbf

contents of Memory Script:
{
   set until scn  1009334;
   recover
   clone database
    delete archivelog
   ;
}
executing Memory Script

executing command: SET until clause

Starting recover at 2015-03-24 17:28:14
using channel ORA_AUX_DISK_1

starting media recovery

channel ORA_AUX_DISK_1: starting archive log restore to default destination
channel ORA_AUX_DISK_1: restoring archive log
archive log thread=1 sequence=64
channel ORA_AUX_DISK_1: reading from backup piece /u02/ora_test875200848_731
channel ORA_AUX_DISK_1: restored backup piece 1
piece handle=/u02/ora_test875200848_731 tag=TAG20150324T152048
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
archive log filename=/u01/app/oracle/product/10.2.0/db/dbs/arch1_64_870806981.dbf thread=1 sequence=64
channel clone_default: deleting archive log(s)
archive log filename=/u01/app/oracle/product/10.2.0/db/dbs/arch1_64_870806981.dbf recid=1 stamp=875208502
media recovery complete, elapsed time: 00:00:01
Finished recover at 2015-03-24 17:28:17

contents of Memory Script:
{
   shutdown clone;
   startup clone nomount ;
}
executing Memory Script

RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of Duplicate Db command at 03/24/2015 18:28:32
RMAN-03015: error occurred in stored script Memory Script
RMAN-06136: ORACLE error from auxiliary database: ORA-01013: user requested cancel of current operation

这里出错是因为启动辅助实例后没有断开连接

[oracle@jingyong1 dbs]$ export ORACLE_SID=dup
[oracle@jingyong1 dbs]$ sqlplus / as sysdba

SQL*Plus: Release 10.2.0.5.0 - Production on Tue Mar 24 16:19:29 2015

Copyright (c) 1982, 2010, Oracle.  All Rights Reserved.

Connected to an idle instance.

SQL> startup nomount
ORACLE instance started.

Total System Global Area  167772160 bytes
Fixed Size                  1272624 bytes
Variable Size              58721488 bytes
Database Buffers          104857600 bytes
Redo Buffers                2920448 bytes

断开连接

SQL> exit
Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

重新执行复制命令:

[oracle@oracle11g admin]$ rman target sys/zzh_2046@test auxiliary sys/oracle@dup catalog rman/rman@jy

Recovery Manager: Release 10.2.0.5.0 - Production on Tue Mar 24 18:58:33 2015

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

connected to target database: TEST (DBID=2168949517)
connected to recovery catalog database
connected to auxiliary database: DUP (not mounted)

RMAN> duplicate target database to dup nofilenamecheck;

Starting Duplicate Db at 2015-03-24 18:58:47
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: sid=36 devtype=DISK

contents of Memory Script:
{
   set until scn  1009334;
   set newname for datafile  1 to
 "/u01/app/oracle/oradata/test/system01.dbf";
   set newname for datafile  2 to
 "/u01/app/oracle/oradata/test/undotbs01.dbf";
   set newname for datafile  3 to
 "/u01/app/oracle/oradata/test/sysaux01.dbf";
   set newname for datafile  4 to
 "/u01/app/oracle/oradata/test/users01.dbf";
   set newname for datafile  5 to
 "/u01/app/oracle/oradata/test/example01.dbf";
   set newname for datafile  6 to
 "/u01/app/oracle/oradata/test/tspitr01.dbf";
   restore
   check readonly
   clone database
   ;
}
executing Memory Script

executing command: SET until clause

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

Starting restore at 2015-03-24 18:58:47
using channel ORA_AUX_DISK_1

channel ORA_AUX_DISK_1: starting datafile backupset restore
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
restoring datafile 00001 to /u01/app/oracle/oradata/test/system01.dbf
restoring datafile 00002 to /u01/app/oracle/oradata/test/undotbs01.dbf
restoring datafile 00003 to /u01/app/oracle/oradata/test/sysaux01.dbf
restoring datafile 00004 to /u01/app/oracle/oradata/test/users01.dbf
restoring datafile 00005 to /u01/app/oracle/oradata/test/example01.dbf
restoring datafile 00006 to /u01/app/oracle/oradata/test/tspitr01.dbf
channel ORA_AUX_DISK_1: reading from backup piece /u02/ora_test875200761_721
channel ORA_AUX_DISK_1: restored backup piece 1
piece handle=/u02/ora_test875200761_721 tag=TAG20150324T151920
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:01:05
Finished restore at 2015-03-24 18:59:53
sql statement: CREATE CONTROLFILE REUSE SET DATABASE "DUP" RESETLOGS ARCHIVELOG
  MAXLOGFILES     16
  MAXLOGMEMBERS      3
  MAXDATAFILES      100
  MAXINSTANCES     8
  MAXLOGHISTORY      292
 LOGFILE
  GROUP  1 ( '/u01/app/oracle/oradata/test/redo01.log' ) SIZE 50 M  REUSE,
  GROUP  2 ( '/u01/app/oracle/oradata/test/redo02.log' ) SIZE 50 M  REUSE,
  GROUP  3 ( '/u01/app/oracle/oradata/test/redo03.log' ) SIZE 50 M  REUSE
 DATAFILE
  '/u01/app/oracle/oradata/test/system01.dbf'
 CHARACTER SET ZHS16GBK


contents of Memory Script:
{
   switch clone datafile all;
}
executing Memory Script

datafile 2 switched to datafile copy
input datafile copy recid=1 stamp=875214004 filename=/u01/app/oracle/oradata/test/undotbs01.dbf
datafile 3 switched to datafile copy
input datafile copy recid=2 stamp=875214004 filename=/u01/app/oracle/oradata/test/sysaux01.dbf
datafile 4 switched to datafile copy
input datafile copy recid=3 stamp=875214004 filename=/u01/app/oracle/oradata/test/users01.dbf
datafile 5 switched to datafile copy
input datafile copy recid=4 stamp=875214004 filename=/u01/app/oracle/oradata/test/example01.dbf
datafile 6 switched to datafile copy
input datafile copy recid=5 stamp=875214004 filename=/u01/app/oracle/oradata/test/tspitr01.dbf

contents of Memory Script:
{
   set until scn  1009334;
   recover
   clone database
    delete archivelog
   ;
}
executing Memory Script

executing command: SET until clause

Starting recover at 2015-03-24 18:59:56
using channel ORA_AUX_DISK_1

starting media recovery

channel ORA_AUX_DISK_1: starting archive log restore to default destination
channel ORA_AUX_DISK_1: restoring archive log
archive log thread=1 sequence=64
channel ORA_AUX_DISK_1: reading from backup piece /u02/ora_test875200848_731
channel ORA_AUX_DISK_1: restored backup piece 1
piece handle=/u02/ora_test875200848_731 tag=TAG20150324T152048
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
archive log filename=/u01/app/oracle/product/10.2.0/db/dbs/arch1_64_870806981.dbf thread=1 sequence=64
channel clone_default: deleting archive log(s)
archive log filename=/u01/app/oracle/product/10.2.0/db/dbs/arch1_64_870806981.dbf recid=1 stamp=875214007
media recovery complete, elapsed time: 00:00:01
Finished recover at 2015-03-24 19:00:00

contents of Memory Script:
{
   shutdown clone;
   startup clone nomount ;
}
executing Memory Script

database dismounted
Oracle instance shut down

connected to auxiliary database (not started)
Oracle instance started

Total System Global Area     167772160 bytes

Fixed Size                     1272624 bytes
Variable Size                 58721488 bytes
Database Buffers             104857600 bytes
Redo Buffers                   2920448 bytes
sql statement: CREATE CONTROLFILE REUSE SET DATABASE "DUP" RESETLOGS ARCHIVELOG
  MAXLOGFILES     16
  MAXLOGMEMBERS      3
  MAXDATAFILES      100
  MAXINSTANCES     8
  MAXLOGHISTORY      292
 LOGFILE
  GROUP  1 ( '/u01/app/oracle/oradata/test/redo01.log' ) SIZE 50 M  REUSE,
  GROUP  2 ( '/u01/app/oracle/oradata/test/redo02.log' ) SIZE 50 M  REUSE,
  GROUP  3 ( '/u01/app/oracle/oradata/test/redo03.log' ) SIZE 50 M  REUSE
 DATAFILE
  '/u01/app/oracle/oradata/test/system01.dbf'
 CHARACTER SET ZHS16GBK


contents of Memory Script:
{
   set newname for tempfile  1 to
 "/u01/app/oracle/oradata/test/temp01.dbf";
   switch clone tempfile all;
   catalog clone datafilecopy  "/u01/app/oracle/oradata/test/undotbs01.dbf";
   catalog clone datafilecopy  "/u01/app/oracle/oradata/test/sysaux01.dbf";
   catalog clone datafilecopy  "/u01/app/oracle/oradata/test/users01.dbf";
   catalog clone datafilecopy  "/u01/app/oracle/oradata/test/example01.dbf";
   catalog clone datafilecopy  "/u01/app/oracle/oradata/test/tspitr01.dbf";
   switch clone datafile all;
}
executing Memory Script

executing command: SET NEWNAME

renamed temporary file 1 to /u01/app/oracle/oradata/test/temp01.dbf in control file

cataloged datafile copy
datafile copy filename=/u01/app/oracle/oradata/test/undotbs01.dbf recid=1 stamp=875214019

cataloged datafile copy
datafile copy filename=/u01/app/oracle/oradata/test/sysaux01.dbf recid=2 stamp=875214019

cataloged datafile copy
datafile copy filename=/u01/app/oracle/oradata/test/users01.dbf recid=3 stamp=875214019

cataloged datafile copy
datafile copy filename=/u01/app/oracle/oradata/test/example01.dbf recid=4 stamp=875214019

cataloged datafile copy
datafile copy filename=/u01/app/oracle/oradata/test/tspitr01.dbf recid=5 stamp=875214019

datafile 2 switched to datafile copy
input datafile copy recid=1 stamp=875214019 filename=/u01/app/oracle/oradata/test/undotbs01.dbf
datafile 3 switched to datafile copy
input datafile copy recid=2 stamp=875214019 filename=/u01/app/oracle/oradata/test/sysaux01.dbf
datafile 4 switched to datafile copy
input datafile copy recid=3 stamp=875214019 filename=/u01/app/oracle/oradata/test/users01.dbf
datafile 5 switched to datafile copy
input datafile copy recid=4 stamp=875214019 filename=/u01/app/oracle/oradata/test/example01.dbf
datafile 6 switched to datafile copy
input datafile copy recid=5 stamp=875214019 filename=/u01/app/oracle/oradata/test/tspitr01.dbf

contents of Memory Script:
{
   Alter clone database open resetlogs;
}
executing Memory Script

database opened
Finished Duplicate Db at 2015-03-24 19:00:36

执行成功

总结:出现这个错误的原因是因为,启动辅助实例的会话没有断开连接,RMAN在执行duplicate
命令时不能有任何其它会话连接到辅助实例,否则就是会执行失败。

rman存储脚本

存储脚本是命令文件的一种替方法用来管理频繁使用的一系列RMAN命令。存储脚本相比命令文件来说它的优点就是对于任何连接到目标数据库和恢复目录的RMAN客户端都能够使用它。而命令文件只有能够访问它的RMAN客户端能够使用。

存储脚本可以是全局或者局部脚本。一个局存储脚本与创建该脚本时RMAN所连接的目标数据库相关,只能当连接到该目标数据库时才能执行存储脚本。一个全局的存储脚本能在恢复目录中所注册的所有数据库中执行。注意执行存储脚本,即使是全局存储脚本,也必须连接到恢复目录和目标实例才能执行。

创建存储脚本
确保RMAN连接到正确的目标数据库和恢复目录,然后执行create script命令来创建局部存储脚本。例如:

create script full_backup
{
backup as backupset database plus archivelog;
delete obsolete;
}


RMAN> create script full_backup
2> {
3> backup as backupset database plus archivelog;
4> delete obsolete;
5> }

created script full_backup

执行创建命令如果没有输出错误信息,那么该存储脚本full_backup就创建成功并存储在恢复目录中。

下面创建一个全局存储脚本,如下所示:

create global script global_full_backup
{
backup as backupset database plus archivelog;
delete obsolete;
}


RMAN> create global script global_full_backup
2> {
3> backup as backupset database plus archivelog;
4> delete obsolete;
5> }

created global script global_full_backup

还可以提供了comment来描述全局存储脚本:

create global script global_full_backup
comment 'use only with archivelog mode database'
{
backup as backupset database plus archivelog;
delete obsolete;
}

RMAN> create global script global_full_backup
2> comment 'use only with archivelog mode database'
3> {
4> backup as backupset database plus archivelog;
5> delete obsolete;
6> }

created global script global_full_backup

还可以读取文本文件来创建局部或全局存储脚本:

RMAN> create script test_script from file '/u01/app/oracle/test_script_file.txt';

script commands will be loaded from file /u01/app/oracle/test_script_file.txt
created script test_script

RMAN> create global script global_test_script from file '/u01/app/oracle/test_script_file.txt';

script commands will be loaded from file /u01/app/oracle/test_script_file.txt
created global script global_test_script

文本文件内宾3必须以{开始,再接RUN块中的一系列有效的命令,最后以}结束。

执行存储脚本
为了执行存储脚本,连接到目标数据库和恢复目录,使用execute script命令,execute script命令要求使用RUN块:

RMAN> run
2> {
3> execute script full_backup;
4> }

executing script: full_backup


Starting backup at 18-MAR-15
current log archived
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=145 devtype=DISK
channel ORA_DISK_1: starting archive log backupset
channel ORA_DISK_1: specifying archive log(s) in backup set
input archive log thread=1 sequence=1 recid=9 stamp=871547115
input archive log thread=1 sequence=2 recid=10 stamp=872692777
input archive log thread=1 sequence=3 recid=11 stamp=873390010
input archive log thread=1 sequence=4 recid=12 stamp=873477689
input archive log thread=1 sequence=5 recid=13 stamp=873557205
input archive log thread=1 sequence=6 recid=14 stamp=873628154
input archive log thread=1 sequence=7 recid=15 stamp=873881476
input archive log thread=1 sequence=8 recid=16 stamp=873969596
input archive log thread=1 sequence=9 recid=17 stamp=874234871
input archive log thread=1 sequence=10 recid=18 stamp=874315436
input archive log thread=1 sequence=11 recid=19 stamp=874486364
input archive log thread=1 sequence=12 recid=20 stamp=874574023
input archive log thread=1 sequence=13 recid=21 stamp=874579545
input archive log thread=1 sequence=14 recid=22 stamp=874657043
input archive log thread=1 sequence=15 recid=23 stamp=874663015
channel ORA_DISK_1: starting piece 1 at 18-MAR-15
channel ORA_DISK_1: finished piece 1 at 18-MAR-15
piece handle=/u01/app/oracle/flash_recovery_area/JY/backupset/2015_03_18/o1_mf_annnn_TAG20150318T095657_bjkpvd26_.bkp tag=TAG20150318T095657 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:27
channel ORA_DISK_1: starting archive log backupset
channel ORA_DISK_1: specifying archive log(s) in backup set
input archive log thread=1 sequence=44 recid=6 stamp=870948358
input archive log thread=1 sequence=45 recid=7 stamp=870948359
input archive log thread=1 sequence=46 recid=8 stamp=870948359
channel ORA_DISK_1: starting piece 1 at 18-MAR-15
channel ORA_DISK_1: finished piece 1 at 18-MAR-15
piece handle=/u01/app/oracle/flash_recovery_area/JY/backupset/2015_03_18/o1_mf_annnn_TAG20150318T095657_bjkpw6cl_.bkp tag=TAG20150318T095657 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:02
Finished backup at 18-MAR-15

Starting backup at 18-MAR-15
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
input datafile fno=00001 name=/u01/app/oracle/oradata/jy/system01.dbf
input datafile fno=00002 name=/u01/app/oracle/oradata/jy/undotbs01.dbf
input datafile fno=00003 name=/u01/app/oracle/oradata/jy/sysaux01.dbf
input datafile fno=00005 name=/u01/app/oracle/oradata/jy/example01.dbf
input datafile fno=00004 name=/u01/app/oracle/oradata/jy/users01.dbf
channel ORA_DISK_1: starting piece 1 at 18-MAR-15
channel ORA_DISK_1: finished piece 1 at 18-MAR-15
piece handle=/u01/app/oracle/flash_recovery_area/JY/backupset/2015_03_18/o1_mf_nnndf_TAG20150318T095727_bjkpw9xz_.bkp tag=TAG20150318T095727 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:01:15
Finished backup at 18-MAR-15

Starting backup at 18-MAR-15
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting archive log backupset
channel ORA_DISK_1: specifying archive log(s) in backup set
input archive log thread=1 sequence=16 recid=24 stamp=874663125
channel ORA_DISK_1: starting piece 1 at 18-MAR-15
channel ORA_DISK_1: finished piece 1 at 18-MAR-15
piece handle=/u01/app/oracle/flash_recovery_area/JY/backupset/2015_03_18/o1_mf_annnn_TAG20150318T095845_bjkpyqdc_.bkp tag=TAG20150318T095845 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:02
Finished backup at 18-MAR-15

Starting Control File and SPFILE Autobackup at 18-MAR-15
piece handle=/u01/app/oracle/flash_recovery_area/JY/autobackup/2015_03_18/o1_mf_s_874663128_bjkpytxr_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 18-MAR-15

RMAN retention policy will be applied to the command
RMAN retention policy is set to redundancy 1
using channel ORA_DISK_1
Deleting the following obsolete backups and copies:
Type                 Key    Completion Time    Filename/Handle
-------------------- ------ ------------------ --------------------
Archive Log          3769   06-FEB-15          /u01/app/oracle/flash_recovery_area/JY/archivelog/2015_02_06/o1_mf_1_44_bf88d537_.arc
Archive Log          3770   06-FEB-15          /u01/app/oracle/flash_recovery_area/JY/archivelog/2015_02_06/o1_mf_1_45_bf88d73o_.arc
Archive Log          3771   06-FEB-15          /u01/app/oracle/flash_recovery_area/JY/archivelog/2015_02_06/o1_mf_1_46_bf88d7cv_.arc
Archive Log          3772   13-FEB-15          /u01/app/oracle/flash_recovery_area/JY/archivelog/2015_02_13/o1_mf_1_1_bftk375y_.arc
Archive Log          3773   26-FEB-15          /u01/app/oracle/flash_recovery_area/JY/archivelog/2015_02_26/o1_mf_1_2_bgxhx2ww_.arc
Archive Log          3774   03-MAR-15          /u01/app/oracle/flash_recovery_area/JY/archivelog/2015_03_03/o1_mf_1_3_bhbvorcp_.arc
Archive Log          3775   04-MAR-15          /u01/app/oracle/flash_recovery_area/JY/archivelog/2015_03_04/o1_mf_1_4_bhfk9mdr_.arc
Archive Log          3776   05-MAR-15          /u01/app/oracle/flash_recovery_area/JY/archivelog/2015_03_05/o1_mf_1_5_bhhyxwnp_.arc
Archive Log          3777   06-MAR-15          /u01/app/oracle/flash_recovery_area/JY/archivelog/2015_03_06/o1_mf_1_6_bhl47mgr_.arc
Archive Log          3778   09-MAR-15          /u01/app/oracle/flash_recovery_area/JY/archivelog/2015_03_09/o1_mf_1_7_bhsvmzby_.arc
Archive Log          3779   10-MAR-15          /u01/app/oracle/flash_recovery_area/JY/archivelog/2015_03_10/o1_mf_1_8_bhwkos6m_.arc
Archive Log          3780   13-MAR-15          /u01/app/oracle/flash_recovery_area/JY/archivelog/2015_03_13/o1_mf_1_9_bj4nqm2j_.arc
Archive Log          3781   14-MAR-15          /u01/app/oracle/flash_recovery_area/JY/archivelog/2015_03_14/o1_mf_1_10_bj73f7y4_.arc
Archive Log          3782   16-MAR-15          /u01/app/oracle/flash_recovery_area/JY/archivelog/2015_03_16/o1_mf_1_11_bjdbbrvm_.arc
Archive Log          3783   17-MAR-15          /u01/app/oracle/flash_recovery_area/JY/archivelog/2015_03_17/o1_mf_1_12_bjgzxz92_.arc
Archive Log          3784   17-MAR-15          /u01/app/oracle/flash_recovery_area/JY/archivelog/2015_03_17/o1_mf_1_13_bjh5bqyo_.arc
Archive Log          3785   18-MAR-15          /u01/app/oracle/flash_recovery_area/JY/archivelog/2015_03_18/o1_mf_1_14_bjkk0h4p_.arc
Backup Set           3786   06-FEB-15
  Backup Piece       3788   06-FEB-15          /u01/app/oracle/flash_recovery_area/JY/autobackup/2015_02_06/o1_mf_s_870945982_bf861zo6_.bkp
Datafile Copy        3794   03-MAR-15          /u01/app/oracle/users01.dbf
Backup Set           3787   06-FEB-15
  Backup Piece       3789   06-FEB-15          /u01/app/oracle/flash_recovery_area/JY/autobackup/2015_02_06/o1_mf_s_870948381_bf88dyom_.bkp
Archive Log          3806   18-MAR-15          /u01/app/oracle/flash_recovery_area/JY/archivelog/2015_03_18/o1_mf_1_15_bjkpv6py_.arc
Backup Set           3813   18-MAR-15
  Backup Piece       3817   18-MAR-15          /u01/app/oracle/flash_recovery_area/JY/backupset/2015_03_18/o1_mf_annnn_TAG20150318T095657_bjkpvd26_.bkp
Backup Set           3814   18-MAR-15
  Backup Piece       3818   18-MAR-15          /u01/app/oracle/flash_recovery_area/JY/backupset/2015_03_18/o1_mf_annnn_TAG20150318T095657_bjkpw6cl_.bkp

Do you really want to delete the above objects (enter YES or NO)? YES
deleted archive log
archive log filename=/u01/app/oracle/flash_recovery_area/JY/archivelog/2015_02_06/o1_mf_1_44_bf88d537_.arc recid=6 stamp=870948358
deleted archive log
archive log filename=/u01/app/oracle/flash_recovery_area/JY/archivelog/2015_02_06/o1_mf_1_45_bf88d73o_.arc recid=7 stamp=870948359
deleted archive log
archive log filename=/u01/app/oracle/flash_recovery_area/JY/archivelog/2015_02_06/o1_mf_1_46_bf88d7cv_.arc recid=8 stamp=870948359
deleted archive log
archive log filename=/u01/app/oracle/flash_recovery_area/JY/archivelog/2015_02_13/o1_mf_1_1_bftk375y_.arc recid=9 stamp=871547115
deleted archive log
archive log filename=/u01/app/oracle/flash_recovery_area/JY/archivelog/2015_02_26/o1_mf_1_2_bgxhx2ww_.arc recid=10 stamp=872692777
deleted archive log
archive log filename=/u01/app/oracle/flash_recovery_area/JY/archivelog/2015_03_03/o1_mf_1_3_bhbvorcp_.arc recid=11 stamp=873390010
deleted archive log
archive log filename=/u01/app/oracle/flash_recovery_area/JY/archivelog/2015_03_04/o1_mf_1_4_bhfk9mdr_.arc recid=12 stamp=873477689
deleted archive log
archive log filename=/u01/app/oracle/flash_recovery_area/JY/archivelog/2015_03_05/o1_mf_1_5_bhhyxwnp_.arc recid=13 stamp=873557205
deleted archive log
archive log filename=/u01/app/oracle/flash_recovery_area/JY/archivelog/2015_03_06/o1_mf_1_6_bhl47mgr_.arc recid=14 stamp=873628154
deleted archive log
archive log filename=/u01/app/oracle/flash_recovery_area/JY/archivelog/2015_03_09/o1_mf_1_7_bhsvmzby_.arc recid=15 stamp=873881476
deleted archive log
archive log filename=/u01/app/oracle/flash_recovery_area/JY/archivelog/2015_03_10/o1_mf_1_8_bhwkos6m_.arc recid=16 stamp=873969596
deleted archive log
archive log filename=/u01/app/oracle/flash_recovery_area/JY/archivelog/2015_03_13/o1_mf_1_9_bj4nqm2j_.arc recid=17 stamp=874234871
deleted archive log
archive log filename=/u01/app/oracle/flash_recovery_area/JY/archivelog/2015_03_14/o1_mf_1_10_bj73f7y4_.arc recid=18 stamp=874315436
deleted archive log
archive log filename=/u01/app/oracle/flash_recovery_area/JY/archivelog/2015_03_16/o1_mf_1_11_bjdbbrvm_.arc recid=19 stamp=874486364
deleted archive log
archive log filename=/u01/app/oracle/flash_recovery_area/JY/archivelog/2015_03_17/o1_mf_1_12_bjgzxz92_.arc recid=20 stamp=874574023
deleted archive log
archive log filename=/u01/app/oracle/flash_recovery_area/JY/archivelog/2015_03_17/o1_mf_1_13_bjh5bqyo_.arc recid=21 stamp=874579545
deleted archive log
archive log filename=/u01/app/oracle/flash_recovery_area/JY/archivelog/2015_03_18/o1_mf_1_14_bjkk0h4p_.arc recid=22 stamp=874657043
deleted backup piece
backup piece handle=/u01/app/oracle/flash_recovery_area/JY/autobackup/2015_02_06/o1_mf_s_870945982_bf861zo6_.bkp recid=4 stamp=870948272
deleted datafile copy
datafile copy filename=/u01/app/oracle/users01.dbf recid=2 stamp=873392067
deleted backup piece
backup piece handle=/u01/app/oracle/flash_recovery_area/JY/autobackup/2015_02_06/o1_mf_s_870948381_bf88dyom_.bkp recid=5 stamp=870948382
deleted archive log
archive log filename=/u01/app/oracle/flash_recovery_area/JY/archivelog/2015_03_18/o1_mf_1_15_bjkpv6py_.arc recid=23 stamp=874663015
deleted backup piece
backup piece handle=/u01/app/oracle/flash_recovery_area/JY/backupset/2015_03_18/o1_mf_annnn_TAG20150318T095657_bjkpvd26_.bkp recid=6 stamp=874663020
deleted backup piece
backup piece handle=/u01/app/oracle/flash_recovery_area/JY/backupset/2015_03_18/o1_mf_annnn_TAG20150318T095657_bjkpw6cl_.bkp recid=7 stamp=874663046
Deleted 23 objects

上面的命令将调用指定名称的局部脚本full_script。如果没有找到局部脚本,但存在相同名称的全局脚本,RMAN将执行同名的全局存储脚本。如果存在同名的局部和全局脚本可以使用execute global script来控制只执行全局脚本。在恢复目录中没有名叫global_full_backup的局部脚本存在,那么执行下面两个命令的结果是一样的:

RMAN> run
2> {
3> execute global script global_full_backup;
4> }

executing global script: global_full_backup


Starting backup at 18-MAR-15
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting archive log backupset
channel ORA_DISK_1: specifying archive log(s) in backup set
input archive log thread=1 sequence=16 recid=24 stamp=874663125
input archive log thread=1 sequence=17 recid=25 stamp=874663571
channel ORA_DISK_1: starting piece 1 at 18-MAR-15
channel ORA_DISK_1: finished piece 1 at 18-MAR-15
piece handle=/u01/app/oracle/flash_recovery_area/JY/backupset/2015_03_18/o1_mf_annnn_TAG20150318T100613_bjkqdppq_.bkp tag=TAG20150318T100613 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:02
Finished backup at 18-MAR-15

Starting backup at 18-MAR-15
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
input datafile fno=00001 name=/u01/app/oracle/oradata/jy/system01.dbf
input datafile fno=00002 name=/u01/app/oracle/oradata/jy/undotbs01.dbf
input datafile fno=00003 name=/u01/app/oracle/oradata/jy/sysaux01.dbf
input datafile fno=00005 name=/u01/app/oracle/oradata/jy/example01.dbf
input datafile fno=00004 name=/u01/app/oracle/oradata/jy/users01.dbf
channel ORA_DISK_1: starting piece 1 at 18-MAR-15
channel ORA_DISK_1: finished piece 1 at 18-MAR-15
piece handle=/u01/app/oracle/flash_recovery_area/JY/backupset/2015_03_18/o1_mf_nnndf_TAG20150318T100615_bjkqds89_.bkp tag=TAG20150318T100615 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:01:15
Finished backup at 18-MAR-15

Starting backup at 18-MAR-15
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting archive log backupset
channel ORA_DISK_1: specifying archive log(s) in backup set
input archive log thread=1 sequence=18 recid=26 stamp=874663651
channel ORA_DISK_1: starting piece 1 at 18-MAR-15
channel ORA_DISK_1: finished piece 1 at 18-MAR-15
piece handle=/u01/app/oracle/flash_recovery_area/JY/backupset/2015_03_18/o1_mf_annnn_TAG20150318T100732_bjkqh6cv_.bkp tag=TAG20150318T100732 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:02
Finished backup at 18-MAR-15

Starting Control File and SPFILE Autobackup at 18-MAR-15
piece handle=/u01/app/oracle/flash_recovery_area/JY/autobackup/2015_03_18/o1_mf_s_874663655_bjkqh9db_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 18-MAR-15

RMAN retention policy will be applied to the command
RMAN retention policy is set to redundancy 1
using channel ORA_DISK_1
Deleting the following obsolete backups and copies:
Type                 Key    Completion Time    Filename/Handle
-------------------- ------ ------------------ --------------------
Archive Log          3845   18-MAR-15          /u01/app/oracle/flash_recovery_area/JY/archivelog/2015_03_18/o1_mf_1_16_bjkpynv3_.arc
Backup Set           3846   18-MAR-15
  Backup Piece       3850   18-MAR-15          /u01/app/oracle/flash_recovery_area/JY/backupset/2015_03_18/o1_mf_nnndf_TAG20150318T095727_bjkpw9xz_.bkp
Backup Set           3864   18-MAR-15
  Backup Piece       3870   18-MAR-15          /u01/app/oracle/flash_recovery_area/JY/backupset/2015_03_18/o1_mf_annnn_TAG20150318T095845_bjkpyqdc_.bkp
Archive Log          3913   18-MAR-15          /u01/app/oracle/flash_recovery_area/JY/archivelog/2015_03_18/o1_mf_1_17_bjkqdmto_.arc
Backup Set           3880   18-MAR-15
  Backup Piece       3882   18-MAR-15          /u01/app/oracle/flash_recovery_area/JY/autobackup/2015_03_18/o1_mf_s_874663128_bjkpytxr_.bkp
Backup Set           3925   18-MAR-15
  Backup Piece       3928   18-MAR-15          /u01/app/oracle/flash_recovery_area/JY/backupset/2015_03_18/o1_mf_annnn_TAG20150318T100613_bjkqdppq_.bkp

Do you really want to delete the above objects (enter YES or NO)? yes
deleted archive log
archive log filename=/u01/app/oracle/flash_recovery_area/JY/archivelog/2015_03_18/o1_mf_1_16_bjkpynv3_.arc recid=24 stamp=874663125
deleted backup piece
backup piece handle=/u01/app/oracle/flash_recovery_area/JY/backupset/2015_03_18/o1_mf_nnndf_TAG20150318T095727_bjkpw9xz_.bkp recid=8 stamp=874663049
deleted backup piece
backup piece handle=/u01/app/oracle/flash_recovery_area/JY/backupset/2015_03_18/o1_mf_annnn_TAG20150318T095845_bjkpyqdc_.bkp recid=9 stamp=874663127
deleted archive log
archive log filename=/u01/app/oracle/flash_recovery_area/JY/archivelog/2015_03_18/o1_mf_1_17_bjkqdmto_.arc recid=25 stamp=874663571
deleted backup piece
backup piece handle=/u01/app/oracle/flash_recovery_area/JY/autobackup/2015_03_18/o1_mf_s_874663128_bjkpytxr_.bkp recid=10 stamp=874663130
deleted backup piece
backup piece handle=/u01/app/oracle/flash_recovery_area/JY/backupset/2015_03_18/o1_mf_annnn_TAG20150318T100613_bjkqdppq_.bkp recid=11 stamp=874663574
Deleted 6 objects



RMAN> run
2> {
3> execute script global_full_backup;
4> }

executing global script: global_full_backup


Starting backup at 18-MAR-15
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting archive log backupset
channel ORA_DISK_1: specifying archive log(s) in backup set
input archive log thread=1 sequence=18 recid=26 stamp=874663651
input archive log thread=1 sequence=19 recid=27 stamp=874664008
channel ORA_DISK_1: starting piece 1 at 18-MAR-15
channel ORA_DISK_1: finished piece 1 at 18-MAR-15
piece handle=/u01/app/oracle/flash_recovery_area/JY/backupset/2015_03_18/o1_mf_annnn_TAG20150318T101329_bjkqtbtn_.bkp tag=TAG20150318T101329 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:02
Finished backup at 18-MAR-15

Starting backup at 18-MAR-15
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
input datafile fno=00001 name=/u01/app/oracle/oradata/jy/system01.dbf
input datafile fno=00002 name=/u01/app/oracle/oradata/jy/undotbs01.dbf
input datafile fno=00003 name=/u01/app/oracle/oradata/jy/sysaux01.dbf
input datafile fno=00005 name=/u01/app/oracle/oradata/jy/example01.dbf
input datafile fno=00004 name=/u01/app/oracle/oradata/jy/users01.dbf
channel ORA_DISK_1: starting piece 1 at 18-MAR-15
channel ORA_DISK_1: finished piece 1 at 18-MAR-15
piece handle=/u01/app/oracle/flash_recovery_area/JY/backupset/2015_03_18/o1_mf_nnndf_TAG20150318T101331_bjkqtdoh_.bkp tag=TAG20150318T101331 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:01:05
Finished backup at 18-MAR-15

Starting backup at 18-MAR-15
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting archive log backupset
channel ORA_DISK_1: specifying archive log(s) in backup set
input archive log thread=1 sequence=20 recid=28 stamp=874664078
channel ORA_DISK_1: starting piece 1 at 18-MAR-15
channel ORA_DISK_1: finished piece 1 at 18-MAR-15
piece handle=/u01/app/oracle/flash_recovery_area/JY/backupset/2015_03_18/o1_mf_annnn_TAG20150318T101439_bjkqwjl4_.bkp tag=TAG20150318T101439 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:02
Finished backup at 18-MAR-15

Starting Control File and SPFILE Autobackup at 18-MAR-15
piece handle=/u01/app/oracle/flash_recovery_area/JY/autobackup/2015_03_18/o1_mf_s_874664082_bjkqwmhg_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 18-MAR-15

RMAN retention policy will be applied to the command
RMAN retention policy is set to redundancy 1
using channel ORA_DISK_1
Deleting the following obsolete backups and copies:
Type                 Key    Completion Time    Filename/Handle
-------------------- ------ ------------------ --------------------
Archive Log          3944   18-MAR-15          /u01/app/oracle/flash_recovery_area/JY/archivelog/2015_03_18/o1_mf_1_18_bjkqh3ov_.arc
Backup Set           3945   18-MAR-15
  Backup Piece       3948   18-MAR-15          /u01/app/oracle/flash_recovery_area/JY/backupset/2015_03_18/o1_mf_nnndf_TAG20150318T100615_bjkqds89_.bkp
Backup Set           3967   18-MAR-15
  Backup Piece       3973   18-MAR-15          /u01/app/oracle/flash_recovery_area/JY/backupset/2015_03_18/o1_mf_annnn_TAG20150318T100732_bjkqh6cv_.bkp
Archive Log          4036   18-MAR-15          /u01/app/oracle/flash_recovery_area/JY/archivelog/2015_03_18/o1_mf_1_19_bjkqt8p5_.arc
Backup Set           3988   18-MAR-15
  Backup Piece       3990   18-MAR-15          /u01/app/oracle/flash_recovery_area/JY/autobackup/2015_03_18/o1_mf_s_874663655_bjkqh9db_.bkp
Backup Set           4053   18-MAR-15
  Backup Piece       4056   18-MAR-15          /u01/app/oracle/flash_recovery_area/JY/backupset/2015_03_18/o1_mf_annnn_TAG20150318T101329_bjkqtbtn_.bkp

Do you really want to delete the above objects (enter YES or NO)? YES
deleted archive log
archive log filename=/u01/app/oracle/flash_recovery_area/JY/archivelog/2015_03_18/o1_mf_1_18_bjkqh3ov_.arc recid=26 stamp=874663651
deleted backup piece
backup piece handle=/u01/app/oracle/flash_recovery_area/JY/backupset/2015_03_18/o1_mf_nnndf_TAG20150318T100615_bjkqds89_.bkp recid=12 stamp=874663576
deleted backup piece
backup piece handle=/u01/app/oracle/flash_recovery_area/JY/backupset/2015_03_18/o1_mf_annnn_TAG20150318T100732_bjkqh6cv_.bkp recid=13 stamp=874663654
deleted archive log
archive log filename=/u01/app/oracle/flash_recovery_area/JY/archivelog/2015_03_18/o1_mf_1_19_bjkqt8p5_.arc recid=27 stamp=874664008
deleted backup piece
backup piece handle=/u01/app/oracle/flash_recovery_area/JY/autobackup/2015_03_18/o1_mf_s_874663655_bjkqh9db_.bkp recid=14 stamp=874663657
deleted backup piece
backup piece handle=/u01/app/oracle/flash_recovery_area/JY/backupset/2015_03_18/o1_mf_annnn_TAG20150318T101329_bjkqtbtn_.bkp recid=15 stamp=874664010
Deleted 6 objects

在执行全局脚本只影响RMAN所连接到的目标数据库;为了跨多个数据库执行全局脚本,必须单独连接到每一个数据库并执行全局存储脚本。

在执行脚本时将会使用配置的自动通道来执行脚本。如果需要覆盖配置的自动通道可以在脚本中使用allocate channel命令来手动分配通道。注意因为使用的是RUN块,如果脚本中的一个RMAN命令失败,脚本中的后续命令将不会执行。

查看存储脚本内容
print script命令用来查看存储脚本或将脚本内容写入到新文件。使用RMAN连接到目标数据库和恢复目录。执行print script:

RMAN> print script full_backup;

printing stored script: full_backup
 {backup as backupset database plus archivelog;
delete obsolete;
}

显示全局脚本内容:
RMAN> print global script global_full_backup;

printing stored global script: global_full_backup
 {backup as backupset database plus archivelog;
delete obsolete;
}

为将脚本内容写入到新文件中,执行以下命令:

RMAN> print script full_backup to file '/u01/app/oracle/full_backup.txt';

script full_backup written to file /u01/app/oracle/full_backup.txt

将全局脚本内容写入文件:

RMAN> print global script global_full_backup to file '/u01/app/oracle/global_full_backup.txt';

global script global_full_backup written to file /u01/app/oracle/global_full_backup.txt

查看恢复目录中的存储脚本:list script names
使用list script names命令来显示恢复目录中的存储脚本名。这个命令会显示所有存储脚本名。

RMAN> list script names;

List of Stored Scripts in Recovery Catalog


    Scripts of Target Database JY

       Script Name
       Description
       -----------------------------------------------------------------------
       full_backup


    Global Scripts


       Script Name
       Description
       -----------------------------------------------------------------------
       global_full_backup
       use only with archivelog mode database

只显示全局存储脚本名:

RMAN> list global script names;

List of Stored Scripts in Recovery Catalog


    Global Scripts


       Script Name
       Description
       -----------------------------------------------------------------------
       global_full_backup
       use only with archivelog mode database

为了查看当前恢复目录中所有存储脚本的名称,包括在恢复目录中所有已经注册的目标数据库的全局和局部脚本,执行以下命令:

RMAN> list all script names;

List of Stored Scripts in Recovery Catalog


    Global Scripts


       Script Name
       Description
       -----------------------------------------------------------------------
       global_full_backup
       use only with archivelog mode database


    Scripts of Target Database JY

       Script Name
       Description
       -----------------------------------------------------------------------
       full_backup


    Scripts of Target Database TEST

       Script Name
       Description
       -----------------------------------------------------------------------
       test_full_backup

可以看到上面显示了两个目标数据库(jy,test)中的所有存储脚本

更新存储脚本
为了更新存储脚本,连接到目标数据库和恢复目录并使用replace script命令来执行更新。如果脚本不存在,那么RMAN将会创建一个新存储脚本。

下面的命令用来更新脚本full_backup的内容:
先来查看恢复目录中所有存储脚本名来检查是否存在full_backup脚本

RMAN> list all script names;

List of Stored Scripts in Recovery Catalog


    Global Scripts


       Script Name
       Description
       -----------------------------------------------------------------------
       global_full_backup
       use only with archivelog mode database


    Scripts of Target Database JY

       Script Name
       Description
       -----------------------------------------------------------------------
       full_backup


    Scripts of Target Database TEST

       Script Name
       Description
       -----------------------------------------------------------------------
       test_full_backup

查看脚本full_backup的内容

RMAN> print script full_backup;

printing stored script: full_backup
 {backup as backupset database plus archivelog;
delete obsolete;
}

更新脚本full_backup
RMAN> replace script full_backup
2> {
3> backup as backupset database plus archivelog;
4> }

replaced script full_backup

检查脚本full_backup是否已经被更新

RMAN> print script full_backup;

printing stored script: full_backup
 {backup as backupset database plus archivelog;
}

从脚本内容可知full_backup内容确实已经被更新.

下面来更新一个不存在的脚本full_backup_bak

RMAN> replace script full_backup_update
2> {
3> backup as backupset database plus archivelog;
4> }

replaced script full_backup_update

从下面的信息中可以看到当更新一个不存在的脚本,RMAN确实会创建这个脚本

RMAN> list all script names;

List of Stored Scripts in Recovery Catalog


    Global Scripts


       Script Name
       Description
       -----------------------------------------------------------------------
       global_full_backup
       use only with archivelog mode database


    Scripts of Target Database JY

       Script Name
       Description
       -----------------------------------------------------------------------
       full_backup

       full_backup_update


    Scripts of Target Database TEST

       Script Name
       Description
       -----------------------------------------------------------------------
       test_full_backup



RMAN> print script full_backup_update;

printing stored script: full_backup_update
 {backup as backupset database plus archivelog;
}

全局存储脚本可以使用replace global script命令来进行更新:
查看更新前global_full_backup脚本的内容

RMAN> print script global_full_backup;

printing stored global script: global_full_backup
 {backup as backupset database plus archivelog;
delete obsolete;
}

更新全局脚本global_full_backup

RMAN> replace global script global_full_backup
2> {
3> backup as backupset database plus archivelog;
4> }

replaced global script global_full_backup

显示更新后全局脚本global_full_backup的内容

RMAN> print global script global_full_backup;

printing stored global script: global_full_backup
 {backup as backupset database plus archivelog;
}

与create script命令一样,可以使用文件来更新局部或全局存储脚本。

更新前查看全局脚本global_full_backup的内容

RMAN> print global script global_full_backup;

printing stored global script: global_full_backup
 {backup as backupset database plus archivelog;
}

使用global_full_backup.txt文件来更新全局脚本global_full_backup

RMAN> replace global script global_full_backup from file '/u01/app/oracle/global_full_backup.txt';

script commands will be loaded from file /u01/app/oracle/global_full_backup.txt
replaced global script global_full_backup

查看更新后的脚本内容:

RMAN> print global script global_full_backup;

printing stored global script: global_full_backup
 {backup as backupset database plus archivelog;
delete obsolete;
}

更新前查看局部脚本full_backup的内容

RMAN> print script full_backup;

printing stored script: full_backup
 {backup as backupset database plus archivelog;
}

使用full_backup.txt文件来更新局部脚本full_backup

RMAN> replace script full_backup from file '/u01/app/oracle/full_backup.txt';

script commands will be loaded from file /u01/app/oracle/full_backup.txt
replaced script full_backup

查看更新后的脚本内容:

RMAN> print script full_backup;

printing stored script: full_backup
 {backup as backupset database plus archivelog;
delete obsolete;
}

删除存储脚本
为了从恢复目录中删除存储脚本,连接恢复目录和目标数据库后执行delete script命令:

RMAN> list script names;

List of Stored Scripts in Recovery Catalog


    Scripts of Target Database JY

       Script Name
       Description
       -----------------------------------------------------------------------
       full_backup

       full_backup_update


    Global Scripts


       Script Name
       Description
       -----------------------------------------------------------------------
       global_full_backup

为了从恢复目录中删除局部存储脚本full_backup

RMAN> delete script 'full_backup';

deleted script: full_backup

为了删除全局存储脚本global_full_backup,执行delete global script:

RMAN> delete global script 'global_full_backup';

deleted global script: global_full_backup

如果没有给delete script命令指定global参数,并且目标数据库中没有指定名称的存储脚本存在,RMAN将使用指定名称来查找全局存储脚本如果找到就将其删除。因此为了删除全局存储脚本也可以执行以下的命令:

RMAN> delete script 'global_full_backup';

deleted script: global_full_backup

对于delete script ‘global_full_backup’命令,RMAN会在连接到的目标数据库中查找脚本’global_full_backup’,如果没有找到,将会搜索名为’global_full_backup’的全局脚本,如果找到就将其删除。

启动RMAN客户端并执行存储脚本
为了运行RMAN客户端并执行存储在恢复目录中的存储脚本,可以使用script参数来启动RMAN客户端:

[oracle@oracle11g ~]$ rman target sys/zzh_2046@test catalog rman/rman@jy script 'global_full_backup'

Recovery Manager: Release 10.2.0.5.0 - Production on Wed Mar 18 11:22:04 2015

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

connected to target database: TEST (DBID=2168949517)
connected to recovery catalog database

executing global script: global_full_backup


Starting backup at 18-MAR-15
current log archived
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=141 devtype=DISK
skipping archive log file /u02/1_49_870806981.dbf; already backed up 1 time(s)
skipping archive log file /u02/1_50_870806981.dbf; already backed up 1 time(s)
skipping archive log file /u02/1_51_870806981.dbf; already backed up 1 time(s)
skipping archive log file /u02/1_52_870806981.dbf; already backed up 1 time(s)
skipping archive log file /u02/1_53_870806981.dbf; already backed up 1 time(s)
skipping archive log file /u02/1_54_870806981.dbf; already backed up 1 time(s)
skipping archive log file /u02/1_55_870806981.dbf; already backed up 1 time(s)
skipping archive log file /u02/1_56_870806981.dbf; already backed up 1 time(s)
channel ORA_DISK_1: starting archive log backupset
channel ORA_DISK_1: specifying archive log(s) in backup set
input archive log thread=1 sequence=57 recid=64 stamp=874668125
channel ORA_DISK_1: starting piece 1 at 18-MAR-15
channel ORA_DISK_1: finished piece 1 at 18-MAR-15
piece handle=/u02/ora_test874668127_671 tag=TAG20150318T112206 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:02
Finished backup at 18-MAR-15

Starting backup at 18-MAR-15
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
input datafile fno=00001 name=/u01/app/oracle/oradata/test/system01.dbf
input datafile fno=00003 name=/u01/app/oracle/oradata/test/sysaux01.dbf
input datafile fno=00005 name=/u01/app/oracle/oradata/test/example01.dbf
input datafile fno=00006 name=/u01/app/oracle/oradata/test/tspitr01.dbf
input datafile fno=00002 name=/u01/app/oracle/oradata/test/undotbs01.dbf
input datafile fno=00004 name=/u01/app/oracle/oradata/test/users01.dbf
channel ORA_DISK_1: starting piece 1 at 18-MAR-15
channel ORA_DISK_1: finished piece 1 at 18-MAR-15
piece handle=/u02/ora_test874668130_681 tag=TAG20150318T112209 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:01:15
Finished backup at 18-MAR-15

Starting backup at 18-MAR-15
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting archive log backupset
channel ORA_DISK_1: specifying archive log(s) in backup set
input archive log thread=1 sequence=58 recid=65 stamp=874668205
channel ORA_DISK_1: starting piece 1 at 18-MAR-15
channel ORA_DISK_1: finished piece 1 at 18-MAR-15
piece handle=/u02/ora_test874668206_691 tag=TAG20150318T112326 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:02
Finished backup at 18-MAR-15

Starting Control File and SPFILE Autobackup at 18-MAR-15
piece handle=/u01/app/oracle/flash_recovery_area/TEST/autobackup/2015_03_18/o1_mf_s_874668209_bjkvxl3b_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 18-MAR-15

Recovery Manager complete.

在启动RMAN客户端时必须要连接到恢复目录(存储脚本存储在恢复目录中)和目标数据库。

存储脚本命名限制
RMAN是如何解决脚本名称,尤其是在局部和全局脚本共享相同名称时存在的一些问题:
.RMAN允许但一般不要求将存储脚本名使用引号括起来。然而,存储脚本名以数字或RMAN的保留关键开头就需要将存储脚本名称使用引号括起来。对于存储脚本名称要考虑避免使用A-Z之外的字符或RMAN的保留关键字作为名称的开始字符。
.当在命令行中使用script参数来启动RMAN客户端,如果存在相同名称的局部和全局存储脚本,那么RMAN将总是执行局部脚本。
.对于execute script,delete script和print script命令,如果脚本名称作为一个参数被传递并且在连接到的目标数据库中没有该相同名称的脚本存在,RMAN将执行,删除或显示相同名称的全局脚本。例如,如果在恢复目录中存在一个名叫global_full_backup的全局存储脚本,但在目标数据库中没有名叫global_full_backup的局部存储脚本,下面的命令将会删除全局脚本:
DELETE SCRIPT global_full_backup;

rman连接辅助数据库ORA-04031: unable to allocate 1040 bytes of shared memory

在给oracle 10g搭建dg使用rman复制数据库时,在连接辅助实例时出错,错误信息如下所示:

[oracle@oracle11g admin]$ rman target sys/zzh_2046@test auxiliary sys/system@aux_test catalog rman/rman@jy

Recovery Manager: Release 10.2.0.5.0 - Production on Tue Mar 17 10:50:22 2015

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

connected to target database: TEST (DBID=2168949517)
connected to recovery catalog database
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-00554: initialization of internal recovery manager package failed
RMAN-04006: error from auxiliary database: ORA-00600: internal error code, arguments: [15435], [SYS], [X$STANDARD], [], [], [], [], []
ORA-04031: unable to allocate 1040 bytes of shared memory ("shared pool","X$STANDARD","PL/SQL DIANA","PAR.C:parapt:Page")
RMAN-04015: error setting target database character set to ZHS16GBK

从上面的错误信息可以看到ORA-04031是因为不能给共享内存分配1040 bytes大小的内存。如是直接用rman连接辅助实例也出现错误,错误信息如下所示:

[oracle@jingyong1 ~]$ rman target sys/system@aux_test

Recovery Manager: Release 10.2.0.5.0 - Production on Tue Mar 17 10:51:28 2015

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

RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-00554: initialization of internal recovery manager package failed
RMAN-04005: error from target database:
ORA-00600: internal error code, arguments: [15435], [SYS], [X$STANDARD], [], [], [], [], []
ORA-04031: unable to allocate 1040 bytes of shared memory ("shared pool","X$STANDARD","PL/SQL DIANA","PAR.C:parapt:Page")
RMAN-04015: error setting target database character set to ZHS16GBK

在MOS上找到了ORA-4031 During Startup Nomount using RMAN without parameter file [ID 1176443.1]内容如下:

Applies to:
Oracle Database - Enterprise Edition - Version 11.2.0.1 and later
Information in this document applies to any platform.
***Checked for relevance on 08-May-2013***
Symptoms
RMAN startup nomount failed with ORA-4031

Customer was testing RMAN backup/restore in Exadata.
Customer firstly backup the database to tape and then remove all the datafiles, spfile, controlfiles for testing.
Then during the recover, customer connected RMAN with nocatalog and try to "startup nomount", then ORA-4031 occured.



==================== Log ========================
oracle@hkfop011db01:/home/oracle
$ export ORACLE_SID=TEST
oracle@test011db01:/home/oracle
$ rman target / nocatalog

Recovery Manager: Release 11.2.0.1.0 - Production on Thu Jul 8 20:45:10 2010
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
connected to target database (not started)

RMAN> startup nomount

startup failed: ORA-01078: failure in processing system parameters
LRM-00109: could not open parameter file '/oracle/product/11.2.0/db_1/dbs/initTEST.ora'

starting Oracle instance without parameter file for retrieval of spfile
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of startup command at 07/08/2010 20:45:19
RMAN-04014: startup failed: ORA-04031: unable to allocate 111264 bytes of shared memory ("shared pool","unknown object","sga heap(1,0)","KEWS sesstat values")
Cause
RMAN has failed to start a dummy instance without pfile.
Default values used for the dummy instance are not enough to start the instance up.

This is reported in Bug 9680987 - RMAN CANNOT START DATABASE WITHOUT PARAMETER FILE

Solution
There are two possible solutions:
1- Create temporary init.ora file (/oracle/product/11.2.0/db_1/dbs/initTEST.ora) with the following parameters:

    db_name=
    large_pool_size=100m
    shared_pool_size=250m
    db_cache_size=10m

2- Set environment variable  ORA_RMAN_SGA_TARGET before executing rman. For example:

    $ export ORA_RMAN_SGA_TARGET=350

这篇文章给出了两种解决方法,一种是增加内存参数,一种是设置环境变量,适用版本是11.2.0.1及其以后版本,我这里是oracle 10.2.0.5,因为第二种方法简单,所以尝试使用设置环境变量的方法:

[oracle@jingyong1 ~]$ export ORA_RMAN_SGA_TARGET=350
[oracle@jingyong1 ~]$ rman target sys/system@aux_test

Recovery Manager: Release 10.2.0.5.0 - Production on Tue Mar 17 10:51:46 2015

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

RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-00554: initialization of internal recovery manager package failed
RMAN-06003: ORACLE error from target database:
ORA-00604: error occurred at recursive SQL level 2
ORA-04031: unable to allocate 16 bytes of shared memory ("shared pool","select ks.inst_id,ksuxsins,k...","sql area","ub1[]: qkexrXformVal")

我这里的版本是10.2.0.5,使用第二种方法不行。只能采取第一种增加内存参数的方法。

[oracle@jingyong1 dbs]$ vi inittest.ora

db_name=test
db_unique_name=_test
control_files= /u01/app/oracle/auxiliary/control01.ctl
db_file_name_convert=(' /u01/app/oracle/oradata/test/',' /u01/app/oracle/auxiliary')
log_file_name_convert=(' /u01/app/oracle/oradata/test/',' /u01/app/oracle/auxiliary')
remote_login_passwordfile=exclusive
compatible = 10.2.0.5.0
db_block_size=8192
sga_target=160M
sga_max_size=160M
pga_aggregate_target=16M

SQL> shutdown immediate
ORA-01507: database not mounted


ORACLE instance shut down.
SQL> startup nomount
ORACLE instance started.

Total System Global Area  167772160 bytes
Fixed Size                  1272624 bytes
Variable Size              58721488 bytes
Database Buffers          104857600 bytes
Redo Buffers                2920448 bytes

[oracle@jingyong1 dbs]$ export ORACLE_SID=test
[oracle@jingyong1 dbs]$ rman target/

Recovery Manager: Release 10.2.0.5.0 - Production on Tue Mar 17 11:00:47 2015

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

connected to target database: test (not mounted)

[oracle@oracle11g admin]$ rman target sys/zzh_2046@test auxiliary sys/system@aux_test catalog rman/rman@jy

Recovery Manager: Release 10.2.0.5.0 - Production on Tue Mar 17 11:01:00 2015

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

connected to target database: TEST (DBID=2168949517)
connected to recovery catalog database
connected to auxiliary database: TEST (not mounted)

通过向参数文件中增加内存参数解决了这个故障。

IBM服务器更换rootvg故障磁盘操作指南

1 Rootvg做镜像
1.1 Rootvg做镜像要求
在安装完操作系统,配完应用后,我们一般要给rootvg做镜像,做rootvg镜像的硬盘必须和rootvg的硬盘空间大小相同,转速相同的同一型号内置SCSI硬盘。可通过下面这些命令来确认:
lsdev -Cc disk 确定主机中有几块硬盘,有几块内置硬盘

# lsdev -Cc disk
[IBMP740-1:root:/]#lsdev -Cc disk
hdisk0      Available 00-00-00 SAS Disk Drive
hdisk1      Available 00-00-00 SAS Disk Drive
hdisk2      Defined   07-00-02 EMC CLARiiON FCP LUNZ Disk
hdisk3      Defined   07-00-02 EMC CLARiiON FCP LUNZ Disk
hdisk4      Defined   05-00-02 EMC CLARiiON FCP LUNZ Disk
hdisk5      Defined   05-00-02 EMC CLARiiON FCP LUNZ Disk
hdisk6      Defined   07-00-02 EMC CLARiiON FCP RAID 5 Disk
hdisk7      Defined   07-00-02 EMC CLARiiON FCP RAID 5 Disk
hdisk8      Defined   07-00-02 EMC CLARiiON FCP RAID 5 Disk
hdisk9      Defined   07-00-02 EMC CLARiiON FCP RAID 5 Disk
hdisk10     Available 05-00-02 EMC CLARiiON FCP RAID 5 Disk
hdisk11     Available 05-00-02 EMC CLARiiON FCP RAID 5 Disk
hdisk12     Available 05-00-02 EMC CLARiiON FCP RAID 5 Disk
hdisk13     Available 05-00-02 EMC CLARiiON FCP RAID 5 Disk
hdisk14     Defined   07-00-02 EMC CLARiiON FCP RAID 5 Disk
hdisk15     Defined   07-00-02 EMC CLARiiON FCP RAID 5 Disk
hdisk16     Available 05-00-02 EMC CLARiiON FCP RAID 5 Disk
hdisk17     Available 05-00-02 EMC CLARiiON FCP RAID 5 Disk
hdisk18     Available 07-00-02 EMC CLARiiON FCP RAID 5 Disk
hdisk19     Available 07-00-02 EMC CLARiiON FCP RAID 5 Disk
hdisk20     Available 07-00-02 EMC CLARiiON FCP RAID 5 Disk
hdisk21     Available 07-00-02 EMC CLARiiON FCP RAID 5 Disk
hdisk22     Available 07-00-02 EMC CLARiiON FCP RAID 5 Disk
hdisk23     Available 07-00-02 EMC CLARiiON FCP RAID 5 Disk
hdiskpower0 Available 05-00-02 PowerPath Device
hdiskpower1 Available 07-00-02 PowerPath Device
hdiskpower2 Available 05-00-02 PowerPath Device

lspv 确定主机中那块内置硬盘没有被VG使用

# lspv
hdisk0          0057908c7251c07a                    rootvg
hdisk1          0057908cea9403a2                    None
hdisk2          005d03fc9859db6c                    datavg
[IBMP740-1:root:/]# lspv
hdisk0          00f7ac3dfb20ed5a                    None
hdisk1          00f7ac3d60694e5e                    rootvg          active
hdisk10         none                                None
hdisk11         none                                None
hdisk12         none                                None
hdisk13         none                                None
hdisk16         none                                None
hdisk17         none                                None
hdisk18         none                                None
hdisk19         none                                None
hdisk20         none                                None
hdisk21         none                                None
hdisk22         none                                None
hdisk23         none                                None

lsattr -El 确定hdisk0与hdisk1硬盘的大小一致

[IBMP740-1:root:/]#lsattr -El hdisk0
PCM             PCM/friend/scsiscsd                        Path Control Module           False
algorithm       fail_over                                  Algorithm                     True
dist_err_pcnt   0                                          Distributed Error Percentage  True
dist_tw_width   50                                         Distributed Error Sample Time True
hcheck_interval 0                                          Health Check Interval         True
hcheck_mode     nonactive                                  Health Check Mode             True
max_coalesce    0x10000                                    Maximum Coalesce Size         True
max_transfer    0x100000                                   Maximum TRANSFER Size         True
pvid            00f7ac3dfb20ed5a0000000000000000           Physical volume identifier    False
queue_depth     16                                         Queue DEPTH                   True
reserve_policy  no_reserve                                 Reserve Policy                True
size_in_mb      300000                                     Size in Megabytes             False
unique_id       2A1135000C50053CA70070BST9300653SS03IBMsas Unique device identifier      False
ww_id           5000c50053ca7007                           World Wide Identifier         False
[IBMP740-1:root:/]#lsattr -El hdisk1
PCM             PCM/friend/scsiscsd                        Path Control Module           False
algorithm       fail_over                                  Algorithm                     True
dist_err_pcnt   0                                          Distributed Error Percentage  True
dist_tw_width   50                                         Distributed Error Sample Time True
hcheck_interval 0                                          Health Check Interval         True
hcheck_mode     nonactive                                  Health Check Mode             True
max_coalesce    0x10000                                    Maximum Coalesce Size         True
max_transfer    0x100000                                   Maximum TRANSFER Size         True
pvid            00f7ac3d60694e5e0000000000000000           Physical volume identifier    False
queue_depth     16                                         Queue DEPTH                   True
reserve_policy  no_reserve                                 Reserve Policy                True
size_in_mb      300000                                     Size in Megabytes             False
unique_id       2A1135000C500594B60570BST9300653SS03IBMsas Unique device identifier      False
ww_id           5000c500594b6057                           World Wide Identifier         False
[IBMP740-1:root:/]#lscfg -vpl hdisk0

lscfg -vpl 确认硬盘的Part number或FRU Number号是否一样,如一样说明硬盘型号一样。

[IBMP740-1:root:/]#lscfg -vpl hdisk0
  hdisk0           U78AA.001.WZSHLUK-P2-D1  SAS Disk Drive (300000 MB)

        Manufacturer................IBM
        Machine Type and Model......ST9300653SS
        FRU Number..................74Y6496
        ROS Level and ID............37343044
        Serial Number...............6XN12EQS
        EC Level....................N23780
        Part Number.................74Y6486
        Device Specific.(Z0)........000006329F001002
        Device Specific.(Z1)........0301740D
        Device Specific.(Z2)........0021
        Device Specific.(Z3)........12136
        Device Specific.(Z4)........
        Device Specific.(Z5)........22
        Device Specific.(Z6)........N23780
        Hardware Location Code......U78AA.001.WZSHLUK-P2-D1


  PLATFORM SPECIFIC

  Name:  disk
    Node:  disk
    Device Type:  block
[IBMP740-1:root:/]#lscfg -vpl hdisk1
  hdisk1           U78AA.001.WZSHLUK-P2-D2  SAS Disk Drive (300000 MB)

        Manufacturer................IBM
        Machine Type and Model......ST9300653SS
        FRU Number..................74Y6496
        ROS Level and ID............37343044
        Serial Number...............6XN1F0V1
        EC Level....................N23780
        Part Number.................74Y6486
        Device Specific.(Z0)........000006329F001002
        Device Specific.(Z1)........0301740D
        Device Specific.(Z2)........0021
        Device Specific.(Z3)........12217
        Device Specific.(Z4)........
        Device Specific.(Z5)........22
        Device Specific.(Z6)........N23780
        Hardware Location Code......U78AA.001.WZSHLUK-P2-D2


  PLATFORM SPECIFIC

  Name:  disk
    Node:  disk
    Device Type:  block由上可知,hdisk0与hdisk1型号、大小一致,可以做rootvg镜像。

#一般基本上除了haview ,netwiew ( Tivoli)的包以外,所有的hacmp的包都要安装。
1.2 配制rootvg镜像
首先将hdisk1硬盘加入到rootvg中

# extendvg rootvg hdisk1
0516-014 linstallpv: The physical volume appears to belong to another
        volume group.
005d027c00004c00
0516-631 extendvg: Warning, all data belonging to physical
        volume hdisk1 will be destroyed.
extendvg: Do you wish to continue? y(es) n(o)? y
# lspv
hdisk0          0057908c7251c07a                    rootvg
hdisk1          0057908cea9403a2                    rootvg
hdisk2          005d03fc9859db6c                    datavg

给rootvg做镜像

# mirrorvg rootvg hdisk1
0516-1124 mirrorvg: Quorum requirement turned off, reboot system for this
        to take effect for rootvg.
0516-1126 mirrorvg: rootvg successfully mirrored, user should perform
        bosboot of system to initialize boot records.  Then, user must modify
        bootlist to include:  hdisk0 hdisk1.

给hdisk0、hdisk1分别做引导分区

# bosboot -ad hdisk0
bosboot: Boot image is 15092 512 byte blocks.
# bosboot -ad hdisk1
bosboot: Boot image is 15092 512 byte blocks.

设定系统的引导顺序为hdisk0、hdisk1

# bootlist -m normal hdisk0 hdisk1
# bootlist -m normal -o
hdisk0 blv=hd5 pathid=0
hdisk1 blv=hd5 pathid=0

设定Quorum为Disable.,这样保证了一旦硬盘坏了一块,rootvg还是能正常启来。

# chvg -Qn rootvg
0516-1804 chvg: The quorum change takes effect immediately.

执行lsvg命令确认rootvg已做镜像,可看到除了lg_dumplv之外所有其它LPs和PPs的对应关系为1对2的关系。

# lsvg -l rootvg
rootvg:
LV NAME             TYPE       LPs     PPs     PVs  LV STATE      MOUNT POINT
hd5                 boot       1       2       2    closed/syncd  N/A
hd6                 paging     33      66      2    open/syncd    N/A
hd8                 jfs2log    1       2       2    open/syncd    N/A
hd4                 jfs2       40      80      2    open/syncd    /
hd2                 jfs2       10      20      2    open/syncd    /usr
hd9var              jfs2       10      20      2    open/syncd    /var
hd3                 jfs2       20      40      2    open/syncd    /tmp
hd1                 jfs2       10      20      2    open/syncd    /home
hd10opt             jfs2       196     392     2    open/syncd    /opt
hd11admin           jfs2       10      20      2    open/syncd    /admin
fwdump              jfs2       3       6       2    open/syncd    /var/adm/ras/platform
lg_dumplv           sysdump    16      16      1    open/syncd    N/A
livedump            jfs2       1       2       2    open/syncd    /var/adm/ras/livedump
fslv00              jfs2       40      80      2    closed/syncd  /u01

2 更换rootvg中的故障盘
这里假设hdisk0硬盘故障,需要更换。
2.1 确定hdisk0硬盘故障
首先执行errpt命令查看错误日志,如果hdisk0损坏的话,会有很多hdisk0的报错。

# errpt -d H
IDENTIFIER TIMESTAMP  T C RESOURCE_NAME  DESCRIPTION
12296806   0312162815 T H sissas0        SAS ERROR
12296806   0312162715 T H sissas0        SAS ERROR
12296806   0311235615 T H sissas0        SAS ERROR
12296806   0311235515 T H sissas0        SAS ERROR
12296806   0310235615 T H sissas0        SAS ERROR
12296806   0310235515 T H sissas0        SAS ERROR
12296806   0309235615 T H sissas0        SAS ERROR
12296806   0309235515 T H sissas0        SAS ERROR
12296806   0308235615 T H sissas0        SAS ERROR
12296806   0308235515 T H sissas0        SAS ERROR
12296806   0307235615 T H sissas0        SAS ERROR
12296806   0307235515 T H sissas0        SAS ERROR
12296806   0306235615 T H sissas0        SAS ERROR
12296806   0306235515 T H sissas0        SAS ERROR
12296806   0305235615 T H sissas0        SAS ERROR
12296806   0305235515 T H sissas0        SAS ERROR
12296806   0304235615 T H sissas0        SAS ERROR
12296806   0304235515 T H sissas0        SAS ERROR
E86653C3   0304054615 P H LVDD           I/O ERROR DETECTED BY LVM
E86653C3   0304054615 P H LVDD           I/O ERROR DETECTED BY LVM
C62E1EB7   0304054615 P H hdisk0         DISK OPERATION ERROR
12296806   0304054615 T H sissas0        SAS ERROR
E86653C3   0304054615 P H LVDD           I/O ERROR DETECTED BY LVM
E86653C3   0304054615 P H LVDD           I/O ERROR DETECTED BY LVM
C62E1EB7   0304054615 P H hdisk0         DISK OPERATION ERROR
C62E1EB7   0304054615 P H hdisk0         DISK OPERATION ERROR
12296806   0304054615 T H sissas0        SAS ERROR
12296806   0304054615 T H sissas0        SAS ERROR
12296806   0304054515 T H sissas0        SAS ERROR
12296806   0304054515 T H sissas0        SAS ERROR
12296806   0304054515 T H sissas0        SAS ERROR
12296806   0304054515 T H sissas0        SAS ERROR
12296806   0304054515 T H sissas0        SAS ERROR
12296806   0304054515 T H sissas0        SAS ERROR
12296806   0304054515 T H sissas0        SAS ERROR
12296806   0304054515 T H sissas0        SAS ERROR
12296806   0304054515 T H sissas0        SAS ERROR
12296806   0304054515 T H sissas0        SAS ERROR
12296806   0304054515 T H sissas0        SAS ERROR
12296806   0304054515 T H sissas0        SAS ERROR
12296806   0304054515 T H sissas0        SAS ERROR
12296806   0304054515 T H sissas0        SAS ERROR
12296806   0304054515 T H sissas0        SAS ERROR
12296806   0304054515 T H sissas0        SAS ERROR
12296806   0304054515 T H sissas0        SAS ERROR
12296806   0304054515 T H sissas0        SAS ERROR
12296806   0304054515 T H sissas0        SAS ERROR
12296806   0304054515 T H sissas0        SAS ERROR
12296806   0304054515 T H sissas0        SAS ERROR
12296806   0304054515 T H sissas0        SAS ERROR
12296806   0304054515 T H sissas0        SAS ERROR
12296806   0304054515 T H sissas0        SAS ERROR
12296806   0304054515 T H sissas0        SAS ERROR
12296806   0304054515 T H sissas0        SAS ERROR
12296806   0304054515 T H sissas0        SAS ERROR
12296806   0304054515 T H sissas0        SAS ERROR
12296806   0304054515 T H sissas0        SAS ERROR
12296806   0304054515 T H sissas0        SAS ERROR
12296806   0304054515 T H sissas0        SAS ERROR
12296806   0304054515 T H sissas0        SAS ERROR
12296806   0304054415 T H sissas0        SAS ERROR
12296806   0304054415 T H sissas0        SAS ERROR
12296806   0304054415 T H sissas0        SAS ERROR
12296806   0304054415 T H sissas0        SAS ERROR
12296806   0304054415 T H sissas0        SAS ERROR
12296806   0304054415 T H sissas0        SAS ERROR
12296806   0304054415 T H sissas0        SAS ERROR
12296806   0304054415 T H sissas0        SAS ERROR
12296806   0304054415 T H sissas0        SAS ERROR
12296806   0304054415 T H sissas0        SAS ERROR
12296806   0304054415 T H sissas0        SAS ERROR
12296806   0304054415 T H sissas0        SAS ERROR
12296806   0304054415 T H sissas0        SAS ERROR
12296806   0304054415 T H sissas0        SAS ERROR
12296806   0304054415 T H sissas0        SAS ERROR
12296806   0304054415 T H sissas0        SAS ERROR
12296806   0304054415 T H sissas0        SAS ERROR
12296806   0304054415 T H sissas0        SAS ERROR
12296806   0304054415 T H sissas0        SAS ERROR
12296806   0304054415 T H sissas0        SAS ERROR
12296806   0304054415 T H sissas0        SAS ERROR
12296806   0304054415 T H sissas0        SAS ERROR
12296806   0304054415 T H sissas0        SAS ERROR
12296806   0304054415 T H sissas0        SAS ERROR
12296806   0304054415 T H sissas0        SAS ERROR
12296806   0304054415 T H sissas0        SAS ERROR
12296806   0304054415 T H sissas0        SAS ERROR
12296806   0304054415 T H sissas0        SAS ERROR
12296806   0304054415 T H sissas0        SAS ERROR
12296806   0304054415 T H sissas0        SAS ERROR
12296806   0304054415 T H sissas0        SAS ERROR
12296806   0304054415 T H sissas0        SAS ERROR

执行lsvg 确认镜像丢失,可看到LPs和PPs的对应关系变为11对应。

# lsvg -l rootvg
rootvg:
LV NAME             TYPE       LPs     PPs     PVs  LV STATE      MOUNT POINT
hd5                 boot       1       1       1    closed/syncd  N/A
hd6                 paging     33      33      1    open/syncd    N/A
hd8                 jfs2log    1       1       1    open/syncd    N/A
hd4                 jfs2       40      40      1    open/syncd    /
hd2                 jfs2       10      10      1    open/syncd    /usr
hd9var              jfs2       10      10      1    open/syncd    /var
hd3                 jfs2       20      20      1    open/syncd    /tmp
hd1                 jfs2       10      10      1    open/syncd    /home
hd10opt             jfs2       196     196     1    open/syncd    /opt
hd11admin           jfs2       10      10      1    open/syncd    /admin
fwdump              jfs2       3       3       1    open/syncd    /var/adm/ras/platform
lg_dumplv           sysdump    8       8       1    open/syncd    N/A
livedump            jfs2       1       1       1    open/syncd    /var/adm/ras/livedump
fslv00              jfs2       40      40      1    closed/syncd  /u01

执行lspv -l hdisk0命令会报错,确认hdisk0硬盘故障。

2.2 更换hdisk0硬盘
首先将hdisk0硬盘从rootvg中unmirror

# unmirrorvg rootvg hdisk0
0516-1246 rmlvcopy: If hd5 is the boot logical volume, please run 'chpv -c '
        as root user to clear the boot record and avoid a potential boot
        off an old boot image that may reside on the disk from which this
        logical volume is moved/removed.
0516-1132 unmirrorvg: Quorum requirement turned on, reboot system for this
        to take effect for rootvg.
0516-1144 unmirrorvg: rootvg successfully unmirrored, user should perform
        bosboot of system to reinitialize boot records.  Then, user must modify
        bootlist to just include:  hdisk1.

执行chpv -c hdisk0命令清除掉boot记录

# chpv -c hdisk0
0301-108 mkboot: Unable to read file blocks. Return code: -1
0516-1248 chpv: mkboot failure

# reducevg rootvg hdisk0
0516-016 ldeletepv: Cannot delete physical volume with allocated
        partitions. Use either migratepv to move the partitions or
        reducevg with the -d option to delete the partitions.
0516-884 reducevg: Unable to remove physical volume hdisk0.

这是因为 lg_dumplv在rootvg缺省情况下没有做镜像的原因,只创建在hdisk0上,现在要修改主dump目录为null(空目录)

# lslv -l lg_dumplv
lg_dumplv:N/A
PV                COPIES        IN BAND       DISTRIBUTION
hdisk0            008:000:000   100%          000:008:000:000:000

# sysdumpdev -P -p /dev/sysdumpnull
primary              /dev/sysdumpnull
secondary            /dev/sysdumpnull
copy directory       /var/adm/ras
forced copy flag     TRUE
always allow dump    FALSE
dump compression     ON
type of dump         traditional

从rootvg中删除hdisk0硬盘

# reducevg -d rootvg hdisk0
0516-914 rmlv: Warning, all data belonging to logical volume
        lg_dumplv on physical volume hdisk0 will be destroyed.
rmlv: Do you wish to continue? y(es) n(o)? yes
rmlv: Logical volume lg_dumplv is removed.

# lsvg -l rootvg
rootvg:
LV NAME             TYPE       LPs     PPs     PVs  LV STATE      MOUNT POINT
hd5                 boot       1       1       1    closed/syncd  N/A
hd6                 paging     33      33      1    open/syncd    N/A
hd8                 jfs2log    1       1       1    open/syncd    N/A
hd4                 jfs2       40      40      1    open/syncd    /
hd2                 jfs2       10      10      1    open/syncd    /usr
hd9var              jfs2       10      10      1    open/syncd    /var
hd3                 jfs2       20      20      1    open/syncd    /tmp
hd1                 jfs2       10      10      1    open/syncd    /home
hd10opt             jfs2       196     196     1    open/syncd    /opt
hd11admin           jfs2       10      10      1    open/syncd    /admin
fwdump              jfs2       3       3       1    open/syncd    /var/adm/ras/platform
livedump            jfs2       1       1       1    open/syncd    /var/adm/ras/livedump
fslv00              jfs2       40      40      1    closed/syncd  /u01

删除hdisk0硬盘

# rmdev -dl hdisk0
hdisk0 deleted
# lspv
hdisk1          00f45bd06cef0cfa                    rootvg          active
hdisk2          none                                None
hdisk3          none                                None
hdisk4          none                                None
hdisk5          none                                None
hdisk6          none                                None
hdisk7          none                                None
hdisk8          none                                None
hdisk9          none                                None
hdisk10         none                                None
hdisk11         none                                None
hdiskpower0     none                                None
hdiskpower1     none                                None
hdiskpower2     none                                None
hdiskpower3     none                                None
hdiskpower4     none                                None
hdisk12         none                                None
hdisk13         none                                None
hdisk14         none                                None
hdisk15         none                                None
hdisk16         none                                None
hdisk17         none                                None
hdiskpower5     none                                None
hdiskpower6     none                                None
hdiskpower7     none                                None
hdisk18         none                                None
hdisk19         none                                None
hdisk20         none                                None
hdisk21         none                                None
hdisk22         none                                None
hdisk23         none                                None
hdiskpower8     none                                None
hdiskpower9     none                                None
hdiskpower10    none                                None

2.3添加新硬盘到rootvg中,并做镜像
拔出hdisk0故障硬盘,插入新硬盘。执行以下操作将新硬盘加入到rootvg中
# cfgmgr -v
查看磁盘是否有pvid如果没有执行chdev -l hdisk0 -a pv=yes

# lspv
hdisk0          none                                None
hdisk1          00f45bd06cef0cfa                    rootvg          active
hdisk2          none                                None
hdisk3          none                                None
hdisk4          none                                None
hdisk5          none                                None
hdisk6          none                                None
hdisk7          none                                None
hdisk8          none                                None
hdisk9          none                                None
hdisk10         none                                None
hdisk11         none                                None
hdiskpower0     none                                None
hdiskpower1     none                                None
hdiskpower2     none                                None
hdiskpower3     none                                None
hdiskpower4     none                                None
hdisk12         none                                None
hdisk13         none                                None
hdisk14         none                                None
hdisk15         none                                None
hdisk16         none                                None
hdisk17         none                                None
hdiskpower5     none                                None
hdiskpower6     none                                None
hdiskpower7     none                                None
hdisk18         none                                None
hdisk19         none                                None
hdisk20         none                                None
hdisk21         none                                None
hdisk22         none                                None
hdisk23         none                                None
hdiskpower8     none                                None
hdiskpower9     none                                None
hdiskpower10    none                                None



# chdev -l hdisk0 -a pv=yes
hdisk0 changed
# lspv
hdisk0          00f45bd0101716a0                    None
hdisk1          00f45bd06cef0cfa                    rootvg          active
hdisk2          none                                None
hdisk3          none                                None
hdisk4          none                                None
hdisk5          none                                None
hdisk6          none                                None
hdisk7          none                                None
hdisk8          none                                None
hdisk9          none                                None
hdisk10         none                                None
hdisk11         none                                None
hdiskpower0     none                                None
hdiskpower1     none                                None
hdiskpower2     none                                None
hdiskpower3     none                                None
hdiskpower4     none                                None
hdisk12         none                                None
hdisk13         none                                None
hdisk14         none                                None
hdisk15         none                                None
hdisk16         none                                None
hdisk17         none                                None
hdiskpower5     none                                None
hdiskpower6     none                                None
hdiskpower7     none                                None
hdisk18         none                                None
hdisk19         none                                None
hdisk20         none                                None
hdisk21         none                                None
hdisk22         none                                None
hdisk23         none                                None
hdiskpower8     none                                None
hdiskpower9     none                                None
hdiskpower10    none                                None

把hdisk0加入到rootvg

# extendvg rootvg hdisk0
# lspv
hdisk0          00f45bd0101716a0                    rootvg          active
hdisk1          00f45bd06cef0cfa                    rootvg          active
hdisk2          none                                None
hdisk3          none                                None
hdisk4          none                                None
hdisk5          none                                None
hdisk6          none                                None
hdisk7          none                                None
hdisk8          none                                None
hdisk9          none                                None
hdisk10         none                                None
hdisk11         none                                None
hdiskpower0     none                                None
hdiskpower1     none                                None
hdiskpower2     none                                None
hdiskpower3     none                                None
hdiskpower4     none                                None
hdisk12         none                                None
hdisk13         none                                None
hdisk14         none                                None
hdisk15         none                                None
hdisk16         none                                None
hdisk17         none                                None
hdiskpower5     none                                None
hdiskpower6     none                                None
hdiskpower7     none                                None
hdisk18         none                                None
hdisk19         none                                None
hdisk20         none                                None
hdisk21         none                                None
hdisk22         none                                None
hdisk23         none                                None
hdiskpower8     none                                None
hdiskpower9     none                                None
hdiskpower10    none                                None

做rootvg镜像

# mirrorvg rootvg hdisk0
0516-306 getlvodm: Unable to find volume group root in the Device
        Configuration Database.
0516-1200 mirrorvg: Failed to mirror the volume group.

创建引导映像

# bosboot -ad hdisk0

bosboot: Boot image is 53276 512 byte blocks.
# bosboot -ad hdisk1

bosboot: Boot image is 53276 512 byte blocks.

改变引导区引导顺序

# bootlist -m normal hdisk0 hdisk1

查看引导顺序

# bootlist -m normal -o
hdisk0 blv=hd5 pathid=0
hdisk1 blv=hd5 pathid=0
# chvg -Qn rootvg
0516-1804 chvg: The quorum change takes effect immediately.

//-Q:确定卷组在丢失其物理卷的限额后,VG是否保持活动;-n:保持活动,默认为:-y。

重新创建dump

# mklv -t sysdump -y lg_dumplv rootvg 16 hdisk0
lg_dumplv

修改主dump device:

# sysdumpdev -Pp /dev/lg_dumplv
primary              /dev/lg_dumplv
secondary            /dev/sysdumpnull
copy directory       /var/adm/ras
forced copy flag     TRUE
always allow dump    FALSE
dump compression     ON
type of dump         traditional
# lsvg -l rootvg
rootvg:
LV NAME             TYPE       LPs     PPs     PVs  LV STATE      MOUNT POINT
hd5                 boot       1       2       2    closed/syncd  N/A
hd6                 paging     33      66      2    open/syncd    N/A
hd8                 jfs2log    1       2       2    open/syncd    N/A
hd4                 jfs2       40      80      2    open/syncd    /
hd2                 jfs2       10      20      2    open/syncd    /usr
hd9var              jfs2       10      20      2    open/syncd    /var
hd3                 jfs2       20      40      2    open/syncd    /tmp
hd1                 jfs2       10      20      2    open/syncd    /home
hd10opt             jfs2       196     392     2    open/syncd    /opt
hd11admin           jfs2       10      20      2    open/syncd    /admin
fwdump              jfs2       3       6       2    open/syncd    /var/adm/ras/platform
lg_dumplv           sysdump    16      16      1    open/syncd    N/A
livedump            jfs2       1       2       2    open/syncd    /var/adm/ras/livedump
fslv00              jfs2       40      80      2    closed/syncd  /u01

时间格式nls_date_format的设置

nls_date_format参数用于设置日期显示格式,设置的方式有多种,不同的方式也会带来不同的结果。参数的设置是有优先级的,日期格式的参数设置也不例外。优先级如下(低到高):初始化参数 < 系统环境变量 < 会话级(session)< 函数
下面来演示参数设置的优先级
1.用初始化参数来设置nls_date_format
检查是否设置了nls_date_format环境变量,从下面的结果可知并没有设置

[oracle@oracle11g ~]$ export nls_date_format
SQL>show parameter nls_date_format

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
nls_date_format                      string

修改参数nls_date_format

SQL> alter system set nls_date_format='yyyy-mm-dd hh24:mi:ss' scope=spfile;

System altered.

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

Total System Global Area  327155712 bytes
Fixed Size                  1273516 bytes
Variable Size             138412372 bytes
Database Buffers          184549376 bytes
Redo Buffers                2920448 bytes
Database mounted.
Database opened.
SQL> show parameter nls_date_format

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
nls_date_format                      string      yyyy-mm-dd hh24:mi:ss

SQL> select sysdate from dual;

SYSDATE
------------
04-FEB-15

在修改参数nls_date_format后,我们查询系统时间并没有以’yyyy-mm-dd hh24:mi:ss’这种格式显式,因为NLS_LANG环境变量同样会影响到nls_date_format参数,只要存在NLS_LANG环境变量,Oracle就会使用环境变量的值(即使nls_date_format),根据上面我们提到的优先级,所以初始化参数文件设置的值会被忽略,但由于环境变量中nls_date_format并没有设置,所以Oracle还是使用了默认的格式。

现在设置NLS_LANG环境变量

[oracle@oracle11g ~]$ export NLS_LANG
[oracle@oracle11g ~]$ sqlplus / as sysdba
SQL*Plus: Release 10.2.0.5.0 - Production on Wed Feb 4 10:00:05 2015

Copyright (c) 1982, 2010, Oracle.  All Rights Reserved.


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

SQL> show parameter nls_date_format

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
nls_date_format                      string      yyyy-mm-dd hh24:mi:ss
SQL> select sysdate from dual;

SYSDATE
-------------------
2015-02-04 10:01:26

从上面的结果可以看到当我们去掉环境变量nls_lang后,查询系统时间就是以初始化参数nls_date_format的格式(yyyy-mm-dd hh24:mi:ss)来显示的

2.我们将参数nls_date_format设置为’yyyy-mm-dd hh24:mi:ss’,将环境变量设置为’yy-mm-dd hh24:mi:ss’来观察它们的优先级

[oracle@oracle11g ~]$ export nls_date_format='yy-mm-dd hh24:mi:ss'
[oracle@oracle11g ~]$ sqlplus / as sysdba

SQL*Plus: Release 10.2.0.5.0 - Production on Wed Feb 4 09:44:07 2015

Copyright (c) 1982, 2010, Oracle.  All Rights Reserved.


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

SQL> show parameter nls_date_format

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
nls_date_format                      string      yyyy-mm-dd hh24:mi:ss
SQL> select sysdate from dual;

SYSDATE
-----------------
15-02-04 09:44:31

可以看到查询系统时间以是环境变量所设置的格式(’yy-mm-dd hh24:mi:ss’)来显示的。这就说明nls_date_format在环境变量中的设置比初始化参数的优先级高。

3.我们将参数nls_date_format设置为’yyyy-mm-dd hh24:mi:ss’,环境变量设置为’yy-mm-dd hh24:mi:ss’,并在会话级将nls_date_format设置为’dd-mm-yy hh24:mi:ss’

[oracle@oracle11g ~]$ export nls_date_format='yy-mm-dd hh24:mi:ss'
[oracle@oracle11g ~]$ sqlplus / as sysdba

SQL*Plus: Release 10.2.0.5.0 - Production on Wed Feb 4 09:44:07 2015

Copyright (c) 1982, 2010, Oracle.  All Rights Reserved.


SQL> alter session set nls_date_format='dd-mm-yy hh24:mi:ss';

Session altered.

SQL> show parameter nls_date_format

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
nls_date_format                      string      yyyy-mm-dd hh24:mi:ss
SQL> select sysdate from dual;

SYSDATE
-----------------
04-02-15 09:50:01

从上面的结果可以看到查询系统时间是以会话级参数nls_date_format的格式(=’dd-mm-yy hh24:mi:ss’)来显示的,这就说明了nls_date_format参数的优先级为:会话级>环境变量>初始化参数

4.我们将参数nls_date_format设置为’yyyy-mm-dd hh24:mi:ss’,环境变量设置为’yy-mm-dd hh24:mi:ss’,并在会话级将nls_date_format设置为’dd-mm-yy hh24:mi:ss’,使用函数来转换日期格式为’mm-dd-yy hh24:mi:ss’

[oracle@oracle11g ~]$ export nls_date_format='yy-mm-dd hh24:mi:ss'
[oracle@oracle11g ~]$ sqlplus / as sysdba

SQL*Plus: Release 10.2.0.5.0 - Production on Wed Feb 4 09:44:07 2015

Copyright (c) 1982, 2010, Oracle.  All Rights Reserved.


SQL> alter session set nls_date_format='dd-mm-yy hh24:mi:ss';

Session altered.

SQL> show parameter nls_date_format

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
nls_date_format                      string      yyyy-mm-dd hh24:mi:ss

SQL> select to_char(sysdate,'mm-dd-yy hh24:mi:ss') from dual;

TO_CHAR(SYSDATE,'
-----------------
02-04-15 10:11:44

从上面的结果可以看到函数的优先级最高,这就证明了日期格式的优先级为:初始化参数 < 系统环境变量 < 会话级(session)< 函数