Oracle DataGuard 11g 雙機實驗

空白葛發表於2016-11-18

|作業系統 | release 6.7 | release 6.7 |

|主機名 | stuaapp01 | stuaapp02 |
|IP | 192.168.20.234 | 192.168.20.235 |
|資料庫軟體版本 | oracle 11.2.0.4.0 | oracle 11.2.0.4.0 |
|ORACLE_BASE | /u01/app/oracle/ | /u01/app/oracle/ |
|ORACLE_HOME |$ORACLE_BASE/product/11.2.0/db_1 | $ORACLE_BASE/product/11.2.0/db_1 |
|ORACLE_SID | orcl | |
|閃回區 | 4G | |
|歸檔 | 開啟 | |
---------------------------------------------------------------------------------------------
檢視資料庫版本
SQL> select * from v$version;
一.Primary 資料庫配置及相關操作
1.確認primary庫處於歸檔模式
2.將primary庫置為FORCE LOGGING 模式
3.新增STANDBY日誌檔案
4.建立primary庫客戶端初始化引數檔案
1).建立主庫中的pfile
2).備份到backup目錄用於建立備庫的pfile
3).修改後主庫pfile中內容如下
4).通過pfile 重建spfile
5).修改監聽配置檔案
6).配置tnsnames.ora檔案
7).啟動資料庫,測試
5.rman備份資料庫,在閃回區中
二.Standby資料庫配置及相關操作
1.建立所需目錄(注意OMF管理的檔案)
2.複製資料檔案到standby庫對應的目錄
1).拷貝閃回區內容
2).拷貝引數檔案
3).拷貝密碼檔案
4).拷貝監聽檔案和tns檔案
3.修改相應配置
1).修改監聽配置檔案
2).修改TNS配置檔案
3).重啟監聽服務
4).standby的初始化引數如下
5).通過該pfile 建立spfile
4.恢復資料庫
5.啟動redo 應用
6.驗證
7.切換到只讀模式
8.切換到同步模式(不需要停庫)

 

一.Primary 資料庫配置及相關操作
1.確認primary庫處於歸檔模式
SQL> archive log list;
Database log mode Archive Mode
Automatic archival Enabled
Archive destination USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence 2
Next log sequence to archive 4
Current log sequence 4

2.將primary庫置為FORCE LOGGING 模式
SQL> alter database force logging;

SQL> select force_logging from v$database;

FOR
---
YES

Database altered.

3.新增STANDBY日誌檔案
alter database add standby logfile group 4 ('/u01/app/oracle/oradata/orcl/redo04.log') size 50m;
alter database add standby logfile group 5 ('/u01/app/oracle/oradata/orcl/redo05.log') size 50m;
alter database add standby logfile group 6 ('/u01/app/oracle/oradata/orcl/redo06.log') size 50m;
alter database add standby logfile group 7 ('/u01/app/oracle/oradata/orcl/redo07.log') size 50m;


4.建立primary庫客戶端初始化引數檔案
1).建立主庫中的pfile
SQL> create pfile from spfile;

File created.

2).備份到backup目錄用於建立備庫的pfile
[oracle@rac1 dbs]$ pwd
/u01/app/oracle/product/11.2.0/db_1/dbs
[oracle@rac1 dbs]$ cp ./initorcl.ora /home/oracle/backup/

3).修改後主庫pfile中內容如下
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=318767104
orcl.__sga_target=469762048
orcl.__shared_io_pool_size=0
orcl.__shared_pool_size=121634816
orcl.__streams_pool_size=0
*.audit_file_dest='/u01/app/oracle/admin/orcl/adump'
*.audit_trail='db'
*.compatible='11.2.0.4.0'
*.control_files='/u01/app/oracle/oradata/orcl/control01.ctl','/u01/app/oracle/fast_recovery_area/orcl/control02.ctl'
*.db_block_size=8192
*.db_domain=''
*.db_name='orcl'
*.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_format='%t_%s_%r.dbf'
*.memory_target=786432000
*.open_cursors=300
*.processes=150
*.remote_login_passwordfile='EXCLUSIVE'
*.undo_tablespace='UNDOTBS1'
#################################################################
#Parameters for Primary Database.
#################################################################
*.DB_NAME='orcl'
*.DB_UNIQUE_NAME=orcl
*.LOG_ARCHIVE_FORMAT=log%t_%s_%r.arc
*.LOG_ARCHIVE_CONFIG='DG_CONFIG=(orcl,orcldg)'
*.LOG_ARCHIVE_DEST_1='LOCATION=/u01/app/oracle/archivelog VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=orcl'
*.LOG_ARCHIVE_DEST_2='SERVICE=orcldg LGWR ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=orcldg'
*.LOG_ARCHIVE_DEST_STATE_1=ENABLE
*.LOG_ARCHIVE_DEST_STATE_2=ENABLE
*.REMOTE_LOGIN_PASSWORDFILE=EXCLUSIVE
*.standby_file_management=auto

#################################################################
#Parameters which using for switch over from Primary to Standby.
#################################################################
*.FAL_SERVER=orcldg
*.FAL_CLIENT=orcl
*.DB_FILE_NAME_CONVERT='/u01/app/oracle/oradata/orcldg','/u01/app/oracle/oradata/orcl'
*.log_file_name_convert='/u01/app/oracle/oradata/orcldg','/u01/app/oracle/oradata/orcl'
*.standby_archive_dest='/u01/app/oracle/archive_log'

4).通過pfile 重建spfile
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.

SQL> create spfile from pfile='initorcl.ora';

File created.

5).修改監聽配置檔案
# listener.ora Network Configuration File: /u01/app/oracle/product/11.2.0/db_1/network/admin/listener.ora
# Generated by Oracle configuration tools.

LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.20.241)(PORT = 1521))
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
)
)

ADR_BASE_LISTENER = /u01/app/oracle
6).配置tnsnames.ora檔案
[oracle@rac1 admin]$ pwd
/u01/app/oracle/product/11.2.0/db_1/network/admin
orcl =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.20.234)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcl)
)
)

orcldg =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.20.235)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcldg)
)
)

EXTPROC_CONNECTION_DATA =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC0))
)
(CONNECT_DATA =
(SID = PLSExtProc)
(PRESENTATION = RO)
)
)
7).啟動資料庫,測試
[oracle@rac1 admin]$ tnsping orcl

TNS Ping Utility for Linux: Version 11.2.0.4.0 - Production on 17-NOV-2016 19:22:52

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

Used parameter files:


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

alter database set standby database to maximize availability;
5.rman備份資料庫,在閃回區中
backup database plus archivelog;
backup current controlfile for standby;

二.Standby資料庫配置及相關操作

1.建立所需目錄(注意OMF管理的檔案)
show parameter dest
mkdir -p /u01/app/oracle/admin/orcl/adump
mkdir -p /u01/app/oracle/admin/orcl/dpdump
mkdir -p /u01/app/oracle/diag/rdbms/orcl/orcldg/trace
mkdir -p /u01/app/oracle/diag/rdbms/orcl/orcldg/cdump
mkdir -p /u01/app/oracle/flash_recovery_area
mkdir -p /u01/app/oracle/archivelog
mkdir -p /u01/app/oracle/archive_log
mkdir -p /u01/app/oracle/fast_recovery_area

2.複製資料檔案到standby庫對應的目錄
從主資料庫伺服器上拷貝檔案
1).拷貝閃回區內容
scp -r ./* 192.168.20.235:/u01/app/oracle/fast_recovery_area/

2).拷貝引數檔案
scp ./* 192.168.20.235:/u01/app/oracle/product/11.2.0/dbhome_1/dbs

3).拷貝密碼檔案
[oracle@stuaapp01 dbs]$ scp orapworcl 192.168.20.235:/u01/app/oracle/product/11.2.0/dbhome_1/dbs/

4).拷貝監聽檔案和tns檔案
scp *.ora 192.168.20.235:/u01/app/oracle/product/11.2.0/dbhome_1/network/admin/

3.修改相應配置

1).修改監聽配置檔案
[oracle@stuaapp02 admin]$ vi listener.ora

# listener.ora Network Configuration File: /u01/app/oracle/product/11.2.0/dbhome_1/network/admin/listener.ora
# Generated by Oracle configuration tools.

LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.20.235)(PORT = 1521))
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
)
)

ADR_BASE_LISTENER = /u01/app/oracle

2).修改TNS配置檔案


3).重啟監聽服務
lsnrctl stop
lsnrctl start

4).standby的初始化引數如下
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=318767104
orcl.__sga_target=469762048
orcl.__shared_io_pool_size=0
orcl.__shared_pool_size=121634816
orcl.__streams_pool_size=0
*.audit_file_dest='/u01/app/oracle/admin/orcl/adump'
*.audit_trail='db'
*.compatible='11.2.0.4.0'
*.control_files='/u01/app/oracle/oradata/orcl/control01.ctl','/u01/app/oracle/fast_recovery_area/orcl/control02.ctl'
*.db_block_size=8192
*.db_domain=''
*.db_name='orcl'
*.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_format='%t_%s_%r.dbf'
*.memory_target=786432000
*.open_cursors=300
*.processes=150
*.remote_login_passwordfile='EXCLUSIVE'
*.undo_tablespace='UNDOTBS1'
#################################################################
#Parameters for Standby Database.
#################################################################
*.DB_NAME='orcl'
*.DB_UNIQUE_NAME=orcldg
*.LOG_ARCHIVE_FORMAT=log%t_%s_%r.arc
*.LOG_ARCHIVE_CONFIG='DG_CONFIG=(orcl,orcldg)'
*.DB_FILE_NAME_CONVERT='/u01/app/oracle/oradata/orcl','/u01/app/oracle/oradata/orcldg'
*.LOG_FILE_NAME_CONVERT='/u01/app/oracle/oradata/orcl','/u01/app/oracle/oradata/orcldg'
*.STANDBY_ARCHIVE_DEST='/u01/app/oracle/archive_log'
*.FAL_SERVER=orcl
*.FAL_CLIENT=orcldg
*.STANDBY_FILE_MANAGEMENT=AUTO

#################################################################
#Parameters which using for switch over from Standby to Primary.
#################################################################
*.LOG_ARCHIVE_DEST_1='LOCATION=/u01/app/oracle/archivelog VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=orcldg'
*.LOG_ARCHIVE_DEST_2='SERVICE=orcl LGWR ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=orcl'
*.LOG_ARCHIVE_DEST_STATE_1=ENABLE
*.LOG_ARCHIVE_DEST_STATE_2=ENABLE
*.REMOTE_LOGIN_PASSWORDFILE=EXCLUSIVE

5).通過該pfile 建立spfile
SQL> create spfile from pfile= 'initorcldg.ora';

File created.
4恢復資料庫
啟動備庫到nomount
startup nomount
[oracle@dg2 admin]$ rman target sys/oracle@orcl auxiliary /
RMAN> duplicate target database for standby nofilenamecheck;
RMAN> exit
關閉資料庫
shutdown immediate




5.啟動redo 應用
startup nomount;
alter database mount standby database;

SQL> alter database recover managed standby database using current logfile disconnect from session;

Database altered.

6.驗證
主庫
SQL> archive log list
Database log mode Archive Mode
Automatic archival Enabled
Archive destination /u01/app/oracle/archivelog
Oldest online log sequence 73
Next log sequence to archive 75
Current log sequence 75
備庫
SQL> archive log list
Database log mode Archive Mode
Automatic archival Enabled
Archive destination /u01/app/oracle/archivelog
Oldest online log sequence 70
Next log sequence to archive 0
Current log sequence 75
7.切換到只讀模式
SQL> alter database recover managed standby database cancel;

Database altered.
SQL> alter database open read only;

Database altered.
8.切換到同步模式(不需要停庫)
SQL> alter database recover managed standby database using current logfile disconnect from session;

Database altered.

相關文章