一、环境(主备库环境相同)
操作系统:Red Hat Enterprise Linux Server release 5.5
oracle:11.2.0.1.0
主库/etc/hosts如下
-
[root@wbg1 ~]# cat /etc/hosts
-
# Do not remove the following line, or various programs
-
# that require network functionality will fail.
-
127.0.0.1 wbg1 localhost.localdomain localhost
-
::1 localhost6.localdomain6 localhost6
-
-
1.1.1.51 wbg1
-
1.1.1.52 wbg2
备库/etc/hosts如下
-
[oracle@wbg2 dbs]$ cat /etc/hosts
-
# Do not remove the following line, or various programs
-
# that require network functionality will fail.
-
127.0.0.1 wbg2 localhost.localdomain localhost
-
::1 localhost6.localdomain6 localhost6
-
-
1.1.1.51 wbg1
-
1.1.1.52 wbg2
二、搭建过程
1.网络配置,tnsname.ora(主备库相同)
-
primary=
-
(DESCRIPTION=
-
(ADDRESS=(PROTOCOL=tcp)(HOST=wbg1)(PORT=1521))
-
(CONNECT_DATA=(SERVICE_NAME=wbg)))
-
standby=
-
(DESCRIPTION=
-
(ADDRESS=(PROTOCOL=tcp)(HOST=wbg2)(PORT=1521))
-
(CONNECT_DATA=(SERVICE_NAME=standby)))
2.从主库拷贝口令文件到备库
-
scp orapwprimary wbg2:/u01/app/oracle/product/11.2.0/db_1/dbs/orapwstandby
3.主库打开强制记录日志
-
SQL> ALTER DATABASE FORCE LOGGING;
-
-
Database altered.
4.在不停库的前提下
DB_UNIQUE_NAME是不能改的,那么就让主库的别名和DB_NAME相同好了
-
SQL> alter system set DB_UNIQUE_NAME=chicago;
-
alter system set DB_UNIQUE_NAME=chicago
-
*
-
ERROR at line 1:
-
ORA-02095: specified initialization parameter cannot be modified
5.对主库的parameter进行配置
-
SQL> alter system set log_archive_config='DG_CONFIG=(wbg,standby)';
-
-
System altered.
-
-
SQL> alter system set LOG_ARCHIVE_DEST_1='LOCATION=/u01/app/oracle/arch/wbg/ VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=wbg';
-
-
System altered.
-
-
SQL> alter system set LOG_ARCHIVE_DEST_2='SERVICE=standby ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=standby';
-
-
System altered.
-
-
-
-
SQL> alter system set FAL_SERVER=standby;
-
-
System altered.
-
-
SQL> alter system set DB_FILE_NAME_CONVERT='/u01/app/oracle/oradata/standby/','/u01/app/oracle/oradata/wbg/' scope=spfile;
-
-
System altered.
-
-
SQL> alter system set LOG_FILE_NAME_CONVERT='/u01/app/oracle/oradata/standby/','/u01/app/oracle/oradata/wbg/' scope=spfile;
-
-
System altered
-
-
SQL> alter system set STANDBY_FILE_MANAGEMENT=AUTO;
-
-
System altered.
6.为主库添加standby redo
-
SQL> ALTER DATABASE ADD STANDBY LOGFILE '/u01/app/oracle/oradata/wbg/std01.log' size 50m;
-
-
Database altered.
-
-
SQL> ALTER DATABASE ADD STANDBY LOGFILE '/u01/app/oracle/oradata/wbg/std02.log' size 50m;
-
-
Database altered.
-
-
SQL> ALTER DATABASE ADD STANDBY LOGFILE '/u01/app/oracle/oradata/wbg/std03.log' size 50m;
-
-
Database altered.
-
-
SQL> ALTER DATABASE ADD STANDBY LOGFILE '/u01/app/oracle/oradata/wbg/std04.log' size 50m;
-
-
Database altered.
7.通过主库生产备库的控制文件,并拷贝到备库
-
SQL> ALTER DATABASE CREATE STANDBY CONTROLFILE AS '/tmp/boston.ctl';
-
-
Database altered.
8.在主库生产pfile,并拷贝到备库
9.在备库修改从主库拷贝过来的pfile,修改为
-
*.compatible='11.2.0.1.0'
-
*.control_files='/u01/app/oracle/oradata/standby/control01.ctl'
-
*.db_block_size=8192
-
*.db_file_name_convert='/u01/app/oracle/oradata/wbg/','/u01/app/oracle/oradata/standby/'
-
*.db_name='WBG'
-
DB_UNIQUE_NAME='standby'
-
*.diagnostic_dest='/u01/app/oracle'
-
*.fal_server='primary'
-
*.log_archive_config='DG_CONFIG=(wbg,standby)'
-
*.log_archive_dest_1='LOCATION=/u01/app/oracle/arch/standby/ VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=standby'
-
*.log_archive_dest_2='SERVICE=primary ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=primary'
-
*.log_file_name_convert='/u01/app/oracle/oradata/wbg/','/u01/app/oracle/oradata/standby/'
-
*.memory_target=662700032
-
*.open_cursors=300
-
*.processes=150
-
*.remote_login_passwordfile='EXCLUSIVE'
-
*.standby_file_management='AUTO'
-
*.undo_tablespace='UNDOTBS1'
10.在主库通过rman进行备库,并拷贝到备库
-
[oracle@wbg1 ~]$ rman target /
-
-
Recovery Manager: Release 11.2.0.1.0 - Production on Sun Apr 12 15:30:14 2015
-
-
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
-
-
connected to target database: WBG (DBID=1668536352)
-
-
RMAN> backup database format '/u01/app/oracle/rman/primary/%U' plus archivelog format '/u01/app/oracle/rman/primary/%U';
-
-
-
Starting backup at 12-APR-15
-
current log archived
-
using target database control file instead of recovery catalog
-
allocated channel: ORA_DISK_1
-
channel ORA_DISK_1: SID=37 device type=DISK
-
channel ORA_DISK_1: starting archived log backup set
-
channel ORA_DISK_1: specifying archived log(s) in backup set
-
input archived log thread=1 sequence=3 RECID=1 STAMP=876840801
-
input archived log thread=1 sequence=4 RECID=2 STAMP=876841838
-
input archived log thread=1 sequence=5 RECID=3 STAMP=876842896
-
input archived log thread=1 sequence=6 RECID=4 STAMP=876842961
-
input archived log thread=1 sequence=7 RECID=5 STAMP=876843016
-
channel ORA_DISK_1: starting piece 1 at 12-APR-15
-
channel ORA_DISK_1: finished piece 1 at 12-APR-15
-
piece handle=/u01/app/oracle/rman/primary/01q47409_1_1 tag=TAG20150412T153017 comment=NONE
-
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:07
-
Finished backup at 12-APR-15
-
-
Starting backup at 12-APR-15
-
using channel ORA_DISK_1
-
channel ORA_DISK_1: starting full datafile backup set
-
channel ORA_DISK_1: specifying datafile(s) in backup set
-
input datafile file number=00001 name=/u01/app/oracle/oradata/wbg/system01.dbf
-
input datafile file number=00002 name=/u01/app/oracle/oradata/wbg/sysaux01.dbf
-
input datafile file number=00005 name=/u01/app/oracle/oradata/wbg/example01.dbf
-
input datafile file number=00003 name=/u01/app/oracle/oradata/wbg/undotbs01.dbf
-
input datafile file number=00004 name=/u01/app/oracle/oradata/wbg/users01.dbf
-
channel ORA_DISK_1: starting piece 1 at 12-APR-15
-
channel ORA_DISK_1: finished piece 1 at 12-APR-15
-
piece handle=/u01/app/oracle/rman/primary/02q4740g_1_1 tag=TAG20150412T153024 comment=NONE
-
channel ORA_DISK_1: backup set complete, elapsed time: 00:01:45
-
channel ORA_DISK_1: starting full datafile backup set
-
channel ORA_DISK_1: specifying datafile(s) in backup set
-
including current control file in backup set
-
including current SPFILE in backup set
-
channel ORA_DISK_1: starting piece 1 at 12-APR-15
-
channel ORA_DISK_1: finished piece 1 at 12-APR-15
-
piece handle=/u01/app/oracle/rman/primary/03q4743p_1_1 tag=TAG20150412T153024 comment=NONE
-
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
-
Finished backup at 12-APR-15
-
-
Starting backup at 12-APR-15
-
current log archived
-
using channel ORA_DISK_1
-
channel ORA_DISK_1: starting archived log backup set
-
channel ORA_DISK_1: specifying archived log(s) in backup set
-
input archived log thread=1 sequence=8 RECID=6 STAMP=876843134
-
channel ORA_DISK_1: starting piece 1 at 12-APR-15
-
channel ORA_DISK_1: finished piece 1 at 12-APR-15
-
piece handle=/u01/app/oracle/rman/primary/04q4743u_1_1 tag=TAG20150412T153214 comment=NONE
-
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
-
Finished backup at 12-APR-15
-
-
RMAN> quit
-
-
-
Recovery Manager complete.
-
[oracle@wbg1 ~]$
11.启动备库的instance,并可以看到,文件已经可以convert过来
-
[oracle@wbg2 dbs]$ !sql
-
sqlplus / as sysdba
-
-
SQL*Plus: Release 11.2.0.1.0 Production on Sun Apr 12 16:07:39 2015
-
-
Copyright (c) 1982, 2009, Oracle. All rights reserved.
-
-
Connected to an idle instance.
-
-
SQL> startup nomount
-
ORACLE instance started.
-
-
Total System Global Area 661209088 bytes
-
Fixed Size 1338560 bytes
-
Variable Size 394265408 bytes
-
Database Buffers 260046848 bytes
-
Redo Buffers 5558272 bytes
-
SQL> !echo $ORACLE_SID
-
standby
-
-
SQL> alter database mount;
-
-
Database altered.
-
-
SQL> select name from v$datafile;
-
-
NAME
-
--------------------------------------------------------------------------------
-
/u01/app/oracle/oradata/standby/system01.dbf
-
/u01/app/oracle/oradata/standby/sysaux01.dbf
-
/u01/app/oracle/oradata/standby/undotbs01.dbf
-
/u01/app/oracle/oradata/standby/users01.dbf
-
/u01/app/oracle/oradata/standby/example01.dbf
12.在备库用rman进行恢复
-
[oracle@wbg2 standby]$ rman target /
-
-
Recovery Manager: Release 11.2.0.1.0 - Production on Sun Apr 12 16:20:54 2015
-
-
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
-
-
connected to target database: WBG (DBID=1668536352, not open)
-
-
RMAN> catalog start with '/u01/app/oracle/rman/standby/';
-
-
using target database control file instead of recovery catalog
-
searching for all files that match the pattern /u01/app/oracle/rman/standby/
-
-
List of Files Unknown to the Database
-
=====================================
-
File Name: /u01/app/oracle/rman/standby/01q47409_1_1
-
File Name: /u01/app/oracle/rman/standby/03q4743p_1_1
-
File Name: /u01/app/oracle/rman/standby/02q4740g_1_1
-
File Name: /u01/app/oracle/rman/standby/04q4743u_1_1
-
-
Do you really want to catalog the above files (enter YES or NO)? yes
-
cataloging files...
-
cataloging done
-
-
List of Cataloged Files
-
=======================
-
File Name: /u01/app/oracle/rman/standby/01q47409_1_1
-
File Name: /u01/app/oracle/rman/standby/03q4743p_1_1
-
File Name: /u01/app/oracle/rman/standby/02q4740g_1_1
-
File Name: /u01/app/oracle/rman/standby/04q4743u_1_1
-
-
RMAN> restore database;
-
-
Starting restore at 12-APR-15
-
allocated channel: ORA_DISK_1
-
channel ORA_DISK_1: SID=20 device type=DISK
-
-
channel ORA_DISK_1: starting datafile backup set restore
-
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
-
channel ORA_DISK_1: restoring datafile 00001 to /u01/app/oracle/oradata/standby/system01.dbf
-
channel ORA_DISK_1: restoring datafile 00002 to /u01/app/oracle/oradata/standby/sysaux01.dbf
-
channel ORA_DISK_1: restoring datafile 00003 to /u01/app/oracle/oradata/standby/undotbs01.dbf
-
channel ORA_DISK_1: restoring datafile 00004 to /u01/app/oracle/oradata/standby/users01.dbf
-
channel ORA_DISK_1: restoring datafile 00005 to /u01/app/oracle/oradata/standby/example01.dbf
-
channel ORA_DISK_1: reading from backup piece /u01/app/oracle/rman/standby/02q4740g_1_1
-
channel ORA_DISK_1: piece handle=/u01/app/oracle/rman/standby/02q4740g_1_1 tag=TAG20150412T153024
-
channel ORA_DISK_1: restored backup piece 1
-
channel ORA_DISK_1: restore complete, elapsed time: 00:01:05
-
Finished restore at 12-APR-15
-
-
RMAN> recover database;
-
-
Starting recover at 12-APR-15
-
using channel ORA_DISK_1
-
-
starting media recovery
-
-
channel ORA_DISK_1: starting archived log restore to default destination
-
channel ORA_DISK_1: restoring archived log
-
archived log thread=1 sequence=5
-
channel ORA_DISK_1: restoring archived log
-
archived log thread=1 sequence=6
-
channel ORA_DISK_1: restoring archived log
-
archived log thread=1 sequence=7
-
channel ORA_DISK_1: reading from backup piece /u01/app/oracle/rman/standby/01q47409_1_1
-
channel ORA_DISK_1: piece handle=/u01/app/oracle/rman/standby/01q47409_1_1 tag=TAG20150412T153017
-
channel ORA_DISK_1: restored backup piece 1
-
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
-
archived log file name=/u01/app/oracle/arch/standby/1_5_876836460.dbf thread=1 sequence=0
-
archived log file name=/u01/app/oracle/arch/standby/1_6_876836460.dbf thread=1 sequence=6
-
archived log file name=/u01/app/oracle/arch/standby/1_7_876836460.dbf thread=1 sequence=7
-
channel ORA_DISK_1: starting archived log restore to default destination
-
channel ORA_DISK_1: restoring archived log
-
archived log thread=1 sequence=8
-
channel ORA_DISK_1: reading from backup piece /u01/app/oracle/rman/standby/04q4743u_1_1
-
channel ORA_DISK_1: piece handle=/u01/app/oracle/rman/standby/04q4743u_1_1 tag=TAG20150412T153214
-
channel ORA_DISK_1: restored backup piece 1
-
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
-
archived log file name=/u01/app/oracle/arch/standby/1_8_876836460.dbf thread=1 sequence=8
-
unable to find archived log
-
archived log thread=1 sequence=9
-
RMAN-00571: ===========================================================
-
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
-
RMAN-00571: ===========================================================
-
RMAN-03002: failure of recover command at 04/12/2015 16:34:13
-
RMAN-06054: media recovery requesting unknown archived log for thread 1 with sequence 9 and starting SCN of 892714
-
-
RMAN>
13.在备库的sqlplus中clear日志文件
-
SQL> ALTER DATABASE CLEAR LOGFILE GROUP 1;
-
-
Database altered.
14.打开备库,备库开启recover
-
SQL> alter database open;
-
-
Database altered.
-
-
SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE DISCONNECT FROM SESSION;
-
-
Database altered.
15.查看主备库告警日志,可以看见主库在发送日志,备库在接收日志,至此dg完成
主库:
-
Sun Apr 12 17:29:06 2015
-
Using STANDBY_ARCHIVE_DEST parameter default value as /u01/app/oracle/arch/wbg/
-
ALTER SYSTEM SET log_archive_dest_state_2='ENABLE' SCOPE=BOTH;
-
Sun Apr 12 17:29:08 2015
-
******************************************************************
-
LGWR: Setting 'active' archival for destination LOG_ARCHIVE_DEST_2
-
******************************************************************
-
Sun Apr 12 17:29:08 2015
-
Thread 1 advanced to log sequence 33 (LGWR switch)
-
Current log# 3 seq# 33 mem# 0: /u01/app/oracle/oradata/wbg/redo03.log
-
Sun Apr 12 17:29:08 2015
-
Archived Log entry 53 added for thread 1 sequence 32 ID 0xcb3dbb7c dest 1:
-
LNS: Standby redo logfile selected for thread 1 sequence 32 for destination LOG_ARCHIVE_DEST_2
-
LNS: Standby redo logfile selected for thread 1 sequence 33 for destination LOG_ARCHIVE_DEST_2
-
Sun Apr 12 17:29:26 2015
-
ALTER SYSTEM ARCHIVE LOG
-
Sun Apr 12 17:29:26 2015
-
Thread 1 advanced to log sequence 34 (LGWR switch)
-
Current log# 1 seq# 34 mem# 0: /u01/app/oracle/oradata/wbg/redo01.log
-
Archived Log entry 55 added for thread 1 sequence 33 ID 0xcb3dbb7c dest 1:
-
Sun Apr 12 17:29:26 2015
-
LNS: Standby redo logfile selected for thread 1 sequence 34 for destination LOG_ARCHIVE_DEST_2
-
ALTER SYSTEM ARCHIVE LOG
-
Thread 1 advanced to log sequence 35 (LGWR switch)
-
Current log# 2 seq# 35 mem# 0: /u01/app/oracle/oradata/wbg/redo02.log
-
Archived Log entry 57 added for thread 1 sequence 34 ID 0xcb3dbb7c dest 1:
-
LNS: Standby redo logfile selected for thread 1 sequence 35 for destination LOG_ARCHIVE_DEST_2
-
ALTER SYSTEM ARCHIVE LOG
-
Thread 1 advanced to log sequence 36 (LGWR switch)
-
Current log# 3 seq# 36 mem# 0: /u01/app/oracle/oradata/wbg/redo03.log
-
Archived Log entry 59 added for thread 1 sequence 35 ID 0xcb3dbb7c dest 1:
-
LNS: Standby redo logfile selected for thread 1 sequence 36 for destination LOG_ARCHIVE_DEST_2
备库:
-
Sun Apr 12 18:10:43 2015
-
RFS[6]: Assigned to RFS process 1957
-
RFS[6]: Identified database type as 'physical standby': Client is ARCH pid 3004
-
RFS[6]: Opened log for thread 1 sequence 29 dbid 1668536352 branch 876836460
-
Sun Apr 12 18:10:43 2015
-
RFS[7]: Assigned to RFS process 1959
-
RFS[7]: Identified database type as 'physical standby': Client is ARCH pid 3008
-
Archived Log entry 25 added for thread 1 sequence 29 rlc 876836460 ID 0xcb3dbb7c dest 2:
-
RFS[7]: Opened log for thread 1 sequence 30 dbid 1668536352 branch 876836460
-
Archived Log entry 26 added for thread 1 sequence 30 rlc 876836460 ID 0xcb3dbb7c dest 2:
-
Sun Apr 12 18:10:43 2015
-
RFS[8]: Assigned to RFS process 1961
-
RFS[8]: Identified database type as 'physical standby': Client is ARCH pid 3011
-
RFS[8]: Opened log for thread 1 sequence 31 dbid 1668536352 branch 876836460
-
Archived Log entry 27 added for thread 1 sequence 31 rlc 876836460 ID 0xcb3dbb7c dest 2:
-
Sun Apr 12 18:10:45 2015
-
RFS[9]: Assigned to RFS process 1963
-
RFS[9]: Identified database type as 'physical standby': Client is LGWR ASYNC pid 3173
-
Primary database is in MAXIMUM PERFORMANCE mode
-
RFS[9]: Selected log 4 for thread 1 sequence 32 dbid 1668536352 branch 876836460
-
Sun Apr 12 18:10:45 2015
-
Archived Log entry 28 added for thread 1 sequence 32 ID 0xcb3dbb7c dest 1:
-
RFS[9]: Selected log 4 for thread 1 sequence 33 dbid 1668536352 branch 876836460
-
Sun Apr 12 18:11:03 2015
-
RFS[9]: Selected log 5 for thread 1 sequence 34 dbid 1668536352 branch 876836460
-
Sun Apr 12 18:11:03 2015
-
Archived Log entry 29 added for thread 1 sequence 33 ID 0xcb3dbb7c dest 1:
-
Sun Apr 12 18:11:04 2015
-
Archived Log entry 30 added for thread 1 sequence 34 ID 0xcb3dbb7c dest 1:
-
RFS[9]: Selected log 4 for thread 1 sequence 35 dbid 1668536352 branch 876836460
-
Sun Apr 12 18:11:05 2015
-
Archived Log entry 31 added for thread 1 sequence 35 ID 0xcb3dbb7c dest 1:
-
RFS[9]: Selected log 4 for thread 1 sequence 36 dbid 1668536352 branch 876836460
-
Sun Apr 12 18:11:37 2015
-
RFS[10]: Assigned to RFS process 1968
-
RFS[10]: Identified database type as 'physical standby': Client is ARCH pid 3004
三、总结
1.用这种方法搭建物理dg,可以保持业务正常使用
2.备库恢复的方法,类似于rman的异机恢复,而且更加简单
3.修改主库的parameter,只能修改spfile
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/30202921/viewspace-1570533/
,如需转载,请注明出处,否则将追究法律责任。