Dataguard的使用试验(一)-- 主从切换

 Dataguard的使用试验(一)-- 主从切换
一、如何主从的手动切换
二、如何完成自动切换?

一、 如何主从的手动切换
1)在主数据库上:
SQL> alter database commit to switchover to physical standby;
Database altered.
(如果遇到ORA-01093错误,就执行alter database commit to switchover to physical standby with session shutdown该语句)

SQL> shutdown immediate
ORA-01507: database not mounted
ORACLE instance shut down.

以备用模式启用原主库
SQL> startup nomount;

SQL> alter database mount standby database;
Database altered.

SQL> select name,open_mode,PROTECTION_MODE,DATABASE_ROLE from v$database;
NAME OPEN_MODE PROTECTION_MODE DATABASE_ROLE
--------- ---------- -------------------- ----------------
GE MOUNTED MAXIMUM PERFORMANCE PHYSICAL STANDBY


SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE DISCONNECT FROM SESSION;
Database altered.

2)在从数据库上:
SQL> alter database commit to switchover to primary;
Database altered.

SQL> shutdown immediate;
ORA-01109: database not open
Database dismounted.
ORACLE instance shut down.

SQL> startup;
ORACLE instance started.
Total System Global Area 167772160 bytes
Fixed Size 1218316 bytes
Variable Size 62916852 bytes
Database Buffers 100663296 bytes
Redo Buffers 2973696 bytes
Database mounted.
Database opened.

SQL> select name,open_mode,PROTECTION_MODE,DATABASE_ROLE from v$database;
NAME OPEN_MODE PROTECTION_MODE DATABASE_ROLE
--------- ---------- -------------------- ----------------
GE READ WRITE MAXIMUM PERFORMANCE PRIMARY


此时发现主从数据库已经被切换过来,下面是测试是否日志保持一致:

SQL>alter system archive log current;
System altered.

SQL> select max(sequence#) from v$archived_log;
MAX(SEQUENCE#)
--------------
  88

此时查询从数据库中的REDO应用情况:
SQL> select sequence# ,applied from v$archived_log order by sequence#;
 SEQUENCE# APP
---------- ---
  1 YES
  1 NO
  2 YES
  。。。
  85 YES
  86 YES
  86 NO
261 rows selected.

分析:发现存在REDO应用中有几条记录中的APP字段是NO的 说明这些REDO没有被应用到从数据库
解决:
先停止Standby:
SQL> alter database recover managed standby database cancel;
Database altered.

SQL> recover managed standby database disconnect from session;
Media recovery complete.

此时产生疑问,主从数据库切换之后从数据库中的REDO应用日志最大为86,而此时主数据库中的REDO日志的最大已经达到89,但是重新应用日志
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE DISCONNECT FROM SESSION;之后还是这样 ,总是有主库的部分日志没有传到从数据库中
并且没有应用。
查看V$ARCHIVE_GAP表:
SQL> select * FROM V$ARCHIVE_GAP;
no rows selected

试图将87,88,89这些在主数据库中的存在但是在从数据库中不存在的日志文件复制到从数据库中,然后再应用这些被遗漏的日志,过程如下:
在主数据库中:
[root@localhost archive]# scp log1_89_676393126.arc root@192.168.1.160:/opt/oracle/oradata/ge/archive/
root@192.168.1.160's password:
log1_89_676393126.arc 100% 50KB 50.0KB/s 00:00
[root@localhost archive]# scp log1_88_676393126.arc root@192.168.1.160:/opt/oracle/oradata/ge/archive/
root@192.168.1.160's password:
log1_88_676393126.arc 100% 91KB 90.5KB/s 00:00
[root@localhost archive]# scp log1_87_676393126.arc root@192.168.1.160:/opt/oracle/oradata/ge/archive/
root@192.168.1.160's password:
log1_87_676393126.arc 100% 1024 1.0KB/s 00:00
[root@localhost archive]#

在从数据库中:
[root@localhost archive]# ls -lpth
total 77M
-rw-r----- 1 root root 1.0K Mar 8 15:27 log1_87_676393126.arc
-rw-r----- 1 root root 91K Mar 8 15:27 log1_88_676393126.arc
-rw-r----- 1 root root 50K Mar 8 15:26 log1_89_676393126.arc

[root@localhost archive]# chown oracle.oinstall *.*

[root@localhost archive]# ls -lpth
total 77M
-rw-r----- 1 oracle oinstall 1.0K Mar 8 15:27 log1_87_676393126.arc
-rw-r----- 1 oracle oinstall 91K Mar 8 15:27 log1_88_676393126.arc
-rw-r----- 1 oracle oinstall 50K Mar 8 15:26 log1_89_676393126.arc

复制成功,此时试图在从数据库中应用这些被遗漏的日志:
SQL> alter database recover managed standby database cancel;
Database altered.

SQL> recover managed standby database disconnect from session;
Media recovery complete.

SQL> select max(sequence#) from v$archived_log;
MAX(SEQUENCE#)
--------------
  86
   
仍然没有被应用过来

SQL> select * from V$ARCHIVE_GAP ;
no rows selected

此时试图使用在从数据库中手动注册这些没有被应用的REDO日志:

下面试图使用在从数据库中注册日志的方法:
在主数据库中查询没有被应用的日志的名称:
SQL> select name from V$ARCHIVED_LOG;
NAME
....
--------------------------------------------------------------------------------
/opt/oracle/oradata/ge/archive/log1_87_676393126.arc
/opt/oracle/oradata/ge/archive/log1_88_676393126.arc
/opt/oracle/oradata/ge/archive/log1_89_676393126.arc
80 rows selected.

在从数据库中注册没再从数据库中应用的日志:
SQL> ALTER DATABASE REGISTER PHYSICAL LOGFILE '/opt/oracle/oradata/ge/archive/log1_87_676393126.arc';
Database altered.
SQL> ALTER DATABASE REGISTER PHYSICAL LOGFILE '/opt/oracle/oradata/ge/archive/log1_88_676393126.arc';
Database altered.
SQL> ALTER DATABASE REGISTER PHYSICAL LOGFILE '/opt/oracle/oradata/ge/archive/log1_89_676393126.arc';
Database altered.

此时查看从数据库被日志应用情况:
SQL> select max(sequence#) from v$archived_log;
MAX(SEQUENCE#)
--------------
  89

SQL> select sequence# ,applied from v$archived_log order by sequence#;
 SEQUENCE# APP
---------- ---
  1 YES
  。。 。。
  87 YES
  88 YES
  89 YES
264 rows selected.

此时这些没有被应用的REDO日志终于被我手动应用到从数据库中了:) 哈哈哈,开心~~

注:如果在查询$ARCHIVE_GAP出来有记录的话,也可以同样采用在复制到从数据库上然后在从数据库中注册这些日志,步骤如下:
a. 备库上检查是否存在归档中断
SQL> SELECT THREAD#, LOW_SEQUENCE#, HIGH_SEQUENCE# FROM V$ARCHIVE_GAP;
b. 在主库上执行语句并找出归档文件
SQL> SELECT NAME FROM V$ARCHIVED_LOG WHERE THREAD#=1 AND DEST_ID=1 AND SEQUENCE# BETWEEN XX AND XX;
c、如果存在拷贝相应的归档到STANDBY数据库,并注册.
SQL> ALTER DATABASE REGISTER PHYSICAL LOGFILE 'xxx';


试验过程中遇到的问题归纳如下:
问题1:
SQL> recover managed standby database disconnect from session ;
ORA-01093: ALTER DATABASE CLOSE only permitted with no sessions connected
解决方法:
查询有那些活动的会话:
SELECT SID, PROCESS, PROGRAM FROM V$SESSION
 WHERE TYPE = 'USER'
AND SID <> (SELECT DISTINCT SID FROM V$MYSTAT);

确实有活动会话,先关闭从数据库 然后重新启动

问题2:
SQL> alter database recover managed standby database disconnect from session;
alter database recover managed standby database disconnect from session
*
ERROR at line 1:
ORA-01153: an incompatible media recovery is active

解决方法:
 alter database recover managed standby database cancel;

 问题3:
 SQL> select sequence# ,applied from v$archived_log where applied='NO' order by sequence# ;
 SEQUENCE# APP
---------- ---
  82 NO
  83 NO

在REDO应用中有几条记录中的APP字段是NO的 说明这些REDO没有被应用到从数据库

解决方法:
SQL> alter database recover managed standby database cancel;
Database altered.
SQL> recover managed standby database disconnect from session;
Media recovery complete.

问题4:
主数据库上查询:
SQL> select max(sequence#) from v$archived_log;
MAX(SEQUENCE#)
--------------
  94
从数据库上查询:
SQL> select max(sequence#) from v$archived_log;
MAX(SEQUENCE#)
--------------
  94

但是在主数据库上执行下面的语句时:
SQL> alter database commit to switchover to physical standby;
alter database commit to switchover to physical standby
*
ERROR at line 1:
ORA-16416: Switchover target is not synchronized with the primary
报上面的错误??

分析:主从数据库的日志最大值都相等,并且都应用了,为什么不允许主从切换呢?
解决方法:
在从数据库上:
SQL> shutdown immediate
ORA-01109: database not open

Database dismounted.
ORACLE instance shut down.
SQL> startup nomount pfile='/opt/oracle/admin/ge/pfile/init.ora.10182008214357';
ORACLE instance started.

Total System Global Area 167772160 bytes
Fixed Size 1218316 bytes
Variable Size 62916852 bytes
Database Buffers 100663296 bytes
Redo Buffers 2973696 bytes
SQL> alter database mount standby database;
Database altered.

然后重新还原从数据库以及日志:
RMAN> restore database;
RMAN> restore archivelog all;

此时查询从数据库的日志应用情况:
SQL> select max(sequence#) from v$archived_log;
MAX(SEQUENCE#)
--------------
  95
   
此时查询主数据库的日志最大值:
SQL> select max(sequence#) from v$archived_log;
MAX(SEQUENCE#)
--------------
  95

然后在主数据库重新切换:
SQL> alter database commit to switchover to physical standby;
Database altered.
执行成功!!

问题5:
SQL> alter database commit to switchover to primary;
alter database commit to switchover to primary
*
ERROR at line 1:
ORA-16139: media recovery required
解决方法:
SQL> alter database recover managed standby database disconnect from session;
Database altered.

参考网页:
http://rdc.taobao.com/blog/dba/html/123_dataguard_physical_standby.html

   
上面是讲述如何主从的手动切换,下面继续讲如何主从自动切换

二、如何完成自动切换?
Oracle Data Guard Broker是一个分布式管理框架,它不但自动化了 Data Guard 配置的创建、维护和监控,并对这些操作进行统一管理。
可以通过Oracle Enterprise Manager(它使用 Broker)或 Broker 的专用命令行界面 (DGMGRL) 执行所有管理操作。
以下列表说明了 Broker 自动化和简化的一些操作:
? 创建和启用 Data Guard 配置,此配置包括一个主数据库和最多九个备用(物理或逻辑)数据库,这些数据库的全部或某个组合可形成 RAC 集群。
? 从配置中的任意站点上管理整个 Data Guard 配置。
? 执行转换或故障切换操作,此类操作涉及到配置中的所有系统的复杂角色转换。
? 利用集中式监控、测试和事件通知,来监控日志使用率、捕获诊断信息并快速检测问题。
Broker 的易于使用的界面和对 Data Guard 配置的集中管理和监控使 Data Guard 成为企业获得增强的高可用性和数据保护的解决方案。

1创建 DG Broker 配置
步骤1:前提条件
步骤2:设置 DG_BROKER_START 初始化参数
步骤3:创建用于监听器的服务
步骤4:创建 Broker 配置
步骤5:启用 Broker 配置

步骤1:前提条件
有主数据库和从数据库

步骤2:设置 DG_BROKER_START 初始化参数
设置 DG_BROKER_START 初始化参数
在这一任务中,您将主数据库和物理备用数据库的 DG_BROKER_START 初始化参数设置为 TRUE。
1). 连接到您的主数据库,检查 DG_BROKER_START 的值。
SQL> show parameter DG_BROKER_START;
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
dg_broker_start boolean FALSE
2).在主数据库上,将 DG_BROKER_START 参数设为 TRUE。
SQL> alter system set DG_BROKER_START=true;
System altered.
3).现在,连接到您的物理备用数据库,检查 DG_BROKER_START 的值。
SQL> connect sys/test@GE as sysdba
Connected.
SQL> show parameter DG_BROKER_START;
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
dg_broker_start boolean FALSE
4)在您的备用数据库上将 DG_BROKER_START 的值设为 TRUE。
SQL> alter system set DG_BROKER_START=true;
System altered.

步骤3:创建用于监听器的服务
在这一任务中,您将定义用于监听器的服务,包括 GLOBAL_DBNAME 的 db_unique_name_DGMGRL.db_domain 值。
1)在从数据库上修改$ORACLE_HOME/network/admin下的listener.ora文件,在
SID_LIST_LISTENER =
  (SID_LIST =
  (SID_DESC =
  (SID_NAME = PLSExtProc)
  (ORACLE_HOME = /opt/oracle/product/10.2.0)
  (PROGRAM = extproc)
  )
  (SID_DESC =
  (GLOBAL_DBNAME = ge02)
  (ORACLE_HOME = /opt/oracle/product/10.2.0)
  (SID_NAME = ge02)
  )
  (SID_DESC =
  (GLOBAL_DBNAME = ge)
  (ORACLE_HOME = /opt/oracle/product/10.2.0)
  (SID_NAME = ge)
  )
  )
中添加
  (SID_DESC =
  (GLOBAL_DBNAME = standby) --GLOBAL_DBNAME为db_unique_name_DGMGRL.db_domain
  (ORACLE_HOME =/opt/oracle/product/10.2.0/)
  (SID_NAME = ge)
  )
 (SID_DESC =
  (GLOBAL_DBNAME = standby_DGMGRL) --GLOBAL_DBNAME为db_unique_name_DGMGRL.db_domain
  (ORACLE_HOME =/opt/oracle/product/10.2.0/)
  (SID_NAME = ge)
 )

修改之后为:
SID_LIST_LISTENER =
  (SID_LIST =
  (SID_DESC =
  (SID_NAME = PLSExtProc)
  (ORACLE_HOME = /opt/oracle/product/10.2.0)
  (PROGRAM = extproc)
  )
  (SID_DESC =
  (GLOBAL_DBNAME = ge02)
  (ORACLE_HOME = /opt/oracle/product/10.2.0)
  (SID_NAME = ge02)
  )
  (SID_DESC =
  (GLOBAL_DBNAME = ge)
  (ORACLE_HOME = /opt/oracle/product/10.2.0)
  (SID_NAME = ge)
  )
  (SID_DESC =
  (GLOBAL_DBNAME = standby)
  (ORACLE_HOME =/opt/oracle/product/10.2.0/)
  (SID_NAME = ge)
  )
  (SID_DESC =
  (GLOBAL_DBNAME = standby_DGMGRL)
  (ORACLE_HOME =/opt/oracle/product/10.2.0/)
  (SID_NAME = ge)
  )
  )
注:GLOBAL_DBNAME 应为初始参数 <db_unique_name>_DGMGRL.<db_domain> 的连接。
注意:在主数据库上也需要修改$ORACLE_HOME/network/admin下的listener.ora文件
添加下面:
  (SID_DESC =
  (GLOBAL_DBNAME = ge)
  (ORACLE_HOME =/opt/oracle/product/10.2.0/)
  (SID_NAME = ge)
  )
  (SID_DESC =
  (GLOBAL_DBNAME = ge_DGMGRL)
  (ORACLE_HOME =/opt/oracle/product/10.2.0/)
  (SID_NAME = ge)
  )
如果添加错误 ,会在switchover时报ORA-12514: TNS:listener does not currently know of service requested in connect descriptor错误
修正参考:http://oracle-tech.blogspot.com/2009/01/ora-12514-during-switchover-using-data.html

   
2)重新加载监听器。
lsnrctl stop
lsnrctl start
或者执行
lsnrctl reload

步骤4:创建 Broker 配置
在这一任务中,您将创建 Data Guard Broker 配置。
1)调用 DGMGRL 并连接至您的主数据库。
[oracle@localhost admin]$ dgmgrl
DGMGRL for Linux: Version 10.2.0.1.0 - Production
Copyright (c) 2000, 2005, Oracle. All rights reserved.
Welcome to DGMGRL, type "help" for information.
DGMGRL> connect sys/test;
Connected.
2)创建 Broker 配置,包括主数据库的档案。
DGMGRL> create configuration 'DGConfig1' as
> primary database is 'ge'
> connect identifier is GE; --GE是Oracle Net Services name
Configuration "DGConfig1" created with primary database "ge"

3)显示有关配置的信息。
DGMGRL> show configuration;
Configuration
  Name: DGConfig1
  Enabled: NO
  Protection Mode: MaxPerformance
  Fast-Start Failover: DISABLED
  Databases:
  ge - Primary database
Current status for "DGConfig1":
DISABLED

4)使用以下命令将您的物理备用数据库添加到 broker 配置中。
DGMGRL> add database 'standby' as connect identifier is STANDBY MAINTAINED AS PHYSICAL; --GE是Oracle Net Services name
Database "standby" added

5)使用 SHOW CONFIGURATION 命令验证 orclsby1 数据库添加到了配置中。
DGMGRL> show configuration;
Configuration
  Name: DGConfig1
  Enabled: NO
  Protection Mode: MaxPerformance
  Fast-Start Failover: DISABLED
  Databases:
  ge - Primary database
  standby - Physical standby database
Current status for "DGConfig1":
DISABLED
DGMGRL>

步骤5:启用 Broker 配置
成功为主数据库和备用数据库设置好 Data Guard 环境后,您现在可以启用 broker 配置。
1)启用整个配置。这可能需要一些时间来完成。
DGMGRL> enable configuration;
Enabled.
2)验证配置已成功启用。
DGMGRL> show configuration;
Configuration
  Name: DGConfig1
  Enabled: YES
  Protection Mode: MaxPerformance
  Fast-Start Failover: DISABLED
  Databases:
  ge - Primary database
  standby - Physical standby database

Current status for "DGConfig1":
SUCCESS
可以注意到Enabled由NO变更为YES

测试自动主从数据库切换操作
在进行主从数据库切换操作之前,必须确保:
1)主从数据库的状态是在线的;
2)所有参与的数据库都必须是完好的,没有任何错误和警告;
3)从数据库的属性也被设置在主数据库上,以便当主数据库转换为从数据库时原主数据库能够正常工作;
4)如有必要的话, Standby redo日志文件需要在主数据库上创建;

1)Check the primary database
DGMGRL> SHOW DATABASE VERBOSE 'ge';
Database
  Name: ge
  Role: PRIMARY
  Enabled: YES
  Intended State: ONLINE
  Instance(s):
  ge

  Properties:
  InitialConnectIdentifier = 'ge'
  LogXptMode = 'ASYNC'
  Dependency = ''
  DelayMins = '0'
  Binding = 'OPTIONAL'
  MaxFailure = '0'
  MaxConnections = '1'
  ReopenSecs = '300'
  NetTimeout = '180'
  LogShipping = 'ON'
  PreferredApplyInstance = ''
  ApplyInstanceTimeout = '0'
  ApplyParallel = 'AUTO'
  StandbyFileManagement = 'MANUAL'
  ArchiveLagTarget = '0'
  LogArchiveMaxProcesses = '2'
  LogArchiveMinSucceedDest = '1'
  DbFileNameConvert = ''
  LogFileNameConvert = ''
  FastStartFailoverTarget = ''
  StatusReport = '(monitor)'
  InconsistentProperties = '(monitor)'
  InconsistentLogXptProps = '(monitor)'
  SendQEntries = '(monitor)'
  LogXptStatus = '(monitor)'
  RecvQEntries = '(monitor)'
  HostName = 'localhost.localdomain'
  SidName = 'ge'
  LocalListenerAddress = '(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.1.160)(PORT=1521))'
  StandbyArchiveLocation = '?/dbs/arch'
  AlternateLocation = ''
  LogArchiveTrace = '0'
  LogArchiveFormat = '%t_%s_%r.dbf'
  LatestLog = '(monitor)'
  TopWaitEvents = '(monitor)'

Current status for "ge":
SUCCESS

2)Check the standby database that is the target of the switchover.
DGMGRL> SHOW DATABASE VERBOSE 'standby';
Database
  Name: standby
  Role: PHYSICAL STANDBY
  Enabled: YES
  Intended State: ONLINE
  Instance(s):
  ge

  Properties:
  InitialConnectIdentifier = 'standby'
  LogXptMode = 'ARCH'
  Dependency = ''
  DelayMins = '0'
  Binding = 'OPTIONAL'
  MaxFailure = '0'
  MaxConnections = '1'
  ReopenSecs = '300'
  NetTimeout = '180'
  LogShipping = 'ON'
  PreferredApplyInstance = ''
  ApplyInstanceTimeout = '0'
  ApplyParallel = 'AUTO'
  StandbyFileManagement = 'AUTO'
  ArchiveLagTarget = '0'
  LogArchiveMaxProcesses = '2'
  LogArchiveMinSucceedDest = '1'
  DbFileNameConvert = ''
  LogFileNameConvert = ''
  FastStartFailoverTarget = ''
  StatusReport = '(monitor)'
  InconsistentProperties = '(monitor)'
  InconsistentLogXptProps = '(monitor)'
  SendQEntries = '(monitor)'
  LogXptStatus = '(monitor)'
  RecvQEntries = '(monitor)'
  HostName = 'localhost.localdomain'
  SidName = 'ge'
  LocalListenerAddress = '(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.1.161)(PORT=1521))'
  StandbyArchiveLocation = '/opt/oracle/oradata/ge/archive'
  AlternateLocation = ''
  LogArchiveTrace = '0'
  LogArchiveFormat = 'log%t_%s_%r.arc'
  LatestLog = '(monitor)'
  TopWaitEvents = '(monitor)'

Current status for "standby":
SUCCESS

3)Issue the switchover command.
DGMGRL> SWITCHOVER TO 'standby';
Performing switchover NOW, please wait...
Operation requires shutdown of instance "ge" on database "ge"
Shutting down instance "ge"...
ORA-01109: database not open

Database dismounted.
ORACLE instance shut down.
Operation requires shutdown of instance "ge" on database "standby"
Shutting down instance "ge"...
ORA-01109: database not open

Database dismounted.
ORACLE instance shut down.
Operation requires startup of instance "ge" on database "ge"
Starting instance "ge"...
ORACLE instance started.
Database mounted.
Operation requires startup of instance "ge" on database "standby"
Starting instance "ge"...
ORACLE instance started.
Database mounted.
Switchover succeeded, new primary is "standby"

4)Show the configuration
如果此时立即进行如下查看,会出现如下错误:
DGMGRL> show configuration;
Error:
ORA-01034: ORACLE not available

这种情况是正常的,因为在http://download.oracle.com/docs/cd/B13789_01/server.101/b10822/dgmgrl.htm#i78344 中的SWITCHOVER命令的使用的最后有如下说明:
You must manually issue the SHUTDOWN and STARTUP commands to restart the new primary and standby database instances in this configuration.
也就是说:在这个配置中你必须手动对新主从数据库进行 SHUTDOWN和STARTUP命令的操作。
If the standby database that is assuming the primary role is a physical standby database, then both the primary and standby databases will
be restarted after the switchover completes.If the standby database is a logical standby database, then neither the primary database nor
the logical standby database is restarted.
也就是说:也就是如果在主从数据库切换之前从数据库是物理从数据库,那么在主从切换之后需要重新启动下新的主从数据库;如果在主从数据库切换之前从数据库是
  逻辑从数据库,则新的主从数据库都不需要重新启动。

在新主数据库中执行:
SQL> connect / as sysdba
Connected to an idle instance.
SQL> startup;

在新从数据库中执行:
SQL> startup nomount;
SQL> alter database mount standby database;
Database altered.

SQL> select name,open_mode,PROTECTION_MODE,DATABASE_ROLE from v$database;
NAME OPEN_MODE PROTECTION_MODE DATABASE_ROLE
--------- ---------- -------------------- ----------------
GE MOUNTED MAXIMUM PERFORMANCE PHYSICAL STANDBY

SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE DISCONNECT FROM SESSION;
Database altered.

注:过程中会遇到ORA-01102: cannot mount database in EXCLUSIVE mode错误,可以通过执行:
[root@localhost dbs]# pwd
/opt/oracle/product/10.2.0/dbs
[root@localhost dbs]# fuser -u lkSTANDBY
[root@localhost dbs]# fuser -k lkSTANDBY
[root@localhost dbs]# fuser -u lkGE
[root@localhost dbs]# fuser -k lkGE
来解决:)

新的主从数据库在重新启动过之后,查看:
DGMGRL> show configuration;
Configuration
  Name: DGConfig1
  Enabled: YES
  Protection Mode: MaxPerformance
  Fast-Start Failover: DISABLED
  Databases:
  ge - Physical standby database
  standby - Primary database

Current status for "DGConfig1":
SUCCESS

此时发现主从数据库确实做了切换。自动切换成功!!


#########################################################################################################################################
问题1:
DGMGRL> SWITCHOVER TO 'standby';
Performing switchover NOW, please wait...
Operation requires shutdown of instance "ge" on database "ge"
Shutting down instance "ge"...
ORA-01109: database not open

Database dismounted.
ORACLE instance shut down.
Operation requires shutdown of instance "ge" on database "standby"
Shutting down instance "ge"...
ORA-01109: database not open

Database dismounted.
ORACLE instance shut down.
Operation requires startup of instance "ge" on database "ge"
Starting instance "ge"...
Unable to connect to database
ORA-12514: TNS:listener does not currently know of service requested in connect descriptor

Failed.
You are no longer connected to ORACLE
Please connect again.
Unable to start instance "ge"
You must start instance "ge" manually
Operation requires startup of instance "ge" on database "standby"
You must start instance "ge" manually
Switchover succeeded, new primary is "standby"

错误原因:
创建用于监听器的服务出错,主数据库的listener.ora中添加为如下错误:
(SID_DESC =
  (GLOBAL_DBNAME = standby)
  (ORACLE_HOME =/opt/oracle/product/10.2.0/)
  (SID_NAME = ge)
  )
  (SID_DESC =
  (GLOBAL_DBNAME = standby_DGMGRL)
  (ORACLE_HOME =/opt/oracle/product/10.2.0/)
  (SID_NAME = ge)
  )
应该改为:
(SID_DESC =
  (GLOBAL_DBNAME = ge)
  (ORACLE_HOME =/opt/oracle/product/10.2.0/)
  (SID_NAME = ge)
  )
  (SID_DESC =
  (GLOBAL_DBNAME = ge_DGMGRL)
  (ORACLE_HOME =/opt/oracle/product/10.2.0/)
  (SID_NAME = ge)
  )
修正参考:http://oracle-tech.blogspot.com/2009/01/ora-12514-during-switchover-using-data.html

问题2:
在LOG文件中发现在SWITCHOVER过程中有如下提示:
LD_LIBRARY_PATH is not set!
The default library directories are /lib and /usr/lib
Unable to find dynamic library libocrb10.so in search paths
Unable to find dynamic library libocrutl10.so in search paths
Unable to find dynamic library libocrutl10.so in search paths

解决:
在.bash_profile文件中添加如下:
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:$LD_LIBRARY_PATH
参考:http://dbataj.blogspot.com/2008/08/lblibrarypath-is-not-set-on-startup.html

DGMGRL> show configuration
Error:
ORA-01034: ORACLE not available

DGMGRL> exit
[oracle@localhost ~]$ dgmgrl
DGMGRL for Linux: Version 10.2.0.1.0 - Production

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

Welcome to DGMGRL, type "help" for information.
DGMGRL> connect sys/test
Connected.
Error:
ORA-01034: ORACLE not available

DGMGRL> exit
[oracle@localhost ~]$ export ORACLE_SID=ge
[oracle@localhost ~]$ dgmgrl
DGMGRL for Linux: Version 10.2.0.1.0 - Production

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

Welcome to DGMGRL, type "help" for information.
DGMGRL> connect sys/test
Connected.
Error:
ORA-01034: ORACLE not available

DGMGRL> show database 'ge' 'LogXptStatus';
Error:
ORA-01034: ORACLE not available


参考网页:
创建 DG Broker 配置
http://www.oracle.com/technology/global/cn/obe/11gr1_db/ha/dataguard/dg_broker/dg_broker.htm
http://chenyan995.itpub.net/post/29348/475967
http://download.oracle.com/docs/cd/B13789_01/server.101/b10822/cli.htm#i1007698
http://download.oracle.com/docs/cd/B13789_01/server.101/b10822/dgmgrl.htm#i78344



Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'myMapeer' defined in file [D:\Users\EX-LUOLIYIN001\IdeaProjects\commpro\target\classes\com\china\commpro\app\module1\mapper\MyMapeer.class]: Unsatisfied dependency expressed through bean property 'sqlSessionFactory'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [org/mybatis/spring/boot/autoconfigure/MybatisAutoConfiguration.class]: Unsatisfied dependency expressed through method 'sqlSessionFactory' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Tomcat.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.tomcat.jdbc.pool.DataSource]: Factory method 'dataSource' threw exception; nested exception is org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Cannot determine embedded database driver class for database type NONE. If you want an embedded database please put a supported one on the classpath. If you have database settings to be loaded from a particular profile you may need to active it (no profiles are currently active).
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页