Oracle 10GR2 DataGuard 部署(物理Standby)

  • 环境介绍
  • DataGuard部署
  • 同步功能测试
  • 物理Standby的switchover
  • 同步功能测试
  • 物理Standby的failover

 

一、环境介绍

 

primary

IP地址:172.20.48.88

主机名:dg01  

 

standby

IP地址:172.20.48.89

主机名:dg02

 

 

二、DataGuard部署

 

  1. 配置网络环境
  2. 配置TNS
  3. 创建pfile文件
  4. 生成口令文件
  5. 修改primary pfile文件
  6. 修改standby pfile文件
  7. 配置archive路径
  8. 拷贝数据库
  9. 替换control文件
  10. 应用primary pfile
  11. 应用standby pfile
  12. 启动standby接收状态

 

1.修改primary、standby主机hosts文件确保网络环境正常

 

登录primary

# vi /etc/hosts
增加
172.20.48.88    dg01
172.20.48.89    dg02

 


验证网络环境

# ping dg01
PING dg01 (172.20.48.88) 56(84) bytes of data.
64 bytes from dg01 (172.20.48.88): icmp_seq=1 ttl=64 time=0.021 ms

--- dg01 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.021/0.021/0.021/0.000 ms
# ping dg02
PING dg02 (172.20.48.89) 56(84) bytes of data.
64 bytes from dg02 (172.20.48.89): icmp_seq=1 ttl=64 time=3.17 ms

--- dg02 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 3.178/3.178/3.178/0.000 ms

 


登录standby

# vi /etc/hosts
增加
172.20.48.89    dg02
172.20.48.88    dg01

 

 

验证网络环境

# ping dg01
PING dg01 (172.20.48.88) 56(84) bytes of data.
64 bytes from dg01 (172.20.48.88): icmp_seq=1 ttl=64 time=2.32 ms

--- dg01 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 2.329/2.329/2.329/0.000 ms
# ping dg02
PING dg02 (172.20.48.89) 56(84) bytes of data.
64 bytes from dg02 (172.20.48.89): icmp_seq=1 ttl=64 time=0.019 ms

--- dg02 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.019/0.019/0.019/0.000 ms

 

 

2.修改primary、standby主机tnsname文件确保数据库通讯正常

 

登录primary

$ vi $ORACLE_HOME/network/admin/tnsnames.ora 
增加
DG02 =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = dg02)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = dg02)
    )
  )

 

 

查看通讯状态

$ tnsping dg01

TNS Ping Utility for Linux: Version 10.2.0.1.0 - Production on 18-AUG-2013 21:33:32

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

Used parameter files:


Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = dg01)(PORT = 1521))) (CONNECT_DATA = (SERVICE_NAME = dg01)))
OK (10 msec)
$ tnsping dg02

TNS Ping Utility for Linux: Version 10.2.0.1.0 - Production on 18-AUG-2013 21:33:34

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

Used parameter files:


Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = dg02)(PORT = 1521))) (CONNECT_DATA = (SERVICE_NAME = dg02)))
OK (10 msec)

 


登录standby

$ vi $ORACLE_HOME/network/admin/tnsnames.ora
增加
DG01 =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = dg01)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = dg01)
    )
  )

 

 

查看通讯状态

$ tnsping dg01

TNS Ping Utility for Linux: Version 10.2.0.1.0 - Production on 18-AUG-2013 21:34:53

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

Used parameter files:


Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = dg01)(PORT = 1521))) (CONNECT_DATA = (SERVICE_NAME = dg01)))
OK (0 msec)
$ tnsping dg02

TNS Ping Utility for Linux: Version 10.2.0.1.0 - Production on 18-AUG-2013 21:34:58

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

Used parameter files:


Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = dg02)(PORT = 1521))) (CONNECT_DATA = (SERVICE_NAME = dg02)))
OK (0 msec)

 

 
登录standby验证tns是否配置成功

$ sqlplus /nolog

SQL*Plus: Release 10.2.0.1.0 - Production on Sun Aug 18 21:36:51 2013

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

SQL> conn system/连接密码@dg01
Connected. #成功连接
SQL> quit
Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options

 

 

3.设定日志记录模式及创建pfile文件

 

登录primary

$ cd /u01/app/oracle/product/db_1/dbs
$ sqlplus /nolog

SQL*Plus: Release 10.2.0.1.0 - Production on Sun Aug 18 21:40:19 2013

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

SQL> conn /as sysdba
Connected.
SQL> alter database force logging;  #设定日志记录模式

Database altered.

SQL> create pfile from spfile; #通过spfile文件创建pfile文件

File created.

SQL> quit
Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options

 

 

4.创建口令文件

 

登录primary

$ cd /u01/app/oracle/product/db_1/dbs
$ orapwd file=orapwdg01 password=数据库密码 entries=5

 

 

5.修改pfile文件

 

登录primary

$ vi  /u01/app/oracle/product/db_1/dbs/initdg01.ora
增加
log_archive_dest_1='LOCATION=/u01/app/oracle/oradata/archive'
log_archive_dest_state_1=enable
log_archive_dest_2='SERVICE=dg02'
log_archive_dest_state_2=enable
log_archive_start=true
log_archive_format='%t_%s_%r.arc'
log_archive_max_processes=2
fal_server=dg02
fal_client=dg01
db_unique_name=dg01

$ mkdir -p /u01/app/oracle/oradata/archive
$ mkdir -p /u01/app/oracle/flash_recovery_area

 

 

 6.修改archive默认目录并创建standby文件

 

登录primary

$ sqlplus /nolog

SQL*Plus: Release 10.2.0.1.0 - Production on Sun Aug 18 21:47:51 2013

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

SQL> conn /as sysdba
Connected.
SQL> archive log list;
Database log mode              Archive Mode
Automatic archival             Enabled
Archive destination            USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence     0
Next log sequence to archive   1
Current log sequence           1
SQL> alter system set db_recovery_file_dest='';#清空路径

System altered.

SQL> alter system set log_archive_dest='/u01/app/oracle/oradata/archive';#设定新路径

System altered.

SQL> archive log list;
Database log mode              Archive Mode
Automatic archival             Enabled
Archive destination            /u01/app/oracle/oradata/archive
Oldest online log sequence     0
Next log sequence to archive   1
Current log sequence           1
SQL>  startup force;
ORACLE instance started.

Total System Global Area  285212672 bytes
Fixed Size                  1218968 bytes
Variable Size              88082024 bytes
Database Buffers          188743680 bytes
Redo Buffers                7168000 bytes
Database mounted.
Database opened.
SQL> archive log list;
Database log mode              Archive Mode
Automatic archival             Enabled
Archive destination            /u01/app/oracle/oradata/archive
Oldest online log sequence     1
Next log sequence to archive   2
Current log sequence           2
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount;
ORACLE instance started.

Total System Global Area  285212672 bytes
Fixed Size                  1218968 bytes
Variable Size              88082024 bytes
Database Buffers          188743680 bytes
Redo Buffers                7168000 bytes
Database mounted.
SQL> alter database create standby controlfile as '/u01/app/oracle/oradata/dg01/standby.ctl';#创建standby文件

Database altered.

SQL> alter database open;

Database altered.

SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> quit
Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options

 

 

7.将primary数据库拷贝至standby

 

登录primary

$ cd /u01/app/oracle/oradata/
$ scp -r dg01 dg02:/u01/app/oracle/oradata 

$ cd /u01/app/oracle/admin/
$ scp -r dg01 dg02:/u01/app/oracle/admin/

$ cd /u01/app/oracle/product/db_1/dbs
$ scp initdg01.ora  orapwdg01 dg02:/u01/app/oracle/product/db_1/dbs

 

 

8. 使用standby替换control文件

 

登录standby

$ cd /u01/app/oracle/oradata/dg01/
$ rm -rf control0*
$ mv standby.ctl control01.ctl
$ cp control01.ctl control02.ctl 
$ cp control02.ctl control03.ctl

 

 

9.修改standby pfile文件

 

登录standby

$ cd /u01/app/oracle/product/db_1/dbs/
$ vi initdg01.ora 
修改为
log_archive_dest_1='LOCATION=/u01/app/oracle/oradata/archive'
log_archive_dest_state_1=enable
log_archive_dest_2='SERVICE=dg01'
log_archive_dest_state_2=enable
log_archive_start=true
log_archive_format='%t_%s_%r.arc'
log_archive_max_processes=2
fal_server=dg01
fal_client=dg02
db_unique_name=dg02
$ mkdir -p /u01/app/oracle/oradata/archive
$ mkdir -p /u01/app/oracle/flash_recovery_area

 

 

10.应用新的primary pfile文件

 

登录primary

$ cd /u01/app/oracle/product/db_1/dbs/
$ rm -rf spfiledg01.ora 
$ sqlplus /nolog

SQL*Plus: Release 10.2.0.1.0 - Production on Sun Aug 18 22:15:55 2013

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

SQL> conn /as sysdba
Connected to an idle instance.
SQL> create spfile from pfile;

File created.

SQL> startup
ORACLE instance started.

Total System Global Area  285212672 bytes
Fixed Size                  1218968 bytes
Variable Size              88082024 bytes
Database Buffers          188743680 bytes
Redo Buffers                7168000 bytes
Database mounted.
Database opened.
SQL> quit
Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options

 

 

11.应用新的standby pfile文件并启动备库

 

登录standby

$ cd /u01/app/oracle/product/db_1/dbs/
$ sqlplus /nolog

SQL*Plus: Release 10.2.0.1.0 - Production on Sun Aug 18 22:18:34 2013

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

SQL> conn /as sysdba
Connected to an idle instance.
SQL>  create spfile from pfile;

File created.

SQL> startup nomount;
ORACLE instance started.

Total System Global Area  285212672 bytes
Fixed Size                  1218968 bytes
Variable Size              88082024 bytes
Database Buffers          188743680 bytes
Redo Buffers                7168000 bytes
SQL> alter database mount standby database;

Database altered.

SQL> select name,database_role from v$database;

NAME               DATABASE_ROLE
------------------ --------------------------------
DG01               PHYSICAL STANDBY

 

 

登录primary

$ sqlplus /nolog

SQL*Plus: Release 10.2.0.1.0 - Production on Sun Aug 18 22:20:43 2013

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

SQL> conn /as sysdba
Connected.
SQL> select name,database_role from v$database;

NAME               DATABASE_ROLE
------------------ --------------------------------
DG01               PRIMARY

 

可以看到我们的主库和备库分别是 PRIMARYPHYSICAL STANDBY

 

 

12.接收从主库到备库的redo信息

 

登录standby

$ sqlplus /nolog

SQL*Plus: Release 10.2.0.1.0 - Production on Sun Aug 18 22:22:18 2013

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

SQL> conn /as sysdba
Connected.
SQL> Alter database recover managed standby database disconnect from session;

Database altered.

 

 

此时数据库日志状态

Sun Aug 18 22:24:17 2013
Alter database recover managed standby database disconnect from session
Sun Aug 18 22:24:17 2013
Attempt to start background Managed Standby Recovery process (dg01)
MRP0 started with pid=19, OS id=2975
Sun Aug 18 22:24:17 2013
MRP0: Background Managed Standby Recovery process started (dg01)
Managed Standby Recovery not using Real Time Apply
Clearing online redo logfile 1 /u01/app/oracle/oradata/dg01/redo01.log
Clearing online log 1 of thread 1 sequence number 2
Sun Aug 18 22:24:23 2013
Clearing online redo logfile 1 complete
Media Recovery Waiting for thread 1 sequence 2
Sun Aug 18 22:24:23 2013
Completed: Alter database recover managed standby database disconnect from session

 

 

使用alter system switch logfile查看传输状态

 

primary

Thread 1 cannot allocate new log, sequence 3
Private strand flush not complete
  Current log# 1 seq# 2 mem# 0: /u01/app/oracle/oradata/dg01/redo01.log
Thread 1 advanced to log sequence 3
  Current log# 2 seq# 3 mem# 0: /u01/app/oracle/oradata/dg01/redo02.log

 

 

standby

RFS[1]: No standby redo logfiles created
RFS[1]: Archived Log: '/u01/app/oracle/oradata/archive/1_2_823812298.arc'
Sun Aug 18 22:26:08 2013
Media Recovery Log /u01/app/oracle/oradata/archive/1_2_823812298.arc
Media Recovery Waiting for thread 1 sequence 3

 

 

三、同步功能测试

 

登录primary建立test表

$ sqlplus /nolog

SQL*Plus: Release 10.2.0.1.0 - Production on Mon Aug 19 09:08:51 2013

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

SQL> conn /as sysdba
Connected.
SQL> create table test (id int, name char(10));

Table created.

SQL> insert into test values(0, ' test 01');   

1 row created.

SQL>  insert into test values(1, ' test 02');

1 row created.

SQL>  commit;

Commit complete.

SQL> select * from test;

        ID NAME
---------- --------------------
         0  test 01
         1  test 02

SQL> alter system switch logfile;

System altered.

SQL> /

System altered.

SQL> quit
Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options

 

 

primary日志状态

Mon Aug 19 09:10:02 2013
Thread 1 advanced to log sequence 5
  Current log# 1 seq# 5 mem# 0: /u01/app/oracle/oradata/dg01/redo01.log
Thread 1 advanced to log sequence 6
  Current log# 2 seq# 6 mem# 0: /u01/app/oracle/oradata/dg01/redo02.log
Mon Aug 19 09:10:13 2013

 

 

standby日志状态

RFS[1]: Archived Log: '/u01/app/oracle/oradata/archive/1_4_823812298.arc'
RFS[1]: No standby redo logfiles created
RFS[1]: Archived Log: '/u01/app/oracle/oradata/archive/1_5_823812298.arc'
Mon Aug 19 09:10:22 2013
Media Recovery Log /u01/app/oracle/oradata/archive/1_4_823812298.arc
Media Recovery Log /u01/app/oracle/oradata/archive/1_5_823812298.arc
Media Recovery Waiting for thread 1 sequence 6

 

 

登录standby验证

$ sqlplus /nolog

SQL*Plus: Release 10.2.0.1.0 - Production on Mon Aug 19 09:13:34 2013

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

SQL> conn /as sysdba
Connected.
SQL> select sequence#, first_time,next_time from v$archived_log order by sequence#;

 SEQUENCE# FIRST_TIME   NEXT_TIME
---------- ------------ ------------
         2 18-AUG-13    18-AUG-13
         3 18-AUG-13    18-AUG-13
         4 18-AUG-13    19-AUG-13
         5 19-AUG-13    19-AUG-13

SQL> select sequence#,applied from v$archived_log order by sequence#;

 SEQUENCE# APPLIE
---------- ------
         2 YES
         3 YES
         4 YES
         5 YES

SQL> alter database recover managed standby database cancel;

Database altered.

SQL> alter database open read only;

Database altered.

SQL> select * from test;

        ID NAME
---------- --------------------
         0  test 01
         1  test 02

SQL> Alter database recover managed standby database disconnect from session;

Database altered.

SQL> quit
Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options

 

 

standy日志应用状态

Mon Aug 19 09:13:58 2013
Errors in file /u01/app/oracle/admin/dg01/bdump/dg01_mrp0_2975.trc:
ORA-16037: user requested cancel of managed recovery operation
Mon Aug 19 09:13:58 2013
MRP0: Background Media Recovery process shutdown (dg01)
Mon Aug 19 09:13:58 2013
Managed Standby Recovery Canceled (dg01)
Mon Aug 19 09:13:58 2013
Completed: alter database recover managed standby database cancel
Mon Aug 19 09:14:05 2013
alter database open read only
Mon Aug 19 09:14:05 2013
SMON: enabling cache recovery
Mon Aug 19 09:14:06 2013
Database Characterset is WE8ISO8859P1
**********************************************************
WARNING: Files may exists in db_recovery_file_dest
that are not known to the database. Use the RMAN command
CATALOG RECOVERY AREA to re-catalog any such files.
One of the following events caused this:
1. A backup controlfile was restored.
2. A standby controlfile was restored.
3. The controlfile was re-created.
4. db_recovery_file_dest had previously been enabled and
   then disabled.
**********************************************************
replication_dependency_tracking turned off (no async multimaster replication found)
Physical standby database opened for read only access.
Completed: alter database open read only
Mon Aug 19 09:14:36 2013
Alter database recover managed standby database disconnect from session
Mon Aug 19 09:14:36 2013
Stopping background process CJQ0
Mon Aug 19 09:14:36 2013
Stopping Job queue slave processes
Mon Aug 19 09:14:36 2013
Job queue slave processes stopped
Waiting for dispatcher 'D000' to shutdown
All dispatchers and shared servers shutdown
Mon Aug 19 09:14:38 2013
SMON: disabling cache recovery
Mon Aug 19 09:14:38 2013
Attempt to start background Managed Standby Recovery process (dg01)
MRP0 started with pid=10, OS id=4602
Mon Aug 19 09:14:38 2013
MRP0: Background Managed Standby Recovery process started (dg01)
Managed Standby Recovery not using Real Time Apply
Clearing online redo logfile 1 /u01/app/oracle/oradata/dg01/redo01.log
Clearing online log 1 of thread 1 sequence number 5
Mon Aug 19 09:14:43 2013
Clearing online redo logfile 1 complete
Media Recovery Waiting for thread 1 sequence 6
Mon Aug 19 09:14:44 2013
Completed: Alter database recover managed standby database disconnect from session

 

至此恢复至原始同步状态。

 

切换分switchoverfailover,前者是无损切换,不会丢失数据,而后者则有可能会丢失数据,并且切换后原primary数据库也不再是该data guard配置的一部分了。

Switchover :无损转换,通常是用户手动触发或者有计划的让其自动触发。其执行分两个阶段,第一步,primary数据库转换为standby角色,第二步,standby数据库转换为primary角色,primarystandby只是简单的角色互换。

Failover 不可预知原因导致primary数据库故障并且短期内不能恢复就需要failover

 

 

四、物理Standby的switchover

 

登录primary

 

$ sqlplus /nolog

SQL*Plus: Release 10.2.0.1.0 - Production on Mon Aug 19 09:27:51 2013

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

SQL> conn /as sysdba
Connected.
SQL> select switchover_status from v$database; 

SWITCHOVER_STATUS
----------------------------------------
SESSIONS ACTIVE

SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount;
ORA-32004: obsolete and/or deprecated parameter(s) specified
ORACLE instance started.

Total System Global Area  285212672 bytes
Fixed Size                  1218968 bytes
Variable Size              88082024 bytes
Database Buffers          188743680 bytes
Redo Buffers                7168000 bytes
Database mounted.
SQL> select switchover_status from v$database;

SWITCHOVER_STATUS
----------------------------------------
TO STANDBY
 

SQL> alter database open;

Database altered.

SQL>  alter database commit to switchover to physical standby with session shutdown;

Database altered.

SQL>  shutdown immediate 
ORA-01507: database not mounted


ORACLE instance shut down.
SQL> startup mount
ORA-32004: obsolete and/or deprecated parameter(s) specified
ORACLE instance started.

Total System Global Area  285212672 bytes
Fixed Size                  1218968 bytes
Variable Size              92276328 bytes
Database Buffers          184549376 bytes
Redo Buffers                7168000 bytes
Database mounted.

 

 

select switchover_status from v$database;

如果该列值为"TO STANDBY"则表示primary数据库支持转换为standby角色

 


primary日志状态

Starting background process EMN0
EMN0 started with pid=21, OS id=30343
Mon Aug 19 09:28:02 2013
Shutting down instance: further logons disabled
Mon Aug 19 09:28:02 2013
Stopping background process QMNC
Mon Aug 19 09:28:02 2013
Stopping background process CJQ0
Mon Aug 19 09:28:04 2013
Stopping background process MMNL
Mon Aug 19 09:28:05 2013
Stopping background process MMON
Mon Aug 19 09:28:06 2013
Shutting down instance (immediate)
License high water mark = 11
Mon Aug 19 09:28:06 2013
Stopping Job queue slave processes
Mon Aug 19 09:28:06 2013
Job queue slave processes stopped
All dispatchers and shared servers shutdown
Mon Aug 19 09:28:17 2013
PMON failed to acquire latch, see PMON dump
PMON failed to acquire latch, see PMON dump
PMON failed to acquire latch, see PMON dump
PMON failed to acquire latch, see PMON dump
PMON failed to acquire latch, see PMON dump
Mon Aug 19 09:28:29 2013
PMON failed to acquire latch, see PMON dump
PMON failed to acquire latch, see PMON dump
Mon Aug 19 09:28:33 2013
ALTER DATABASE CLOSE NORMAL
Mon Aug 19 09:28:34 2013
SMON: disabling tx recovery
SMON: disabling cache recovery
Mon Aug 19 09:28:34 2013
Shutting down archive processes
Archiving is disabled
Mon Aug 19 09:28:39 2013
ARCH shutting down
ARC1: Archival stopped
Mon Aug 19 09:28:44 2013
ARC0: Becoming the heartbeat ARCH
ARC0: Archiving disabled
ARCH shutting down
ARC0: Archival stopped
Mon Aug 19 09:28:45 2013
Thread 1 closed at log sequence 6
Successful close of redo thread 1
Mon Aug 19 09:28:45 2013
Completed: ALTER DATABASE CLOSE NORMAL
Mon Aug 19 09:28:45 2013
ALTER DATABASE DISMOUNT
Completed: ALTER DATABASE DISMOUNT
ARCH: Archival disabled due to shutdown: 1089
Shutting down archive processes
Archiving is disabled
Archive process shutdown avoided: 0 active
ARCH: Archival disabled due to shutdown: 1089
Shutting down archive processes
Archiving is disabled
Archive process shutdown avoided: 0 active
Mon Aug 19 09:28:52 2013
Starting ORACLE instance (normal)
LICENSE_MAX_SESSION = 0
LICENSE_SESSIONS_WARNING = 0
Picked latch-free SCN scheme 2
Autotune of undo retention is turned on. 
IMODE=BR
ILAT =18
LICENSE_MAX_USERS = 0
SYS auditing is disabled
ksdpec: called for event 13740 prior to event group initialization
Starting up ORACLE RDBMS Version: 10.2.0.1.0.
System parameters with non-default values:
  processes                = 150
  __shared_pool_size       = 79691776
  __large_pool_size        = 4194304
  __java_pool_size         = 4194304
  __streams_pool_size      = 0
  sga_target               = 285212672
  control_files            = /u01/app/oracle/oradata/dg01/control01.ctl, /u01/app/oracle/oradata/dg01/control02.ctl, /u01/app/oracle/oradata/dg01/control03.ctl
  db_block_size            = 8192
  __db_cache_size          = 188743680
  compatible               = 10.2.0.1.0
  log_archive_start        = TRUE
  log_archive_dest_1       = LOCATION=/u01/app/oracle/oradata/archive
  log_archive_dest_2       = SERVICE=dg02
  log_archive_dest_state_1 = enable
  log_archive_dest_state_2 = enable
  log_archive_max_processes= 2
  log_archive_format       = %t_%s_%r.arc
  fal_client               = dg01
  fal_server               = dg02
  db_file_multiblock_read_count= 16
  db_recovery_file_dest    = /u01/app/oracle/flash_recovery_area
  db_recovery_file_dest_size= 2147483648
  undo_management          = AUTO
  undo_tablespace          = UNDOTBS1
  remote_login_passwordfile= EXCLUSIVE
  db_domain                = 
  dispatchers              = (PROTOCOL=TCP) (SERVICE=dg01XDB)
  job_queue_processes      = 10
  background_dump_dest     = /u01/app/oracle/admin/dg01/bdump
  user_dump_dest           = /u01/app/oracle/admin/dg01/udump
  core_dump_dest           = /u01/app/oracle/admin/dg01/cdump
  audit_file_dest          = /u01/app/oracle/admin/dg01/adump
  db_name                  = dg01
  db_unique_name           = dg01
  open_cursors             = 300
  pga_aggregate_target     = 94371840
Deprecated system parameters with specified values:
  log_archive_start        
End of deprecated system parameter listing
PMON started with pid=2, OS id=30389
PSP0 started with pid=3, OS id=30391
MMAN started with pid=4, OS id=30393
DBW0 started with pid=5, OS id=30395
LGWR started with pid=6, OS id=30397
CKPT started with pid=7, OS id=30399
SMON started with pid=8, OS id=30401
RECO started with pid=9, OS id=30403
CJQ0 started with pid=10, OS id=30405
MMON started with pid=11, OS id=30407
MMNL started with pid=12, OS id=30409
Mon Aug 19 09:28:52 2013
starting up 1 dispatcher(s) for network address '(ADDRESS=(PARTIAL=YES)(PROTOCOL=TCP))'...
starting up 1 shared server(s) ...
Mon Aug 19 09:28:52 2013
ALTER DATABASE   MOUNT
Mon Aug 19 09:28:56 2013
Setting recovery target incarnation to 2
Mon Aug 19 09:28:56 2013
Successful mount of redo thread 1, with mount id 459322772
Mon Aug 19 09:28:56 2013
Database mounted in Exclusive Mode
Completed: ALTER DATABASE   MOUNT
Mon Aug 19 09:29:06 2013
alter database open
Mon Aug 19 09:29:06 2013
LGWR: STARTING ARCH PROCESSES
ARC0 started with pid=16, OS id=30445
Mon Aug 19 09:29:06 2013
ARC0: Archival started
ARC1: Archival started
LGWR: STARTING ARCH PROCESSES COMPLETE
ARC1 started with pid=17, OS id=30449
Mon Aug 19 09:29:06 2013
Thread 1 opened at log sequence 6
  Current log# 2 seq# 6 mem# 0: /u01/app/oracle/oradata/dg01/redo02.log
Successful open of redo thread 1
Mon Aug 19 09:29:06 2013
ARC0: STARTING ARCH PROCESSES
Mon Aug 19 09:29:06 2013
MTTR advisory is disabled because FAST_START_MTTR_TARGET is not set
Mon Aug 19 09:29:06 2013
SMON: enabling cache recovery
Mon Aug 19 09:29:06 2013
ARC1: Becoming the 'no FAL' ARCH
ARC1: Becoming the 'no SRL' ARCH
ARC2 started with pid=18, OS id=30459
Mon Aug 19 09:29:06 2013
ARC2: Archival started
ARC0: STARTING ARCH PROCESSES COMPLETE
ARC0: Becoming the heartbeat ARCH
Mon Aug 19 09:29:06 2013
Successfully onlined Undo Tablespace 1.
Mon Aug 19 09:29:06 2013
SMON: enabling tx recovery
Mon Aug 19 09:29:07 2013
Database Characterset is WE8ISO8859P1
replication_dependency_tracking turned off (no async multimaster replication found)
Starting background process QMNC
QMNC started with pid=19, OS id=30463
Mon Aug 19 09:29:07 2013
db_recovery_file_dest_size of 2048 MB is 0.00% used. This is a
user-specified limit on the amount of space that will be used by this
database for recovery-related files, and does not reflect the amount of
space available in the underlying filesystem or ASM diskgroup.
Mon Aug 19 09:29:08 2013
Completed: alter database open
Mon Aug 19 09:29:17 2013
 alter database commit to switchover to physical standby with session shutdown
Mon Aug 19 09:29:17 2013
ALTER DATABASE COMMIT TO SWITCHOVER TO PHYSICAL STANDBY (dg01)
Mon Aug 19 09:30:07 2013
SMON: disabling tx recovery
Mon Aug 19 09:30:07 2013
Stopping background process CJQ0
Mon Aug 19 09:30:07 2013
Stopping background process QMNC
Mon Aug 19 09:30:09 2013
Stopping Job queue slave processes
Mon Aug 19 09:30:09 2013
Job queue slave processes stopped
Waiting for dispatcher 'D000' to shutdown
All dispatchers and shared servers shutdown
Active process 30529 user 'oracle' program 'oracledg01@dg01'
Active process 30481 user 'oracle' program 'oracledg01@dg01'
Active process 30479 user 'oracle' program 'oracledg01@dg01'
Active process 30475 user 'oracle' program 'oracledg01@dg01'
Active process 30473 user 'oracle' program 'oracledg01@dg01'
Active process 30477 user 'oracle' program 'oracledg01@dg01'
Active process 30508 user 'oracle' program 'oracledg01@dg01'
Active process 30467 user 'oracle' program 'oracledg01@dg01'
Active process 30485 user 'oracle' program 'oracledg01@dg01'
CLOSE: waiting for server sessions to complete.
Mon Aug 19 09:30:15 2013
PMON failed to acquire latch, see PMON dump
PMON failed to acquire latch, see PMON dump
PMON failed to acquire latch, see PMON dump
PMON failed to acquire latch, see PMON dump
PMON failed to acquire latch, see PMON dump
Mon Aug 19 09:30:27 2013
PMON failed to acquire latch, see PMON dump
PMON failed to acquire latch, see PMON dump
PMON failed to acquire latch, see PMON dump
PMON failed to acquire latch, see PMON dump
Mon Aug 19 09:30:36 2013
CLOSE: all sessions shutdown successfully.
Mon Aug 19 09:30:36 2013
SMON: disabling cache recovery
Mon Aug 19 09:30:36 2013
Shutting down archive processes
Archiving is disabled
Mon Aug 19 09:30:41 2013
ARCH shutting down
ARC2: Archival stopped
Mon Aug 19 09:30:46 2013
ARCH shutting down
ARC1: Archival stopped
Mon Aug 19 09:30:51 2013
ARCH shutting down
ARC0: Archival stopped
Mon Aug 19 09:30:52 2013
Thread 1 closed at log sequence 6
Successful close of redo thread 1
Mon Aug 19 09:30:52 2013
ARCH: Noswitch archival of thread 1, sequence 6
ARCH: End-Of-Redo Branch archival of thread 1 sequence 6
ARCH: Archiving is disabled due to current logfile archival
Clearing standby activation ID 459262087 (0x1b5fc887)
The primary database controlfile was created using the
'MAXLOGFILES 16' clause.
There is space for up to 13 standby redo logfiles
Use the following SQL commands on the standby database to create
standby redo logfiles that match the primary database:
ALTER DATABASE ADD STANDBY LOGFILE 'srl1.f' SIZE 52428800;
ALTER DATABASE ADD STANDBY LOGFILE 'srl2.f' SIZE 52428800;
ALTER DATABASE ADD STANDBY LOGFILE 'srl3.f' SIZE 52428800;
ALTER DATABASE ADD STANDBY LOGFILE 'srl4.f' SIZE 52428800;
Archivelog for thread 1 sequence 6 required for standby recovery
MRP0 started with pid=10, OS id=30591
Mon Aug 19 09:30:53 2013
MRP0: Background Managed Standby Recovery process started (dg01)
Managed Standby Recovery not using Real Time Apply
Online logfile pre-clearing operation disabled by switchover
Media Recovery Log /u01/app/oracle/oradata/archive/1_6_823812298.arc
Identified End-Of-Redo for thread 1 sequence 6
Mon Aug 19 09:30:58 2013
Media Recovery End-Of-Redo indicator encountered
Mon Aug 19 09:30:58 2013
Media Recovery Applied until change 528858
Mon Aug 19 09:30:58 2013
MRP0: Media Recovery Complete: End-Of-REDO (dg01)
Resetting standby activation ID 459262087 (0x1b5fc887)
Mon Aug 19 09:30:59 2013
Waiting for MRP0 pid 30591 to terminate
Waiting for MRP0 pid 30591 to terminate
Mon Aug 19 09:31:01 2013
MRP0: Background Media Recovery process shutdown (dg01)
Mon Aug 19 09:31:01 2013
idle dispatcher 'D000' terminated, pid = (13, 1)
Mon Aug 19 09:31:01 2013
Switchover: Complete - Database shutdown required (dg01)
Mon Aug 19 09:31:01 2013
Completed:  alter database commit to switchover to physical standby with session shutdown
Shutting down instance: further logons disabled
Mon Aug 19 09:31:05 2013
Stopping background process MMNL
Mon Aug 19 09:31:06 2013
Stopping background process MMON
Mon Aug 19 09:31:07 2013
Shutting down instance (immediate)
License high water mark = 11
Waiting for dispatcher 'D000' to shutdown
All dispatchers and shared servers shutdown
Mon Aug 19 09:31:09 2013
ALTER DATABASE CLOSE NORMAL
ORA-1507 signalled during: ALTER DATABASE CLOSE NORMAL...
ARCH: Archival disabled due to shutdown: 1089
Shutting down archive processes
Archiving is disabled
Archive process shutdown avoided: 0 active
ARCH: Archival disabled due to shutdown: 1089
Shutting down archive processes
Archiving is disabled
Archive process shutdown avoided: 0 active
Mon Aug 19 09:31:16 2013
Starting ORACLE instance (normal)
LICENSE_MAX_SESSION = 0
LICENSE_SESSIONS_WARNING = 0
Picked latch-free SCN scheme 2
Autotune of undo retention is turned on. 
IMODE=BR
ILAT =18
LICENSE_MAX_USERS = 0
SYS auditing is disabled
ksdpec: called for event 13740 prior to event group initialization
Starting up ORACLE RDBMS Version: 10.2.0.1.0.
System parameters with non-default values:
  processes                = 150
  __shared_pool_size       = 83886080
  __large_pool_size        = 4194304
  __java_pool_size         = 4194304
  __streams_pool_size      = 0
  sga_target               = 285212672
  control_files            = /u01/app/oracle/oradata/dg01/control01.ctl, /u01/app/oracle/oradata/dg01/control02.ctl, /u01/app/oracle/oradata/dg01/control03.ctl
  db_block_size            = 8192
  __db_cache_size          = 184549376
  compatible               = 10.2.0.1.0
  log_archive_start        = TRUE
  log_archive_dest_1       = LOCATION=/u01/app/oracle/oradata/archive
  log_archive_dest_2       = SERVICE=dg02
  log_archive_dest_state_1 = enable
  log_archive_dest_state_2 = enable
  log_archive_max_processes= 2
  log_archive_format       = %t_%s_%r.arc
  fal_client               = dg01
  fal_server               = dg02
  db_file_multiblock_read_count= 16
  db_recovery_file_dest    = /u01/app/oracle/flash_recovery_area
  db_recovery_file_dest_size= 2147483648
  undo_management          = AUTO
  undo_tablespace          = UNDOTBS1
  remote_login_passwordfile= EXCLUSIVE
  db_domain                = 
  dispatchers              = (PROTOCOL=TCP) (SERVICE=dg01XDB)
  job_queue_processes      = 10
  background_dump_dest     = /u01/app/oracle/admin/dg01/bdump
  user_dump_dest           = /u01/app/oracle/admin/dg01/udump
  core_dump_dest           = /u01/app/oracle/admin/dg01/cdump
  audit_file_dest          = /u01/app/oracle/admin/dg01/adump
  db_name                  = dg01
  db_unique_name           = dg01
  open_cursors             = 300
  pga_aggregate_target     = 94371840
Deprecated system parameters with specified values:
  log_archive_start        
End of deprecated system parameter listing
PMON started with pid=2, OS id=30621
PSP0 started with pid=3, OS id=30623
MMAN started with pid=4, OS id=30625
DBW0 started with pid=5, OS id=30627
LGWR started with pid=6, OS id=30629
CKPT started with pid=7, OS id=30631
SMON started with pid=8, OS id=30633
RECO started with pid=9, OS id=30635
CJQ0 started with pid=10, OS id=30637
MMON started with pid=11, OS id=30639
MMNL started with pid=12, OS id=30641
Mon Aug 19 09:31:16 2013
starting up 1 dispatcher(s) for network address '(ADDRESS=(PARTIAL=YES)(PROTOCOL=TCP))'...
starting up 1 shared server(s) ...
Mon Aug 19 09:31:16 2013
ALTER DATABASE   MOUNT
Mon Aug 19 09:31:20 2013
Setting recovery target incarnation to 2
ARCH: STARTING ARCH PROCESSES
ARC0 started with pid=16, OS id=30650
Mon Aug 19 09:31:20 2013
ARC0: Archival started
ARC1: Archival started
ARCH: STARTING ARCH PROCESSES COMPLETE
Mon Aug 19 09:31:20 2013
ARC0: Becoming the 'no FAL' ARCH
ARC0: Becoming the 'no SRL' ARCH
ARC0: Thread not mounted
ARC1 started with pid=17, OS id=30652
ARC1: Becoming the heartbeat ARCH
ARC1: Thread not mounted
Mon Aug 19 09:31:20 2013
Successful mount of redo thread 1, with mount id 459281700
Mon Aug 19 09:31:20 2013
Physical Standby Database mounted.
Completed: ALTER DATABASE   MOUNT

 

 

登录standby切换角色

$ sqlplus /nolog

SQL*Plus: Release 10.2.0.1.0 - Production on Mon Aug 19 09:40:49 2013

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

SQL> conn /as sysdba
Connected.
SQL> select switchover_status from v$database;

SWITCHOVER_STATUS
----------------------------------------
TO PRIMARY

SQL> alter database commit to switchover to primary; 

Database altered.

 

 

select switchover_status from v$database;

此时待转换standby数据库switchover_status列值应该是"TO_PRIMARY"

 

standby日志状态

Mon Aug 19 09:41:03 2013
alter database commit to switchover to primary
Mon Aug 19 09:41:03 2013
ALTER DATABASE SWITCHOVER TO PRIMARY (dg01)
Mon Aug 19 09:41:03 2013
If media recovery active, switchover will wait 900 seconds
SwitchOver after complete recovery through change 528858
Online log /u01/app/oracle/oradata/dg01/redo02.log: Thread 1 Group 2 was previously cleared
Standby became primary SCN: 528856
Mon Aug 19 09:41:08 2013
Switchover: Complete - Database shutdown required (dg01)
Completed: alter database commit to switchover to primary
Mon Aug 19 09:41:14 2013
ARC1: Archival disabled due to instance shutdown
Shutting down archive processes
Archiving is disabled
Mon Aug 19 09:41:21 2013
RFS[4]: Archival disabled due to shutdown: 16098
Shutting down archive processes
Archiving is disabled
Mon Aug 19 09:41:24 2013
ARCH shutting down
Mon Aug 19 09:41:24 2013
Archive process shutdown avoided: 0 active
Mon Aug 19 09:41:24 2013
ARC0: Archival stopped
Mon Aug 19 09:41:24 2013
RFS[4]: Archival disabled due to shutdown: 16098
Shutting down archive processes
Archiving is disabled
Archive process shutdown avoided: 0 active
Mon Aug 19 09:41:29 2013
ARCH shutting down
ARC1: Archival stopped

 

登录查看角色是否转化成功

 

登录primary

SQL> select name,database_role from v$database;

NAME               DATABASE_ROLE
------------------ --------------------------------
DG01               PHYSICAL STANDBY

 

 

登录standby

SQL> select name,database_role from v$database;

NAME               DATABASE_ROLE
------------------ --------------------------------
DG01               PRIMARY

 

 

使用alter system switch logfile查看传输状态

 

standby

Mon Aug 19 09:58:12 2013
Thread 1 advanced to log sequence 8
  Current log# 1 seq# 8 mem# 0: /u01/app/oracle/oradata/dg01/redo01.log
Thread 1 advanced to log sequence 9
  Current log# 3 seq# 9 mem# 0: /u01/app/oracle/oradata/dg01/redo03.log

 


primary

RFS[2]: Assigned to RFS process 32645
RFS[2]: Identified database type as 'physical standby'
RFS[2]: No standby redo logfiles created
RFS[2]: Archived Log: '/u01/app/oracle/oradata/archive/1_7_823812298.arc'
RFS[2]: No standby redo logfiles created
RFS[2]: Archived Log: '/u01/app/oracle/oradata/archive/1_8_823812298.arc'

 

 

五、同步功能测试

 

登录dg02新建test02表

$ sqlplus /nolog

SQL*Plus: Release 10.2.0.1.0 - Production on Mon Aug 19 10:08:57 2013

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

SQL> conn /as sysdba
Connected.
SQL> create table test02 (id int, name char(10));

Table created.

SQL>  insert into test02 values(0, ' test 01');

1 row created.

SQL>  insert into test02 values(1, ' test 02');

1 row created.

SQL> commit;                                   

Commit complete.

SQL> select * from test02;

        ID NAME
---------- --------------------
         0  test 01
         1  test 02

SQL>  alter system switch logfile;

System altered.

SQL> /

System altered.

SQL> quit
Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options

 

 

dg02日志状态

Thread 1 advanced to log sequence 10
  Current log# 2 seq# 10 mem# 0: /u01/app/oracle/oradata/dg01/redo02.log
Thread 1 advanced to log sequence 11
  Current log# 1 seq# 11 mem# 0: /u01/app/oracle/oradata/dg01/redo01.log

 

登录dg01验证

SQL> select * from test02;

        ID NAME
---------- --------------------
         0  test 01
         1  test 02

 

 

六、物理Standby的failover

 

1、 检查归档文件是否连续

 

查询待转换standby数据库的V$ARCHIVE_GAP视图,确认归档文件是否连接

SQL> SELECT THREAD#, LOW_SEQUENCE#, HIGH_SEQUENCE# FROM V$ARCHIVE_GAP;

no rows selected

 

 

2、 检查归档文件是否完整

 

分别在primary/standby执行下列语句

SQL> select distinct thread#,max(sequence#) over(partition by thread#) a from v$archived_log;
 
SQL> select distinct thread#,max(sequence#) over(partition by thread#) a from v$archived_log; 

   THREAD#          A
---------- ----------
       1           26

 
SQL> select distinct thread#,max(sequence#) over(partition by thread#) a from v$archived_log; 
 
  

   THREAD#          A
---------- ----------
         1         26

 

 

3、 启动failover

SQL> alter database recover managed standby database finish force; 

Database altered.

 

 

4、 切换物理standby角色为primary

 

SQL> alter database commit to switchover to primary; 

Database altered.

 

 

5、 启动新的primary数据库。 

SQL> shutdown immediate

ORA-01109: database not open
Database dismounted.
ORACLE instance shut down.


SQL> startup

Total System Global Area 2298478592 bytes
Fixed Size                  1220652 bytes
Variable Size             503320532 bytes
Database Buffers         1778384896 bytes
Redo Buffers               15552512 bytes
Database mounted.
Database opened.

 

角色转换工作完成。剩下的是补救措施(针对原primary数据库),由于此时primary数据库已经不再是data guard配置的一部分,我们需要做的就是尝试看看能否恢复原primary数据库,将其改造为新的standby服务器。具体操作方式可以分为二类:1.重建  2.备份恢复。

 

至此、完成。

 

你可能感兴趣的:(dataguard)