使用RMAN DUPLICATE...FROM ACTIVE DATABASE命令來建立DataGuard物理備庫
環境:
database_name:beijing
database_version:11.2.0.2.0
primary:
IP:10.0.2.118
hostname:beijing
oracle_sid:beijing
standby:
IP:10.0.2.112
hostname:shanghai
oracle_sid:shanghai
一、準備主資料庫:
1、確保主資料庫處於歸檔模式:
SQL> select log_mode from v$database;
LOG_MODE
------------
ARCHIVELOG
2、開啟force logging:
SQL> alter database force logging;
Database altered.
3、建立standby redologs:
SQL> col file_name for a50
SQL> select lf.group#,member as file_name,bytes/1024/1024 as size_MB from v$logfile lf,v$log l where lf.group#=l.group# order by group#;
GROUP# FILE_NAME SIZE_MB
---------- -------------------------------------------------- ----------
1 /u01/app/oracle/oradata/beijing/redo01.log 50
2 /u01/app/oracle/oradata/beijing/redo02.log 50
3 /u01/app/oracle/oradata/beijing/redo03.log 50
注意:建立的standby redo大小需要和主庫的redo大小保持一致
SQL> alter database add standby logfile group 4 ('/u01/app/oracle/oradata/beijing/stby04.log') size 50m;
Database altered.
SQL> alter database add standby logfile group 5 ('/u01/app/oracle/oradata/beijing/stby05.log') size 50m;
Database altered.
SQL> alter database add standby logfile group 6 ('/u01/app/oracle/oradata/beijing/stby06.log') size 50m;
Database altered.
SQL> alter database add standby logfile group 7 ('/u01/app/oracle/oradata/beijing/stby07.log') size 50m;
Database altered.
SQL> select type,member from v$logfile;
TYPE MEMBER
------- --------------------------------------------------
ONLINE /u01/app/oracle/oradata/beijing/redo03.log
ONLINE /u01/app/oracle/oradata/beijing/redo02.log
ONLINE /u01/app/oracle/oradata/beijing/redo01.log
STANDBY /u01/app/oracle/oradata/beijing/stby04.log
STANDBY /u01/app/oracle/oradata/beijing/stby05.log
STANDBY /u01/app/oracle/oradata/beijing/stby06.log
STANDBY /u01/app/oracle/oradata/beijing/stby07.log
7 rows selected.
4、修改主資料庫的初始化引數:
SQL> alter system set log_archive_config='DG_CONFIG=(beijing,shanghai)';
System altered.
SQL> alter system set log_archive_dest_1='location=/archivelog/ valid_for=(ALL_LOGFILES,ALL_ROLES) db_unique_name=beijing';
System altered.
SQL> alter system set log_archive_dest_2='SERVICE=shanghai lgwr async valid_for=(ONLINE_LOGFILES,PRIMARY_ROLE) db_unique_name=shanghai';
System altered.
SQL> alter system set log_archive_dest_state_1=enable;
System altered.
SQL> alter system set fal_server=shanghai;
System altered.
SQL> alter system set fal_client=beijing;
System altered.
SQL> alter system set db_file_name_convert='/u01/app/oracle/oradata/shanghai/','/u01/app/oracle/oradata/beijing/' scope=spfile;
System altered.
SQL> alter system set log_file_name_convert='/u01/app/oracle/oradata/shanghai/','/u01/app/oracle/oradata/beijing/' scope=spfile;
System altered.
二、配置網路:
1、在備庫上配置靜態監聽:
[oracle@shanghai ~]$ cd $ORACLE_HOME/network/admin
[oracle@shanghai admin]$ vi listener.ora
[oracle@shanghai admin]$ cat listener.ora
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = shanghai)
(ORACLE_HOME = /u01/app/oracle/product/11.2/db_1)
(SID_NAME = shanghai)
)
)
LISTENER =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = shanghai>)(PORT = 1521))
)
2、在主庫和備庫上都編輯tnsnames.ora檔案:
[oracle@beijing admin]$ cat tnsnames.ora
beijing =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = beijing)(PORT = 1521))
)
(CONNECT_DATA = (SERVICE_NAME = beijing))
)
shanghai =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = shanghai)(PORT = 1521))
)
(CONNECT_DATA = (SERVICE_NAME = shanghai))
)
檢查網路配置:
[oracle@beijing admin]$ tnsping shanghai
[oracle@shanghai admin]$ tnsping beijing
三、建立備用資料庫:
1、複製密碼檔案:
主資料庫和備資料庫的密碼必須相同,所以做好的辦法就是複製密碼檔案:
[oracle@beijing dbs]$ scp orapwbeijing oracle@shanghai:/u01/app/oracle/product/11.2/db_1/dbs/orapwshanghai
[oracle@shanghai dbs]$ pwd
/u01/app/oracle/product/11.2/db_1/dbs
[oracle@shanghai dbs]$ ls
hc_DBUA0.dat init.ora orapwshanghai
2、在備庫上建立引數檔案:
只需要一個引數db_name就行:
如下所示:
[oracle@shanghai dbs]$ cat initshanghai.ora
DB_NAME=beijing
DB_UNIQUE_NAME=shanghai
DB_BLOCK_SIZE=8192
3、在備庫上建立相應的目錄:
[oracle@shanghai ~]$ cd $ORACLE_BASE
[oracle@shanghai oracle]$ mkdir -p oradata/shanghai
[oracle@shanghai oracle]$ mkdir -p diag/rdbms/shanghai/shanghai/trace
[oracle@shanghai oracle]$ mkdir -p diag/rdbms/shanghai/shanghai/cdump
[oracle@shanghai oracle]$ mkdir -p admin/shanghai/adump
建立歸檔日誌目錄:
[root@shanghai ~]# cd /
[root@shanghai /]# mkdir archivelog
[root@shanghai /]# chown -R oracle:oinstall /archivelog
4、啟動備庫例項:
[oracle@shanghai ~]$ export ORACLE_SID=shanghai
[oracle@shanghai ~]$ sqlplus / as sysdba;
SQL> startup nomount pfile=$ORACLE_HOME/dbs/initshanghai.ora
ORACLE instance started.
Total System Global Area 217157632 bytes
Fixed Size 2225064 bytes
Variable Size 159386712 bytes
Database Buffers 50331648 bytes
Redo Buffers 5214208 bytes
5、確認可以以sysdba許可權登入
[oracle@shanghai ~]$ sqlplus /nolog
SQL*Plus: Release 11.2.0.2.0 Production on Sun Dec 23 16:07:18 2012
Copyright (c) 1982, 2010, Oracle. All rights reserved.
SQL> conn sys/qweasd@shanghai as sysdba;
Connected.
SQL> conn sys/qweasd@beijing as sysdba;
Connected.
注意:如果遇到如下錯誤,則重啟監聽再試:
SQL> conn sys/qweasd@shanghai as sysdba;
ERROR:
ORA-12528: TNS:listener: all appropriate instances are blocking new connections
6、在主庫上執行rman duplicate命令:
[oracle@beijing ~]$ rman target sys/qweasd@beijing auxiliary sys/qweasd@shanghai
Recovery Manager: Release 11.2.0.2.0 - Production on Sun Dec 23 16:29:21 2012
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
connected to target database: BEIJING (DBID=767262686)
connected to auxiliary database (not started)
RMAN> run {
allocate channel prmy1 type disk;
allocate channel prmy2 type disk;
allocate channel prmy3 type disk;
allocate channel prmy4 type disk;
allocate auxiliary channel stby type disk;
duplicate target database for standby from active database
spfile
parameter_value_convert 'beijing','shanghai'
set db_unique_name='shanghai'
set db_file_name_convert='/beijing/','/shanghai/'
set log_file_name_convert='/beijing/','/shanghai/'
set control_files='/u01/app/oracle/oradata/shanghai/control01.ctl'
set log_archive_max_processes='5'
set fal_client='shanghai'
set fal_server='beijing'
set standby_file_management='AUTO'
set log_archive_config='dg_config=(beijing,shanghai)'
set log_archive_dest_2='service=beijing ASYNC valid_for=(ONLINE_LOGFILE,PRIMARY_ROLE) db_unique_name=beijing'
;
}
過程:
allocated channel: prmy1
channel prmy1: SID=961 device type=DISK
allocated channel: prmy2
channel prmy2: SID=1152 device type=DISK
allocated channel: prmy3
channel prmy3: SID=1344 device type=DISK
allocated channel: prmy4
channel prmy4: SID=6 device type=DISK
allocated channel: stby
channel stby: SID=91 device type=DISK
Starting Duplicate Db at 23-DEC-12
contents of Memory Script.:
{
backup as copy reuse
targetfile '/u01/app/oracle/product/11.2/db_1/dbs/orapwbeijing' auxiliary format
'/u01/app/oracle/product/11.2/db_1/dbs/orapwshanghai' targetfile
'/u01/app/oracle/product/11.2/db_1/dbs/spfilebeijing.ora' auxiliary format
'/u01/app/oracle/product/11.2/db_1/dbs/spfileshanghai.ora' ;
sql clone "alter system set spfile= ''/u01/app/oracle/product/11.2/db_1/dbs/spfileshanghai.ora''";
}
executing Memory Script
Starting backup at 23-DEC-12
Finished backup at 23-DEC-12
sql statement: alter system set spfile= ''/u01/app/oracle/product/11.2/db_1/dbs/spfileshanghai.ora''
contents of Memory Script.:
{
sql clone "alter system set audit_file_dest = ''/u01/app/oracle/admin/shanghai/adump'' comment='''' scope=spfile";
sql clone "alter system set dispatchers = ''(PROTOCOL=TCP) (SERVICE=shanghaiXDB)'' comment='''' scope=spfile";
sql clone "alter system set log_archive_dest_1 = ''location=/archivelog/ valid_for=(ALL_LOGFILES,ALL_ROLES) db_unique_name=shanghai'' comment='''' scope=spfile";
sql clone "alter system set db_unique_name = ''shanghai'' comment='''' scope=spfile";
sql clone "alter system set db_file_name_convert = ''/beijing/'', ''/shanghai/'' comment='''' scope=spfile";
sql clone "alter system set log_file_name_convert = ''/beijing/'', ''/shanghai/'' comment='''' scope=spfile";
sql clone "alter system set control_files = ''/u01/app/oracle/oradata/control01.ctl'' comment='''' scope=spfile";
sql clone "alter system set log_archive_max_processes = 5 comment='''' scope=spfile";
sql clone "alter system set fal_client = ''shanghai'' comment='''' scope=spfile";
sql clone "alter system set fal_server = ''beijing'' comment='''' scope=spfile";
sql clone "alter system set standby_file_management = ''AUTO'' comment='''' scope=spfile";
sql clone "alter system set log_archive_config = ''dg_config=(chicago,boston)'' comment='''' scope=spfile";
sql clone "alter system set log_archive_dest_2 = ''service=beijing ASYNC valid_for=(ONLINE_LOGFILE,PRIMARY_ROLE) db_unique_name=beijing'' comment=''''
scope=spfile";
shutdown clone immediate;
startup clone nomount;
}
executing Memory Script
sql statement: alter system set audit_file_dest = ''/u01/app/oracle/admin/shanghai/adump'' comment= '''' scope=spfile
sql statement: alter system set dispatchers = ''(PROTOCOL=TCP) (SERVICE=shanghaiXDB)'' comment= '''' scope=spfile
sql statement: alter system set log_archive_dest_1 = ''location=/archivelog/ valid_for=(ALL_LOGFILES,ALL_ROLES) db_unique_name=shanghai'' comment= '''' scope=spfile
sql statement: alter system set db_unique_name = ''shanghai'' comment= '''' scope=spfile
sql statement: alter system set db_file_name_convert = ''/beijing/'', ''/shanghai/'' comment= '''' scope=spfile
sql statement: alter system set log_file_name_convert = ''/beijing/'', ''/shanghai/'' comment= '''' scope=spfile
sql statement: alter system set control_files = ''/u01/app/oracle/oradata/control01.ctl'' comment= '''' scope=spfile
sql statement: alter system set log_archive_max_processes = 5 comment= '''' scope=spfile
sql statement: alter system set fal_client = ''shanghai'' comment= '''' scope=spfile
sql statement: alter system set fal_server = ''beijing'' comment= '''' scope=spfile
sql statement: alter system set standby_file_management = ''AUTO'' comment= '''' scope=spfile
sql statement: alter system set log_archive_config = ''dg_config=(chicago,boston)'' comment= '''' scope=spfile
sql statement: alter system set log_archive_dest_2 = ''service=beijing ASYNC valid_for=(ONLINE_LOGFILE,PRIMARY_ROLE) db_unique_name=beijing'' comment= ''''
scope=spfile
Oracle instance shut down
connected to auxiliary database (not started)
Oracle instance started
Total System Global Area 839282688 bytes
Fixed Size 2231128 bytes
Variable Size 574620840 bytes
Database Buffers 255852544 bytes
Redo Buffers 6578176 bytes
allocated channel: stby
channel stby: SID=958 device type=DISK
contents of Memory Script.:
{
backup as copy current controlfile for standby auxiliary format '/u01/app/oracle/oradata/control01.ctl';
}
executing Memory Script
Starting backup at 23-DEC-12
channel prmy1: starting datafile copy
copying standby control file
output file name=/u01/app/oracle/product/11.2/db_1/dbs/snapcf_beijing.f tag=TAG20121223T163128 RECID=2 STAMP=802801888
channel prmy1: datafile copy complete, elapsed time: 00:00:01
Finished backup at 23-DEC-12
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/oracle/oradata/shanghai/temp01.dbf";
switch clone tempfile all;
set newname for datafile 1 to "/u01/app/oracle/oradata/shanghai/system01.dbf";
set newname for datafile 2 to "/u01/app/oracle/oradata/shanghai/sysaux01.dbf";
set newname for datafile 3 to "/u01/app/oracle/oradata/shanghai/undotbs01.dbf";
set newname for datafile 4 to "/u01/app/oracle/oradata/shanghai/users01.dbf";
set newname for datafile 5 to "/u01/app/oracle/oradata/shanghai/example01.dbf";
backup as copy reuse
datafile 1 auxiliary format "/u01/app/oracle/oradata/shanghai/system01.dbf"
datafile 2 auxiliary format "/u01/app/oracle/oradata/shanghai/sysaux01.dbf"
datafile 3 auxiliary format "/u01/app/oracle/oradata/shanghai/undotbs01.dbf"
datafile 4 auxiliary format "/u01/app/oracle/oradata/shanghai/users01.dbf"
datafile 5 auxiliary format "/u01/app/oracle/oradata/shanghai/example01.dbf" ;
sql 'alter system archive log current';
}
executing Memory Script
executing command: SET NEWNAME
renamed tempfile 1 to /u01/app/oracle/oradata/shanghai/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 backup at 23-DEC-12
channel prmy1: starting datafile copy
input datafile file number=00001 name=/u01/app/oracle/oradata/beijing/system01.dbf
channel prmy2: starting datafile copy
input datafile file number=00002 name=/u01/app/oracle/oradata/beijing/sysaux01.dbf
channel prmy3: starting datafile copy
input datafile file number=00005 name=/u01/app/oracle/oradata/beijing/example01.dbf
channel prmy4: starting datafile copy
input datafile file number=00003 name=/u01/app/oracle/oradata/beijing/undotbs01.dbf
output file name=/u01/app/oracle/oradata/shanghai/undotbs01.dbf tag=TAG20121223T163134
channel prmy4: datafile copy complete, elapsed time: 00:00:07
channel prmy4: starting datafile copy
input datafile file number=00004 name=/u01/app/oracle/oradata/beijing/users01.dbf
output file name=/u01/app/oracle/oradata/shanghai/example01.dbf tag=TAG20121223T163134
channel prmy3: datafile copy complete, elapsed time: 00:00:09
output file name=/u01/app/oracle/oradata/shanghai/users01.dbf tag=TAG20121223T163134
channel prmy4: datafile copy complete, elapsed time: 00:00:01
output file name=/u01/app/oracle/oradata/shanghai/system01.dbf tag=TAG20121223T163134
channel prmy1: datafile copy complete, elapsed time: 00:00:15
output file name=/u01/app/oracle/oradata/shanghai/sysaux01.dbf tag=TAG20121223T163134
channel prmy2: datafile copy complete, elapsed time: 00:00:15
Finished backup at 23-DEC-12
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=2 STAMP=802801851 file name=/u01/app/oracle/oradata/shanghai/system01.dbf
datafile 2 switched to datafile copy
input datafile copy RECID=3 STAMP=802801851 file name=/u01/app/oracle/oradata/shanghai/sysaux01.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=4 STAMP=802801851 file name=/u01/app/oracle/oradata/shanghai/undotbs01.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=5 STAMP=802801851 file name=/u01/app/oracle/oradata/shanghai/users01.dbf
datafile 5 switched to datafile copy
input datafile copy RECID=6 STAMP=802801851 file name=/u01/app/oracle/oradata/shanghai/example01.dbf
Finished Duplicate Db at 23-DEC-12
released channel: prmy1
released channel: prmy2
released channel: prmy3
released channel: prmy4
released channel: stby
複製結束。
四、連線到備庫啟動 MRP (Managed Recovery Process)
[oracle@shanghai ~]$ sqlplus / as sysdba;
SQL> alter database recover managed standby database disconnect;
Database altered.
如果需要啟用實時應用,則應該:
SQL> alter database recover managed standby database using current logfile disconnect;
五、如果有Active Dataguard (ADG)的license,可以以read only模式開啟備庫,並開啟恢復:
[oracle@shanghai ~]$ sqlplus / as sysdba;
SQL> alter database recover managed standby database cancel;
SQL> alter database open;
SQL> alter database recover managed standby database disconnect;
或者啟用實時應用:
SQL> alter database recover managed standby database using current logfile disconnect;
database_name:beijing
database_version:11.2.0.2.0
primary:
IP:10.0.2.118
hostname:beijing
oracle_sid:beijing
standby:
IP:10.0.2.112
hostname:shanghai
oracle_sid:shanghai
一、準備主資料庫:
1、確保主資料庫處於歸檔模式:
SQL> select log_mode from v$database;
LOG_MODE
------------
ARCHIVELOG
2、開啟force logging:
SQL> alter database force logging;
Database altered.
3、建立standby redologs:
SQL> col file_name for a50
SQL> select lf.group#,member as file_name,bytes/1024/1024 as size_MB from v$logfile lf,v$log l where lf.group#=l.group# order by group#;
GROUP# FILE_NAME SIZE_MB
---------- -------------------------------------------------- ----------
1 /u01/app/oracle/oradata/beijing/redo01.log 50
2 /u01/app/oracle/oradata/beijing/redo02.log 50
3 /u01/app/oracle/oradata/beijing/redo03.log 50
注意:建立的standby redo大小需要和主庫的redo大小保持一致
SQL> alter database add standby logfile group 4 ('/u01/app/oracle/oradata/beijing/stby04.log') size 50m;
Database altered.
SQL> alter database add standby logfile group 5 ('/u01/app/oracle/oradata/beijing/stby05.log') size 50m;
Database altered.
SQL> alter database add standby logfile group 6 ('/u01/app/oracle/oradata/beijing/stby06.log') size 50m;
Database altered.
SQL> alter database add standby logfile group 7 ('/u01/app/oracle/oradata/beijing/stby07.log') size 50m;
Database altered.
SQL> select type,member from v$logfile;
TYPE MEMBER
------- --------------------------------------------------
ONLINE /u01/app/oracle/oradata/beijing/redo03.log
ONLINE /u01/app/oracle/oradata/beijing/redo02.log
ONLINE /u01/app/oracle/oradata/beijing/redo01.log
STANDBY /u01/app/oracle/oradata/beijing/stby04.log
STANDBY /u01/app/oracle/oradata/beijing/stby05.log
STANDBY /u01/app/oracle/oradata/beijing/stby06.log
STANDBY /u01/app/oracle/oradata/beijing/stby07.log
7 rows selected.
4、修改主資料庫的初始化引數:
SQL> alter system set log_archive_config='DG_CONFIG=(beijing,shanghai)';
System altered.
SQL> alter system set log_archive_dest_1='location=/archivelog/ valid_for=(ALL_LOGFILES,ALL_ROLES) db_unique_name=beijing';
System altered.
SQL> alter system set log_archive_dest_2='SERVICE=shanghai lgwr async valid_for=(ONLINE_LOGFILES,PRIMARY_ROLE) db_unique_name=shanghai';
System altered.
SQL> alter system set log_archive_dest_state_1=enable;
System altered.
SQL> alter system set fal_server=shanghai;
System altered.
SQL> alter system set fal_client=beijing;
System altered.
SQL> alter system set db_file_name_convert='/u01/app/oracle/oradata/shanghai/','/u01/app/oracle/oradata/beijing/' scope=spfile;
System altered.
SQL> alter system set log_file_name_convert='/u01/app/oracle/oradata/shanghai/','/u01/app/oracle/oradata/beijing/' scope=spfile;
System altered.
二、配置網路:
1、在備庫上配置靜態監聽:
[oracle@shanghai ~]$ cd $ORACLE_HOME/network/admin
[oracle@shanghai admin]$ vi listener.ora
[oracle@shanghai admin]$ cat listener.ora
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = shanghai)
(ORACLE_HOME = /u01/app/oracle/product/11.2/db_1)
(SID_NAME = shanghai)
)
)
LISTENER =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = shanghai>)(PORT = 1521))
)
2、在主庫和備庫上都編輯tnsnames.ora檔案:
[oracle@beijing admin]$ cat tnsnames.ora
beijing =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = beijing)(PORT = 1521))
)
(CONNECT_DATA = (SERVICE_NAME = beijing))
)
shanghai =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = shanghai)(PORT = 1521))
)
(CONNECT_DATA = (SERVICE_NAME = shanghai))
)
檢查網路配置:
[oracle@beijing admin]$ tnsping shanghai
[oracle@shanghai admin]$ tnsping beijing
三、建立備用資料庫:
1、複製密碼檔案:
主資料庫和備資料庫的密碼必須相同,所以做好的辦法就是複製密碼檔案:
[oracle@beijing dbs]$ scp orapwbeijing oracle@shanghai:/u01/app/oracle/product/11.2/db_1/dbs/orapwshanghai
[oracle@shanghai dbs]$ pwd
/u01/app/oracle/product/11.2/db_1/dbs
[oracle@shanghai dbs]$ ls
hc_DBUA0.dat init.ora orapwshanghai
2、在備庫上建立引數檔案:
只需要一個引數db_name就行:
如下所示:
[oracle@shanghai dbs]$ cat initshanghai.ora
DB_NAME=beijing
DB_UNIQUE_NAME=shanghai
DB_BLOCK_SIZE=8192
3、在備庫上建立相應的目錄:
[oracle@shanghai ~]$ cd $ORACLE_BASE
[oracle@shanghai oracle]$ mkdir -p oradata/shanghai
[oracle@shanghai oracle]$ mkdir -p diag/rdbms/shanghai/shanghai/trace
[oracle@shanghai oracle]$ mkdir -p diag/rdbms/shanghai/shanghai/cdump
[oracle@shanghai oracle]$ mkdir -p admin/shanghai/adump
建立歸檔日誌目錄:
[root@shanghai ~]# cd /
[root@shanghai /]# mkdir archivelog
[root@shanghai /]# chown -R oracle:oinstall /archivelog
4、啟動備庫例項:
[oracle@shanghai ~]$ export ORACLE_SID=shanghai
[oracle@shanghai ~]$ sqlplus / as sysdba;
SQL> startup nomount pfile=$ORACLE_HOME/dbs/initshanghai.ora
ORACLE instance started.
Total System Global Area 217157632 bytes
Fixed Size 2225064 bytes
Variable Size 159386712 bytes
Database Buffers 50331648 bytes
Redo Buffers 5214208 bytes
5、確認可以以sysdba許可權登入
[oracle@shanghai ~]$ sqlplus /nolog
SQL*Plus: Release 11.2.0.2.0 Production on Sun Dec 23 16:07:18 2012
Copyright (c) 1982, 2010, Oracle. All rights reserved.
SQL> conn sys/qweasd@shanghai as sysdba;
Connected.
SQL> conn sys/qweasd@beijing as sysdba;
Connected.
注意:如果遇到如下錯誤,則重啟監聽再試:
SQL> conn sys/qweasd@shanghai as sysdba;
ERROR:
ORA-12528: TNS:listener: all appropriate instances are blocking new connections
6、在主庫上執行rman duplicate命令:
[oracle@beijing ~]$ rman target sys/qweasd@beijing auxiliary sys/qweasd@shanghai
Recovery Manager: Release 11.2.0.2.0 - Production on Sun Dec 23 16:29:21 2012
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
connected to target database: BEIJING (DBID=767262686)
connected to auxiliary database (not started)
RMAN> run {
allocate channel prmy1 type disk;
allocate channel prmy2 type disk;
allocate channel prmy3 type disk;
allocate channel prmy4 type disk;
allocate auxiliary channel stby type disk;
duplicate target database for standby from active database
spfile
parameter_value_convert 'beijing','shanghai'
set db_unique_name='shanghai'
set db_file_name_convert='/beijing/','/shanghai/'
set log_file_name_convert='/beijing/','/shanghai/'
set control_files='/u01/app/oracle/oradata/shanghai/control01.ctl'
set log_archive_max_processes='5'
set fal_client='shanghai'
set fal_server='beijing'
set standby_file_management='AUTO'
set log_archive_config='dg_config=(beijing,shanghai)'
set log_archive_dest_2='service=beijing ASYNC valid_for=(ONLINE_LOGFILE,PRIMARY_ROLE) db_unique_name=beijing'
;
}
過程:
allocated channel: prmy1
channel prmy1: SID=961 device type=DISK
allocated channel: prmy2
channel prmy2: SID=1152 device type=DISK
allocated channel: prmy3
channel prmy3: SID=1344 device type=DISK
allocated channel: prmy4
channel prmy4: SID=6 device type=DISK
allocated channel: stby
channel stby: SID=91 device type=DISK
Starting Duplicate Db at 23-DEC-12
contents of Memory Script.:
{
backup as copy reuse
targetfile '/u01/app/oracle/product/11.2/db_1/dbs/orapwbeijing' auxiliary format
'/u01/app/oracle/product/11.2/db_1/dbs/orapwshanghai' targetfile
'/u01/app/oracle/product/11.2/db_1/dbs/spfilebeijing.ora' auxiliary format
'/u01/app/oracle/product/11.2/db_1/dbs/spfileshanghai.ora' ;
sql clone "alter system set spfile= ''/u01/app/oracle/product/11.2/db_1/dbs/spfileshanghai.ora''";
}
executing Memory Script
Starting backup at 23-DEC-12
Finished backup at 23-DEC-12
sql statement: alter system set spfile= ''/u01/app/oracle/product/11.2/db_1/dbs/spfileshanghai.ora''
contents of Memory Script.:
{
sql clone "alter system set audit_file_dest = ''/u01/app/oracle/admin/shanghai/adump'' comment='''' scope=spfile";
sql clone "alter system set dispatchers = ''(PROTOCOL=TCP) (SERVICE=shanghaiXDB)'' comment='''' scope=spfile";
sql clone "alter system set log_archive_dest_1 = ''location=/archivelog/ valid_for=(ALL_LOGFILES,ALL_ROLES) db_unique_name=shanghai'' comment='''' scope=spfile";
sql clone "alter system set db_unique_name = ''shanghai'' comment='''' scope=spfile";
sql clone "alter system set db_file_name_convert = ''/beijing/'', ''/shanghai/'' comment='''' scope=spfile";
sql clone "alter system set log_file_name_convert = ''/beijing/'', ''/shanghai/'' comment='''' scope=spfile";
sql clone "alter system set control_files = ''/u01/app/oracle/oradata/control01.ctl'' comment='''' scope=spfile";
sql clone "alter system set log_archive_max_processes = 5 comment='''' scope=spfile";
sql clone "alter system set fal_client = ''shanghai'' comment='''' scope=spfile";
sql clone "alter system set fal_server = ''beijing'' comment='''' scope=spfile";
sql clone "alter system set standby_file_management = ''AUTO'' comment='''' scope=spfile";
sql clone "alter system set log_archive_config = ''dg_config=(chicago,boston)'' comment='''' scope=spfile";
sql clone "alter system set log_archive_dest_2 = ''service=beijing ASYNC valid_for=(ONLINE_LOGFILE,PRIMARY_ROLE) db_unique_name=beijing'' comment=''''
scope=spfile";
shutdown clone immediate;
startup clone nomount;
}
executing Memory Script
sql statement: alter system set audit_file_dest = ''/u01/app/oracle/admin/shanghai/adump'' comment= '''' scope=spfile
sql statement: alter system set dispatchers = ''(PROTOCOL=TCP) (SERVICE=shanghaiXDB)'' comment= '''' scope=spfile
sql statement: alter system set log_archive_dest_1 = ''location=/archivelog/ valid_for=(ALL_LOGFILES,ALL_ROLES) db_unique_name=shanghai'' comment= '''' scope=spfile
sql statement: alter system set db_unique_name = ''shanghai'' comment= '''' scope=spfile
sql statement: alter system set db_file_name_convert = ''/beijing/'', ''/shanghai/'' comment= '''' scope=spfile
sql statement: alter system set log_file_name_convert = ''/beijing/'', ''/shanghai/'' comment= '''' scope=spfile
sql statement: alter system set control_files = ''/u01/app/oracle/oradata/control01.ctl'' comment= '''' scope=spfile
sql statement: alter system set log_archive_max_processes = 5 comment= '''' scope=spfile
sql statement: alter system set fal_client = ''shanghai'' comment= '''' scope=spfile
sql statement: alter system set fal_server = ''beijing'' comment= '''' scope=spfile
sql statement: alter system set standby_file_management = ''AUTO'' comment= '''' scope=spfile
sql statement: alter system set log_archive_config = ''dg_config=(chicago,boston)'' comment= '''' scope=spfile
sql statement: alter system set log_archive_dest_2 = ''service=beijing ASYNC valid_for=(ONLINE_LOGFILE,PRIMARY_ROLE) db_unique_name=beijing'' comment= ''''
scope=spfile
Oracle instance shut down
connected to auxiliary database (not started)
Oracle instance started
Total System Global Area 839282688 bytes
Fixed Size 2231128 bytes
Variable Size 574620840 bytes
Database Buffers 255852544 bytes
Redo Buffers 6578176 bytes
allocated channel: stby
channel stby: SID=958 device type=DISK
contents of Memory Script.:
{
backup as copy current controlfile for standby auxiliary format '/u01/app/oracle/oradata/control01.ctl';
}
executing Memory Script
Starting backup at 23-DEC-12
channel prmy1: starting datafile copy
copying standby control file
output file name=/u01/app/oracle/product/11.2/db_1/dbs/snapcf_beijing.f tag=TAG20121223T163128 RECID=2 STAMP=802801888
channel prmy1: datafile copy complete, elapsed time: 00:00:01
Finished backup at 23-DEC-12
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/oracle/oradata/shanghai/temp01.dbf";
switch clone tempfile all;
set newname for datafile 1 to "/u01/app/oracle/oradata/shanghai/system01.dbf";
set newname for datafile 2 to "/u01/app/oracle/oradata/shanghai/sysaux01.dbf";
set newname for datafile 3 to "/u01/app/oracle/oradata/shanghai/undotbs01.dbf";
set newname for datafile 4 to "/u01/app/oracle/oradata/shanghai/users01.dbf";
set newname for datafile 5 to "/u01/app/oracle/oradata/shanghai/example01.dbf";
backup as copy reuse
datafile 1 auxiliary format "/u01/app/oracle/oradata/shanghai/system01.dbf"
datafile 2 auxiliary format "/u01/app/oracle/oradata/shanghai/sysaux01.dbf"
datafile 3 auxiliary format "/u01/app/oracle/oradata/shanghai/undotbs01.dbf"
datafile 4 auxiliary format "/u01/app/oracle/oradata/shanghai/users01.dbf"
datafile 5 auxiliary format "/u01/app/oracle/oradata/shanghai/example01.dbf" ;
sql 'alter system archive log current';
}
executing Memory Script
executing command: SET NEWNAME
renamed tempfile 1 to /u01/app/oracle/oradata/shanghai/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 backup at 23-DEC-12
channel prmy1: starting datafile copy
input datafile file number=00001 name=/u01/app/oracle/oradata/beijing/system01.dbf
channel prmy2: starting datafile copy
input datafile file number=00002 name=/u01/app/oracle/oradata/beijing/sysaux01.dbf
channel prmy3: starting datafile copy
input datafile file number=00005 name=/u01/app/oracle/oradata/beijing/example01.dbf
channel prmy4: starting datafile copy
input datafile file number=00003 name=/u01/app/oracle/oradata/beijing/undotbs01.dbf
output file name=/u01/app/oracle/oradata/shanghai/undotbs01.dbf tag=TAG20121223T163134
channel prmy4: datafile copy complete, elapsed time: 00:00:07
channel prmy4: starting datafile copy
input datafile file number=00004 name=/u01/app/oracle/oradata/beijing/users01.dbf
output file name=/u01/app/oracle/oradata/shanghai/example01.dbf tag=TAG20121223T163134
channel prmy3: datafile copy complete, elapsed time: 00:00:09
output file name=/u01/app/oracle/oradata/shanghai/users01.dbf tag=TAG20121223T163134
channel prmy4: datafile copy complete, elapsed time: 00:00:01
output file name=/u01/app/oracle/oradata/shanghai/system01.dbf tag=TAG20121223T163134
channel prmy1: datafile copy complete, elapsed time: 00:00:15
output file name=/u01/app/oracle/oradata/shanghai/sysaux01.dbf tag=TAG20121223T163134
channel prmy2: datafile copy complete, elapsed time: 00:00:15
Finished backup at 23-DEC-12
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=2 STAMP=802801851 file name=/u01/app/oracle/oradata/shanghai/system01.dbf
datafile 2 switched to datafile copy
input datafile copy RECID=3 STAMP=802801851 file name=/u01/app/oracle/oradata/shanghai/sysaux01.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=4 STAMP=802801851 file name=/u01/app/oracle/oradata/shanghai/undotbs01.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=5 STAMP=802801851 file name=/u01/app/oracle/oradata/shanghai/users01.dbf
datafile 5 switched to datafile copy
input datafile copy RECID=6 STAMP=802801851 file name=/u01/app/oracle/oradata/shanghai/example01.dbf
Finished Duplicate Db at 23-DEC-12
released channel: prmy1
released channel: prmy2
released channel: prmy3
released channel: prmy4
released channel: stby
複製結束。
四、連線到備庫啟動 MRP (Managed Recovery Process)
[oracle@shanghai ~]$ sqlplus / as sysdba;
SQL> alter database recover managed standby database disconnect;
Database altered.
如果需要啟用實時應用,則應該:
SQL> alter database recover managed standby database using current logfile disconnect;
五、如果有Active Dataguard (ADG)的license,可以以read only模式開啟備庫,並開啟恢復:
[oracle@shanghai ~]$ sqlplus / as sysdba;
SQL> alter database recover managed standby database cancel;
SQL> alter database open;
SQL> alter database recover managed standby database disconnect;
或者啟用實時應用:
SQL> alter database recover managed standby database using current logfile disconnect;
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/26194851/viewspace-751546/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 使用 RMAN DUPLICATE...FROM ACTIVE DATABASE 建立物理備用資料庫的分步指南Database資料庫
- RMAN DUPLICATE建立DataGuard物理備庫
- dataguard回顧之安裝———使用rman建立物理備庫
- 使用oracle 11g rman新特性 duplicate target database for standby from active database 建立物理dataguard並開啟RealOracleDatabase
- 【DataGuard】使用GC建立的物理DataGuard主備庫pfile比較GC
- dataguard-建立物理備庫全程解析
- Oracle11g的Dataguard測試,建立物理備庫(Physical Standby Database)OracleDatabase
- 配置Oracle11g的Dataguard測試,建立物理備庫(Physical Standby Database)OracleDatabase
- 使用RMAN複製資料庫 active database資料庫Database
- ORACLE DATAGUARD 資料庫---建立物理備用資料庫Oracle資料庫
- 通過RMAN Duplicate建立Oracle物理standby備庫Oracle
- 使用RMAN建立物理Standby資料庫資料庫
- Step by Step Guide on Creating Physical Standby Using RMAN DUPLICATE...FROM ACTIVE DATABASE WithoutGUIIDEDatabase
- 11gR2中使用duplicate建立physical standby (從rman備份或從active database)Database
- 【DATAGUARD 學習】使用duplicate 建立物理standby 資料庫資料庫
- 使用RMAN進行快速Dataguard資料庫建立資料庫
- 【DataGuard】手工冷備搭建 Oracle 11g DataGuard 物理備庫Oracle
- 【DATAGUARD】 基於同一個主機建立物理備庫和邏輯備庫(二)
- 【DATAGUARD】 基於同一個主機建立物理備庫和邏輯備庫(一)
- 【DATAGUARD】 基於同一個主機建立物理備庫和邏輯備庫 (三)
- 使用RMAN backup和restore方式部署物理備庫REST
- RMAN duplicate from active database 複製資料庫Database資料庫
- 使用RMAN線上建立DataGuard備用庫(資料檔案不同路徑結構)
- 【RMAN】使用RMAN的Duplicate功能建立物理DataGuard報錯(ORA-17627、ORA-17629)處理
- 建立RMAN catalog實現物理備份
- 【DATAGUARD】 基於同一個主機建立物理備庫和邏輯備庫 (四)--新增一個物理dg節點
- 【DATAGUARD】DG系列之RACtoONE物理備庫的搭建
- 使用RMAN建立資料庫備份庫(筆記)資料庫筆記
- Oracle 11gR2 使用 RMAN duplicate from active database 複製資料庫OracleDatabase資料庫
- 用rman建立dataguard備用資料庫繼續(無法找到備份檔案)資料庫
- 【DATAGUARD】Oracle Dataguard物理備庫切換最佳實踐(sqlplus)OracleSQL
- 【DataGuard】Oracle 11g DataGuard 角色轉換(一)物理備庫SwitchoverOracle
- Oracle 11g Rman Active database duplicateOracleDatabase
- 利用RMAN 建立 oracle dataguardOracle
- Oracle 12c 使用RMAN搭建物理備庫(RAC to RAC)Oracle
- dataguard之物理備庫丟失資料檔案
- 一步一步學DataGuard(25)RMAN備份來建立之實踐
- 使用rman建立standby database的過程Database