1. 程式人生 > >Oracle11g Dataguard配置

Oracle11g Dataguard配置

----------------------配置環境----------------------------------------------------
主庫
主機名: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
-------------------------------------------------------------------------------------

一. 作業系統環境配置

新增主備庫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-09

1. 配置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
[email protected]'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
[email protected]'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
[email protected]'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
[email protected]'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
[email protected]'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