1 描述
利用rman duplicate同一主机上创建standby database.
2 操作环境
OEL7.2
Oracle database 12.1.0.2.0
DB_NAME=S12102
|
primary |
standby |
parameter |
LOG_ARCHIVE_CONFIG='DG_CONFIG=(S12102,S12102D)' LOG_ARCHIVE_DEST_1='LOCATION=USE_DB_RECOVERY_FILE_DEST VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=S12102' LOG_ARCHIVE_DEST_2='SERVICE=S12102D ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=S12102D' FAL_SERVER=S12102D FAL_CLIENT=S12102 STANDBY_FILE_MANAGEMENT=AUTO |
control_files='/u01/app/product/oradata/S12102D/control01.ctl','/u01/app/product/fast_recovery_area/S12102D/control02.ctl' DB_UNIQUE_NAME='S12102D' LOG_ARCHIVE_CONFIG='DG_CONFIG=(S12102D,S12102)' LOG_ARCHIVE_DEST_1='LOCATION=USE_DB_RECOVERY_FILE_DEST VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=S12102D' LOG_ARCHIVE_DEST_2='SERVICE=S12102 ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=S12102' FAL_SERVER='S12102' FAL_CLIENT='S12102D' DB_FILE_NAME_CONVERT='/u01/app/product/oradata/S12102','/u01/app/product/oradata/S12102D' LOG_FILE_NAME_CONVERT='/u01/app/product/oradata/S12102','/u01/app/product/oradata/S12102D' STANDBY_FILE_MANAGEMENT='AUTO' |
Datafile dire |
/u01/app/product/oradata/S12102 |
/u01/app/product/oradata/S12102D |
3 过程设计
3.1 主库DG配置
3.2 操作系统用户DG环境配置
3.3 listener.ora与tnsnames.ora配置
3.4 rman duplicate
4 详细步骤操作
4.1 主库DG配置
shutdown immediate;
startup mount;
alter database archivelog;
alter database open;
create pfile from spfile;
ALTER DATABASE FORCE LOGGING;
ALTER DATABASE ADD STANDBY LOGFILE ('/u01/app/product/oradata/S12102/sredo01.log') SIZE 50M;
ALTER DATABASE ADD STANDBY LOGFILE ('/u01/app/product/oradata/S12102/sredo02.log') SIZE 50M;
ALTER DATABASE ADD STANDBY LOGFILE ('/u01/app/product/oradata/S12102/sredo03.log') SIZE 50M;
ALTER DATABASE ADD STANDBY LOGFILE ('/u01/app/product/oradata/S12102/sredo04.log') SIZE 50M;
--standby redo是在备库上work的,主库也可以添加,方便日后switchover改maxprotected模式时使用。添加在主库,在创建DataGuard时,备库自然也就有了,比较省事。-- The standby redo log must have at least one more redo log group than the redo log at the redo source database, for each redo thread at the redo source database. At the redo source database, query the V$LOG view to determine how many redo log groups are in the redo log at the redo source database and query the V$THREAD view to determine how many redo threads exist at the redo source database.
alter system set LOG_ARCHIVE_CONFIG='DG_CONFIG=(S12102,S12102D)';
alter system set LOG_ARCHIVE_DEST_1='LOCATION=USE_DB_RECOVERY_FILE_DEST VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=S12102';
alter system set LOG_ARCHIVE_DEST_2='SERVICE=S12102D ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=S12102D' ;
alter system set FAL_SERVER=S12102D;
alter system set FAL_CLIENT=S12102;
alter system set STANDBY_FILE_MANAGEMENT=AUTO;
--此两项需要重启数据库生效
alter system set DB_FILE_NAME_CONVERT='/u01/app/product/oradata/S12102D/','/u01/app/product/oradata/S12102' scope=spfile;
alter system set LOG_FILE_NAME_CONVERT='/u01/app/product/oradata/S12102D/','/u01/app/product/oradata/S12102' scope=spfile;
4.2 操作系统用户DG环境配置
cd $ORACLE_HOME/dbs
cp initS12102.ora initS12102D.ora
cp orapwS12102 orapwS12102D
chmod 775 $TNS_ADMIN
编辑standby db参数文件,创建standby database目录,配置standby系统环境变量略
4.3 listener.ora与tnsnames.ora配置(本环境使用GRID监听)
[grid@localhost 12.1.0.2.0:(+ASM) network ] $ cat listener.ora
# listener.ora Network Configuration File: /u01/app/product/admin/network/listener.ora
# Generated by Oracle configuration tools.
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = S12102)
(ORACLE_HOME = /u01/app/product/database/12.1.0.2.0)
(SID_NAME = S12102)
)
(SID_DESC =
(GLOBAL_DBNAME = S12102D)
(ORACLE_HOME = /u01/app/product/database/12.1.0.2.0)
(SID_NAME = S12102D)
)
)
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
)
(DESCRIPTION =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
)
)
ADR_BASE_LISTENER = /u01/app/product
[grid@localhost 12.1.0.2.0:(+ASM) network ] $ cat tnsnames.ora
# tnsnames.ora Network Configuration File: /u01/app/product/admin/network/tnsnames.ora
# Generated by Oracle configuration tools.
S12102D =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = S12102D)
)
)
S12102 =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = S12102)
)
)
4.4 rman duplicate
--备库启到nomount状态略
rman target sys/oracle@S12102 auxiliary sys/oracle@S12102D
startup clone nomount;
run{
duplicate target database for standby from active database nofilenamecheck
SPFILE
set control_files='/u01/app/product/oradata/S12102D/control01.ctl','/u01/app/product/fast_recovery_area/S12102D/control02.ctl'
set DB_UNIQUE_NAME='S12102D'
set LOG_ARCHIVE_CONFIG='DG_CONFIG=(S12102D,S12102)'
set LOG_ARCHIVE_DEST_1='LOCATION=USE_DB_RECOVERY_FILE_DEST VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=S12102D'
set LOG_ARCHIVE_DEST_2='SERVICE=S12102 ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=S12102'
set FAL_SERVER='S12102'
set FAL_CLIENT='S12102D'
set DB_FILE_NAME_CONVERT='/u01/app/product/oradata/S12102','/u01/app/product/oradata/S12102D'
set LOG_FILE_NAME_CONVERT='/u01/app/product/oradata/S12102','/u01/app/product/oradata/S12102D'
set STANDBY_FILE_MANAGEMENT='AUTO';
}
下面是duplicate过程详细输出
[oracle@localhost 12.1.0.2.0:(S12102) bin ] $ rman target sys/oracle@S12102 auxiliary sys/oracle@S12102D
Recovery Manager: Release 12.1.0.2.0 - Production on Fri Jun 1 17:35:24 2018
Copyright (c) 1982, 2014, Oracle and/or its affiliates. All rights reserved.
connected to target database: S12102 (DBID=2197238228)
connected to auxiliary database (not started)
RMAN> startup clone nomount;
Oracle instance started
Total System Global Area 3070230528 bytes
Fixed Size 2929112 bytes
Variable Size 754978344 bytes
Database Buffers 2298478592 bytes
Redo Buffers 13844480 bytes
RMAN> run{
duplicate target database for standby from active database nofilenamecheck
SPFILE
set control_files='/u01/app/product/oradata/S12102D/control01.ctl','/u01/app/product/fast_recovery_area/S12102D/control02.ctl'
set DB_UNIQUE_NAME='S12102D'
set LOG_ARCHI2> 3> 4> 5> 6> VE_CONFIG='DG_CONFIG=(S12102D,S12102)'
set LOG_ARCHIVE_DEST_1='LOCATION=USE_DB_RECOVERY_FILE_DEST VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=S12102D'
set LOG_ARCHIVE_DEST_2='SERVICE=S12102 ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NA7> 8> ME=S12102'
set FAL_SERVER='S12102'
set FAL_CLIENT='S12102D'
set DB_FILE_NAME_CONVERT='/u01/app/product/oradata/S12102','/u01/app/product/oradata/S12102D'
set LOG_FILE_NAME_CONVERT='/u01/app/product/oradata/S12102','/u01/app/product/oradata/S12102D'
set STA9> 10> 11> 12> 13> NDBY_FILE_MANAGEMENT='AUTO';
}
14>
Starting Duplicate Db at 01-JUN-2018 17:36:46
using target database control file instead of recovery catalog
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=240 device type=DISK
contents of Memory Script:
{
backup as copy reuse
targetfile '/u01/app/product/database/12.1.0.2.0/dbs/orapwS12102' auxiliary format
'/u01/app/product/database/12.1.0.2.0/dbs/orapwS12102D' ;
restore clone from service 'S12102' spfile to
'/u01/app/product/database/12.1.0.2.0/dbs/spfileS12102D.ora';
sql clone "alter system set spfile= ''/u01/app/product/database/12.1.0.2.0/dbs/spfileS12102D.ora''";
}
executing Memory Script
Starting backup at 01-JUN-2018 17:36:47
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=37 device type=DISK
Finished backup at 01-JUN-2018 17:36:49
Starting restore at 01-JUN-2018 17:36:49
using channel ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using network backup set from service S12102
channel ORA_AUX_DISK_1: restoring SPFILE
output file name=/u01/app/product/database/12.1.0.2.0/dbs/spfileS12102D.ora
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
Finished restore at 01-JUN-2018 17:36:50
sql statement: alter system set spfile= ''/u01/app/product/database/12.1.0.2.0/dbs/spfileS12102D.ora''
contents of Memory Script:
{
sql clone "alter system set control_files =
''/u01/app/product/oradata/S12102D/control01.ctl'', ''/u01/app/product/fast_recovery_area/S12102D/control02.ctl'' comment=
'''' scope=spfile";
sql clone "alter system set db_unique_name =
''S12102D'' comment=
'''' scope=spfile";
sql clone "alter system set LOG_ARCHIVE_CONFIG =
''DG_CONFIG=(S12102D,S12102)'' comment=
'''' scope=spfile";
sql clone "alter system set LOG_ARCHIVE_DEST_1 =
''LOCATION=USE_DB_RECOVERY_FILE_DEST VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=S12102D'' comment=
'''' scope=spfile";
sql clone "alter system set LOG_ARCHIVE_DEST_2 =
''SERVICE=S12102 ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=S12102'' comment=
'''' scope=spfile";
sql clone "alter system set FAL_SERVER =
''S12102'' comment=
'''' scope=spfile";
sql clone "alter system set FAL_CLIENT =
''S12102D'' comment=
'''' scope=spfile";
sql clone "alter system set db_file_name_convert =
''/u01/app/product/oradata/S12102'', ''/u01/app/product/oradata/S12102D'' comment=
'''' scope=spfile";
sql clone "alter system set LOG_FILE_NAME_CONVERT =
''/u01/app/product/oradata/S12102'', ''/u01/app/product/oradata/S12102D'' comment=
'''' scope=spfile";
sql clone "alter system set STANDBY_FILE_MANAGEMENT =
''AUTO'' comment=
'''' scope=spfile";
shutdown clone immediate;
startup clone nomount;
}
executing Memory Script
sql statement: alter system set control_files = ''/u01/app/product/oradata/S12102D/control01.ctl'', ''/u01/app/product/fast_recovery_area/S12102D/control02.ctl'' comment= '''' scope=spfile
sql statement: alter system set db_unique_name = ''S12102D'' comment= '''' scope=spfile
sql statement: alter system set LOG_ARCHIVE_CONFIG = ''DG_CONFIG=(S12102D,S12102)'' comment= '''' scope=spfile
sql statement: alter system set LOG_ARCHIVE_DEST_1 = ''LOCATION=USE_DB_RECOVERY_FILE_DEST VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=S12102D'' comment= '''' scope=spfile
sql statement: alter system set LOG_ARCHIVE_DEST_2 = ''SERVICE=S12102 ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=S12102'' comment= '''' scope=spfile
sql statement: alter system set FAL_SERVER = ''S12102'' comment= '''' scope=spfile
sql statement: alter system set FAL_CLIENT = ''S12102D'' comment= '''' scope=spfile
sql statement: alter system set db_file_name_convert = ''/u01/app/product/oradata/S12102'', ''/u01/app/product/oradata/S12102D'' comment= '''' scope=spfile
sql statement: alter system set LOG_FILE_NAME_CONVERT = ''/u01/app/product/oradata/S12102'', ''/u01/app/product/oradata/S12102D'' comment= '''' scope=spfile
sql statement: alter system set STANDBY_FILE_MANAGEMENT = ''AUTO'' comment= '''' scope=spfile
Oracle instance shut down
connected to auxiliary database (not started)
Oracle instance started
Total System Global Area 3070230528 bytes
Fixed Size 2929112 bytes
Variable Size 754978344 bytes
Database Buffers 2298478592 bytes
Redo Buffers 13844480 bytes
contents of Memory Script:
{
restore clone from service 'S12102' standby controlfile;
}
executing Memory Script
Starting restore at 01-JUN-2018 17:37:39
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=12 device type=DISK
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using network backup set from service S12102
channel ORA_AUX_DISK_1: restoring control file
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:04
output file name=/u01/app/product/oradata/S12102D/control01.ctl
output file name=/u01/app/product/fast_recovery_area/S12102D/control02.ctl
Finished restore at 01-JUN-2018 17:37:44
contents of Memory Script:
{
sql clone 'alter database mount standby database';
}
executing Memory Script
sql statement: alter database mount standby database
contents of Memory Script:
{
set newname for tempfile 1 to
"/u01/app/product/oradata/S12102D/temp01.dbf";
switch clone tempfile all;
set newname for datafile 1 to
"/u01/app/product/oradata/S12102D/system01.dbf";
set newname for datafile 3 to
"/u01/app/product/oradata/S12102D/sysaux01.dbf";
set newname for datafile 4 to
"/u01/app/product/oradata/S12102D/undotbs01.dbf";
set newname for datafile 5 to
"/u01/app/product/oradata/S12102D/example01.dbf";
set newname for datafile 6 to
"/u01/app/product/oradata/S12102D/users01.dbf";
restore
from service 'S12102' clone database
;
sql 'alter system archive log current';
}
executing Memory Script
executing command: SET NEWNAME
renamed tempfile 1 to /u01/app/product/oradata/S12102D/temp01.dbf in control file
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
Starting restore at 01-JUN-2018 17:37:50
using channel ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using network backup set from service S12102
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00001 to /u01/app/product/oradata/S12102D/system01.dbf
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:36
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using network backup set from service S12102
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00003 to /u01/app/product/oradata/S12102D/sysaux01.dbf
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:35
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using network backup set from service S12102
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00004 to /u01/app/product/oradata/S12102D/undotbs01.dbf
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:16
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using network backup set from service S12102
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00005 to /u01/app/product/oradata/S12102D/example01.dbf
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:01:06
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using network backup set from service S12102
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00006 to /u01/app/product/oradata/S12102D/users01.dbf
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:02
Finished restore at 01-JUN-2018 17:40:25
sql statement: alter system archive log current
contents of Memory Script:
{
switch clone datafile all;
}
executing Memory Script
datafile 1 switched to datafile copy
input datafile copy RECID=1 STAMP=977679627 file name=/u01/app/product/oradata/S12102D/system01.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=2 STAMP=977679627 file name=/u01/app/product/oradata/S12102D/sysaux01.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=3 STAMP=977679627 file name=/u01/app/product/oradata/S12102D/undotbs01.dbf
datafile 5 switched to datafile copy
input datafile copy RECID=4 STAMP=977679627 file name=/u01/app/product/oradata/S12102D/example01.dbf
datafile 6 switched to datafile copy
input datafile copy RECID=5 STAMP=977679627 file name=/u01/app/product/oradata/S12102D/users01.dbf
Finished Duplicate Db at 01-JUN-2018 17:40:46
RMAN>
5 个人总结
当监听由gird用户启动时,注意$TNS_ADMIN目录权限应为775。
6 资料参考引用
https://docs.oracle.com/database/121/SBYDB/rcmbackp.htm#SBYDB4987