----------------------配置环境----------------------------------------------------
主库
主机名:centos6 ip地址:192.168.48.10
操作系统版本:Centos6.5(final)
数据库版本:11.2.0.4.0
Oracle sid:orcl
db_unique_name:orcl
备库 主机名:centos6_dg ip地址:192.168.48.11 操作系统版本:Centos6.5(final) 只安装Oracle软件,无需建库 db_uniqe_name:orcldg
-------------------------------------------------------------------------------------
1. 设置dg_broker_start为true
备库 主机名:centos6_dg ip地址:192.168.48.11 操作系统版本:Centos6.5(final) 只安装Oracle软件,无需建库 db_uniqe_name:orcldg
-------------------------------------------------------------------------------------
一. 操作系统环境配置
添加主备库ip地址映射
主库:
[root@centos6 ~]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.48.10 centos6
192.168.48.11 centos6_dg
备库:
[root@centos6_dg ~]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.48.11 centos6_dg
192.168.48.10 centos6
(可选)确保防火墙关闭,以免监听出现连接问题
主库+备库
[root@centos6 ~]# cat /etc/selinux/config | grep 'SELINUX'
# SELINUX= can take one of these three values:
SELINUX=diabled # 应为disabled
[root@centos6 ~]# service iptables stop
iptables: Setting chains to policy ACCEPT: filter [ OK ]
iptables: Flushing firewall rules: [ OK ]
iptables: Unloading modules: [ OK ]
[root@centos6 ~]# chkconfig iptables off
[root@centos6 ~]# service iptables status
iptables: Firewall is not running.
二. 监听配置
参考官方文档:E10835-091. 配置db_domain(可选,这里只是为了与官方文档中的监听配置一致)
SQL> alter system set db_domain='us.oracle.com' scope=spfile;
System altered.
2. 配置listener.ora(静态)
关于这里为什么要配置静态监听:因为备库上是有oracle实例的,静态监听即使没有实例也可以启动,而动态监听则需要PMon来注册oracle服务
主库:
[oracle@centos6 admin]$ cat listener.ora
LISTENER=
(DESCRIPTION=
(ADDRESS_LIST=
(ADDRESS=(PROTOCOL=tcp)(HOST=centos6)(PORT=1521))
))
SID_LIST_LISTENER=
(SID_LIST=
(SID_DESC=
(GLOBAL_DBNAME=orcl_DGMGRL.us.oracle.com) #这里glocal dbname的格式为 db_unique_name+DGMGRL+db_domain
(ORACLE_HOME=/u01/app/oracle/product/11.2.0)
(SID_NAME=orcl))
)
测试监听能否正常开启:
[oracle@centos6 ~]$ lsnrctl start
LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 27-NOV-2016 11:49:16
Copyright (c) 1991, 2013, Oracle. All rights reserved.
Starting /u01/app/oracle/product/11.2.0/bin/tnslsnr: please wait...
TNSLSNR for Linux: Version 11.2.0.4.0 - Production
System parameter file is /u01/app/oracle/product/11.2.0/network/admin/listener.ora
Log messages written to /u01/app/oracle/diag/tnslsnr/centos6/listener/alert/log.xml
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=centos6)(PORT=1521)))
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=centos6)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Linux: Version 11.2.0.4.0 - Production
Start Date 27-NOV-2016 11:49:16
Uptime 0 days 0 hr. 0 min. 0 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /u01/app/oracle/product/11.2.0/network/admin/listener.ora
Listener Log File /u01/app/oracle/diag/tnslsnr/centos6/listener/alert/log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=centos6)(PORT=1521)))
Services Summary...
Service "orcl_DGMGRL.us.oracle.com" has 1 instance(s).
Instance "orcl", status UNKNOWN, has 1 handler(s) for this service...
The command completed successfully
3. 配置TNS
主库:
[oracle@centos6 admin]$ cat tnsnames.ora
orcl=
(DESCRIPTION=
(ADDRESS_LIST=
(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.48.10)(PORT=1521))
)
(CONNECT_DATA=
(SERVICE_NAME=orcl_DGMGRL.us.oracle.com)))
orcldg= # 事先配置了备库的TNS
(DESCRIPTION=
(ADDRESS_LIST=
(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.48.11)(PORT=1521))
)
(CONNECT_DATA=
(SERVICE_NAME=orcldg_DGMGRL.us.oracle.com)))
[oracle@centos6 admin]$ sqlplus system/oracle@orcl #测试下是否能够正常连接
4. 将监听和TNS传输到备库
[oracle@centos6 admin]$ scp tnsnames.ora 192.168.48.11:/u01/app/oracle/product/11.2.0/db_1
oracle@192.168.48.11's password:
tnsnames.ora 100% 167 0.2KB/s 00:00
[oracle@centos6 admin]$ scp listener.ora 192.168.48.11:/u01/app/oracle/product/11.2.0/db_1/network/admin
oracle@192.168.48.11's password:
listener.ora 100% 286 0.3KB/s 00:00
[oracle@centos6 admin]$ scp tnsnames.ora 192.168.48.11:/u01/app/oracle/product/11.2.0/db_1/network/admin
oracle@192.168.48.11's password:
tnsnames.ora 100% 167 0.2KB/s 00:00
5. 配置备库监听与TNS
[oracle@centos6_dg admin]$ cat listener.ora
LISTENER=
(DESCRIPTION=
(ADDRESS_LIST=
(ADDRESS=(PROTOCOL=tcp)(HOST=centos6_dg)(PORT=1521))
))
SID_LIST_LISTENER=
(SID_LIST=
(SID_DESC=
(GLOBAL_DBNAME=orcldg_DGMGRL.us.oracle.com)
(ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1)
(SID_NAME=orcldg))
)
[oracle@centos6_dg admin]$ cat tnsnames.ora
orcl=
(DESCRIPTION=
(ADDRESS_LIST=
(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.48.10)(PORT=1521))
)
(CONNECT_DATA=
(SERVICE_NAME=orcl_DGMGRL.us.oracle.com)))
orcldg=
(DESCRIPTION=
(ADDRESS_LIST=
(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.48.11)(PORT=1521))
)
(CONNECT_DATA=
(SERVICE_NAME=orcldg_DGMGRL.us.oracle.com)))
三. 参数文件和密码文件配置
1. 主库开启归档
SQL> archive log list;
Database log mode Archive Mode
Automatic archival Enabled
Archive destination USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence 7
Next log sequence to archive 9
Current log sequence 9
2. (主库)开启远程传输日志的归档
SQL> show parameter log_archive_dest
SQL> alter system set log_archive_dest_2='service=orcldg LGWR ASYNC';
System altered.
3. (主库)配置数据文件、日志文件日志传输路径
SQL> show parameter convert
SQL> select * from v$logfile; #主库
SQL> select * from v$dbfile; #主库
(备库)建立数据文件和日志文件路径
oracle@centos6_dg ~]$ mkdir -p /u01/app/oracle/oradata/orcldg
(主库)根据主库和备库文件目录设置参数:
SQL> alter system set db_file_name_convert='/u01/app/oracle/oradata/orcldg','/u01/app/oracle/oradata/orcl' scope=spfile;
System altered.
SQL> alter system set log_file_name_convert='/u01/app/oracle/oradata/orcldg','/u01/app/oracle/oradata/orcl' scope=spfile;
System altered.
4. (主库)开启闪回
SQL> show parameter recover
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount;
ORACLE instance started.
Total System Global Area 776646656 bytes
Fixed Size 2257272 bytes
Variable Size 507514504 bytes
Database Buffers 264241152 bytes
Redo Buffers 2633728 bytes
Database mounted.
SQL> alter database flashback on;
Database altered.
SQL> alter database open;
Database altered.
5.(主库) 设置standby_file_management参数为自动
SQL> alter system set standby_file_management=auto;
System altered.
6.(主库)设置主库操作强制产生日志
SQL> alter database force logging;
Database altered.
7. (主库)创建主库standby日志组(一般比日志原来多一组)
SQL> alter database add standby logfile group 4 '/u01/app/oracle/oradata/orcl/std_redo04.log' size 50M;
Database altered.
SQL> alter database add standby logfile group 5 '/u01/app/oracle/oradata/orcl/std_redo05.log' size 50M;
Database altered.
SQL> alter database add standby logfile group 6 '/u01/app/oracle/oradata/orcl/std_redo06.log' size 50M;
Database altered.
SQL> alter database add standby logfile group 7 '/u01/app/oracle/oradata/orcl/std_redo07.log' size 50M;
Database altered.
8. (主库)根据spfile创建pfile
SQL> create pfile ='/home/oracle/initorcldg.ora' from spfile;
File created.
9. (主库)将参数文件和密码文件传输到备库
[oracle@centos6 ~]$ scp initorcldg.ora 192.168.48.11:/u01/app/oracle/product/11.2.0/db_1/dbs
oracle@192.168.48.11's password:
initorcldg.ora 100% 1172 1.1KB/s 00:00
[oracle@centos6 ~]$ cd $ORACLE_HOME/dbs
[oracle@centos6 dbs]$ scp orapworcl 192.168.48.11:/u01/app/oracle/product/11.2.0/db_1/dbs/orapworcldg
oracle@192.168.48.11's password:
orapworcl 100% 1536 1.5KB/s 00:00
10.(备库)调整参数文件,根据参数文件中的设置创建目录
参数文件:[oracle@centos6_dg dbs]$ vim initorcldg.ora
orcl.__db_cache_size=327155712 # 隐藏参数无需修改
orcl.__java_pool_size=4194304
orcl.__large_pool_size=8388608
orcl.__oracle_base='/u01/app/oracle'#ORACLE_BASE set from environment
orcl.__pga_aggregate_target=314572800
orcl.__sga_target=465567744
orcl.__shared_io_pool_size=0
orcl.__shared_pool_size=117440512
orcl.__streams_pool_size=0
*.audit_file_dest='/u01/app/oracle/admin/orcldg/adump' # 检测目录是否存在
*.audit_trail='db'
*.compatible='11.2.0.4.0'
*.control_files='/u01/app/oracle/oradata/orcldg/std_control01.ctl','/u01/app/oracle/fast_recovery_area/orcldg/std_control02.ctl'
*.db_block_size=8192 # 检测目录是否存在
*.db_domain='us.oracle.com'
*.db_file_name_convert='/u01/app/oracle/oradata/orcl','/u01/app/oracle/oradata/orcldg' # 与主库是相反的
*.db_name='orcl' # db_name与主库一致,因为dataguaed把主库和备库视为一个逻辑上的数据库
*.db_unique_name='orcldg' # db_unique_name要与主库不一样
*.db_recovery_file_dest='/u01/app/oracle/fast_recovery_area'
*.db_recovery_file_dest_size=4385144832
*.diagnostic_dest='/u01/app/oracle'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=orclXDB)'
*.log_archive_dest_2='service=orcldg LGWR ASYNC'
*.log_file_name_convert='/u01/app/oracle/oradata/orcl','/u01/app/oracle/oradata/orcldg' # 与主库相反
*.memory_target=780140544
*.open_cursors=300
*.processes=150
*.remote_login_passwordfile='EXCLUSIVE'
*.standby_file_management='AUTO'
*.undo_tablespace='UNDOTBS1'
"initorcldg.ora" 30L, 1212C written
创建目录:
[oracle@centos6_dg dbs]$ cd /u01/app/oracle/admin/orcldg/adump
-bash: cd: /u01/app/oracle/admin/orcldg/adump: No such file or directory
[oracle@centos6_dg dbs]$ mkdir -p /u01/app/oracle/admin/orcldg/adump
[oracle@centos6_dg dbs]$ cd /u01/app/oracle/oradata/orcldg
[oracle@centos6_dg orcldg]$ cd /u01/app/oracle/fast_recovery_area/orcldg
-bash: cd: /u01/app/oracle/fast_recovery_area/orcldg: No such file or directory
[oracle@centos6_dg orcldg]$ mkdir -p /u01/app/oracle/fast_recovery_area/orcldg
四. 启动备库实例
SQL> startup nomount;
ORACLE instance started.
Total System Global Area 776646656 bytes
Fixed Size 2257272 bytes
Variable Size 507514504 bytes
Database Buffers 264241152 bytes
Redo Buffers 2633728 bytes
SQL> create spfile from pfile; # 根据pfile创建spfile,使用rman复制备库必须使用spfile
File created.
SQL> shutdown immediate
ORA-01507: database not mounted
ORACLE instance shut down.
SQL> startup nomount;
ORACLE instance started.
Total System Global Area 776646656 bytes
Fixed Size 2257272 bytes
Variable Size 507514504 bytes
Database Buffers 264241152 bytes
Redo Buffers 2633728 bytes
五. 检查主备库的监听及TNS
[oracle@centos6_dg admin]$ sqlplus sys/oracle@orcl as sysdba
[oracle@centos6_dg admin]$ sqlplus sys/oracle@orcldg as sysdba
[oracle@centos6 admin]$ sqlplus sys/oracle@orcl as sysdba
[oracle@centos6 admin]$ sqlplus sys/oracle@orcl as sysdba
如果访问不了,多半是防火墙的问题咯
六. 使用rman开始复制
[oracle@centos6 dbs]$ rman target sys/oracle@orcl auxiliary sys/oracle@orcldg
Recovery Manager: Release 11.2.0.4.0 - Production on Sun Nov 27 13:08:51 2016
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
connected to target database: ORCL (DBID=1448896496)
connected to auxiliary database: ORCL (not mounted)
RMAN> duplicate target database for standby from active database; #如果主备库文件路径一样,需要加上nofilenamecheck参数 for standby nofilenamecheck
Starting Duplicate Db at 2016-11-27 13:09:09
using target database control file instead of recovery catalog
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=20 device type=DISK
contents of Memory Script:
{
backup as copy reuse
targetfile '/u01/app/oracle/product/11.2.0/dbs/orapworcl' auxiliary format
'/u01/app/oracle/product/11.2.0/db_1/dbs/orapworcldg' ;
}
executing Memory Script
Starting backup at 2016-11-27 13:09:10
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=41 device type=DISK
Finished backup at 2016-11-27 13:09:11
contents of Memory Script:
{
backup as copy current controlfile for standby auxiliary format '/u01/app/oracle/oradata/orcldg/std_control01.ctl';
restore clone controlfile to '/u01/app/oracle/fast_recovery_area/orcldg/std_control02.ctl' from
'/u01/app/oracle/oradata/orcldg/std_control01.ctl';
}
executing Memory Script
Starting backup at 2016-11-27 13:09:11
using channel ORA_DISK_1
channel ORA_DISK_1: starting datafile copy
copying standby control file
output file name=/u01/app/oracle/product/11.2.0/dbs/snapcf_orcl.f tag=TAG20161127T130911 RECID=2 STAMP=929020152
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:03
Finished backup at 2016-11-27 13:09:14
Starting restore at 2016-11-27 13:09:14
using channel ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: copied control file copy
Finished restore at 2016-11-27 13:09:15
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/orcldg/temp01.dbf";
switch clone tempfile all;
set newname for datafile 1 to
"/u01/app/oracle/oradata/orcldg/system01.dbf";
set newname for datafile 2 to
"/u01/app/oracle/oradata/orcldg/sysaux01.dbf";
set newname for datafile 3 to
"/u01/app/oracle/oradata/orcldg/undotbs01.dbf";
set newname for datafile 4 to
"/u01/app/oracle/oradata/orcldg/users01.dbf";
set newname for datafile 5 to
"/u01/app/oracle/oradata/orcldg/example01.dbf";
backup as copy reuse
datafile 1 auxiliary format
"/u01/app/oracle/oradata/orcldg/system01.dbf" datafile
2 auxiliary format
"/u01/app/oracle/oradata/orcldg/sysaux01.dbf" datafile
3 auxiliary format
"/u01/app/oracle/oradata/orcldg/undotbs01.dbf" datafile
4 auxiliary format
"/u01/app/oracle/oradata/orcldg/users01.dbf" datafile
5 auxiliary format
"/u01/app/oracle/oradata/orcldg/example01.dbf" ;
sql 'alter system archive log current';
}
executing Memory Script
executing command: SET NEWNAME
renamed tempfile 1 to /u01/app/oracle/oradata/orcldg/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 2016-11-27 13:09:22
using channel ORA_DISK_1
channel ORA_DISK_1: starting datafile copy
input datafile file number=00001 name=/u01/app/oracle/oradata/orcl/system01.dbf
output file name=/u01/app/oracle/oradata/orcldg/system01.dbf tag=TAG20161127T130922
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:55
channel ORA_DISK_1: starting datafile copy
input datafile file number=00002 name=/u01/app/oracle/oradata/orcl/sysaux01.dbf
output file name=/u01/app/oracle/oradata/orcldg/sysaux01.dbf tag=TAG20161127T130922
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:35
channel ORA_DISK_1: starting datafile copy
input datafile file number=00005 name=/u01/app/oracle/oradata/orcl/example01.dbf
output file name=/u01/app/oracle/oradata/orcldg/example01.dbf tag=TAG20161127T130922
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:25
channel ORA_DISK_1: starting datafile copy
input datafile file number=00003 name=/u01/app/oracle/oradata/orcl/undotbs01.dbf
output file name=/u01/app/oracle/oradata/orcldg/undotbs01.dbf tag=TAG20161127T130922
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:15
channel ORA_DISK_1: starting datafile copy
input datafile file number=00004 name=/u01/app/oracle/oradata/orcl/users01.dbf
output file name=/u01/app/oracle/oradata/orcldg/users01.dbf tag=TAG20161127T130922
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01
Finished backup at 2016-11-27 13:11:33
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=928907962 file name=/u01/app/oracle/oradata/orcldg/system01.dbf
datafile 2 switched to datafile copy
input datafile copy RECID=3 STAMP=928907962 file name=/u01/app/oracle/oradata/orcldg/sysaux01.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=4 STAMP=928907962 file name=/u01/app/oracle/oradata/orcldg/undotbs01.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=5 STAMP=928907962 file name=/u01/app/oracle/oradata/orcldg/users01.dbf
datafile 5 switched to datafile copy
input datafile copy RECID=6 STAMP=928907962 file name=/u01/app/oracle/oradata/orcldg/example01.dbf
Finished Duplicate Db at 2016-11-27 13:11:48
六. 在备库应用日志
SQL> select status from v$instance; # 备库已经处于Mount状态了
STATUS
------------
MOUNTED
SQL> alter database recover managed standby database disconnect from session;
Database altered.
七. 使用broker工具
1. 设置dg_broker_start为true
SQL> alter system set dg_broker_start=true;
System altered.
备库:
SQL> alter system set dg_broker_start=true;
System altered.
2. 连接broker
[oracle@centos6_dg dbs]$ dgmgrl sys/oracle@orcl
DGMGRL for Linux: Version 11.2.0.4.0 - 64bit Production
Copyright (c) 2000, 2009, Oracle. All rights reserved.
Welcome to DGMGRL, type "help" for information.
Connected.
DGMGRL> CREATE CONFIGURATION c1 AS # 创建配置
> PRIMARY DATABASE IS orcl
> CONNECT IDENTIFIER IS orcl;
Configuration "c1" created withprimary database "orcl"
DGMGRL> ADD DATABASE orcldg AS CONNECT IDENTIFIER IS orcldg #添加备库
> ;
Database "orcldg" added
DGMGRL> enable configuration; # 使配置生效
Enabled.
DGMGRL> show configuration; # 查看配置是否成功
Configuration - c1
Protection Mode: MaxPerformance
Databases:
orcl - Primary database
orcldg - Physical standby database
Fast-Start Failover: DISABLED
Configuration Status:
SUCCESS
此时备库的状态:
SQL> select database_role,open_mode from v$database;
DATABASE_ROLE OPEN_MODE
---------------- --------------------
PHYSICAL STANDBY READ ONLY
SQL> insert into test values(2,'bbb'); # 此时备库是无法写数据进去的
insert into test values(2,'bbb')
*
ERROR at line 1:
ORA-16000: database open for read-only access
八. 把备库当测试库使用
1. (备库)开启闪回
SQL> select flashback_on from v$database;
FLASHBACK_ON
------------------
NO
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount;
ORACLE instance started.
Total System Global Area 776646656 bytes
Fixed Size 2257272 bytes
Variable Size 507514504 bytes
Database Buffers 264241152 bytes
Redo Buffers 2633728 bytes
Database mounted.
SQL> alter database flashback on;
Database altered.
SQL> alter database open;
Database altered.
2. 将备库改为snapshot standby
DGMGRL> convert database orcldg to snapshot standby;
Converting database "orcldg" to a Snapshot Standby database, please wait...
Database "orcldg" converted successfully
3. 验证
SQL> insert into test values(2,'bbb') # 已经可以写数据到备库,但是主库是没有这些数据的。依赖于oracle的闪回特性
2 ;
1 row created.
SQL> commit;
Commit complete.
DGMGRL> show configuration; # 再看下此时的配置
Configuration - c1
Protection Mode: MaxPerformance
Databases:
orcl - Primary database
orcldg - Snapshot standby database
Fast-Start Failover: DISABLED
Configuration Status:
SUCCESS
4. 把snap shot standby切换回物理备库
DGMGRL> convert database orcldg to physical standby;
Converting database "orcldg" to a Physical Standby database, please wait...
Operation requires shutdown of instance "orcldg" on database "orcldg"
Shutting down instance "orcldg"...
Database closed.
Database dismounted.
ORACLE instance shut down.
Operation requires startup of instance "orcldg" on database "orcldg"
Starting instance "orcldg"...
ORACLE instance started.
Database mounted.
Continuing to convert database "orcldg" ...
Operation requires shutdown of instance "orcldg" on database "orcldg"
Shutting down instance "orcldg"...
ORA-01109: database not open
Database dismounted.
ORACLE instance shut down.
Operation requires startup of instance "orcldg" on database "orcldg"
Starting instance "orcldg"...
ORACLE instance started.
Database mounted.
Database "orcldg" converted successfully
此时在看刚才备库上插入的数据已经没有了
SQL> select * from test;
ID NAME
---------- ------------------------------
1 aaa
SQL> select open_mode,database_role from v$database;
OPEN_MODE DATABASE_ROLE
-------------------- ----------------
READ ONLY WITH APPLY PHYSICAL STANDBY
九. 将备库切换为主库
DGMGRL> switchover to orcldg;
Performing switchover NOW, please wait...
Operation requires a connection to instance "orcldg" on database "orcldg"
Connecting to instance "orcldg"...
Connected.
New primary database "orcldg" is opening...
Operation requires startup of instance "orcl" on database "orcl"
Starting instance "orcl"...
ORACLE instance started.
Database mounted.
Database opened.
Switchover succeeded, new primary is "orcldg"
SQL> select open_mode,database_role from v$database; # 主库
OPEN_MODE
------------------------------------------------------------
DATABASE_ROLE
------------------------------------------------
READ ONLY WITH APPLY
PHYSICAL STANDBY