正式生產庫,配置雙節點的RAC + 單例項的 DATAGUARD
阿新 • • 發佈:2019-01-05
正式生產庫,配置DATAGUARD
RAC+單例項DATAGUARD 配置
RAC 兩節點:
192.1.0.101 rac1
192.1.0.102 rac2
儲存:ASM
DB_UNIQUE_NAME= racdb
例項:racdb1; racdb2;
DG:
192.1.0.103 dg1
儲存 :ASM
資料庫名: racdb
DB_UNIQUE_NAME=stbdb;
一、系統準備
1.1 DG 磁碟分割槽:
本地磁碟,磁碟分割槽ASM DISK 對照表
磁碟分割槽 磁碟大小 RAID ASM NAME ASM GROUPDISKNAME
-----------------------------------------------------------------
/dev/sdb
/dev/sdb1 300 GB RAID5 RECOVERY1 +RECOVERY
/dev/sdb2 300 GB RAID5 RECOVERY2 +RECOVERY
/dev/sdb3 4023.1 GB RAID5 RECOVERY3 +RECOVERY
/dev/sdc1 899.5 MB RAID0 DATA1 +DATA
/dev/sdd1 899.5 GB RAID0 DATA2 +DATA
/dev/sde1 899.5 GB RAID0 DATA3 +DATA
/dev/sdf1 899.5 GB RAID0 DATA4 +DATA
/dev/sdg1 899.5 GB RAID0 DATA5 +DATA
/dev/sdb 為多個小盤合併成為一個RAID5的磁碟,因考慮到多個小盤(8*146G)多分割槽不好管理,
同時這幾個多個小盤已使用了2年左右,合併一起做RAID5也可以做個容錯處理。
1.2 做一個SSH對待訪問
#在dg1上執行建立私匙,以方便拷貝檔案
# su - oracle
$ mkdir ~/.ssh
$ ssh-keygen -t rsa
$ ssh-keygen -t dsa
#將dg1的加入
$ ssh dg1 cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
$ ssh dg1 cat ~/.ssh/id_dsa.pub >> ~/.ssh/authorized_keys
$ scp ~/.ssh/authorized_keys dg1:~/.ssh/authorized_keys
(遇到一個問題:
[ [email protected] .ssh]$ ssh dg1 date
Warning: the RSA host key for 'dg1' differs from the key for the IP address '192.1.0.103'
Offending key for IP in /home/oracle/.ssh/known_hosts:15
Matching host key in /home/oracle/.ssh/known_hosts:17
Are you sure you want to continue connecting (yes/no)? yes
2013年 10月 12日 星期六 11:39:08 CST
解決方法:
檢視known_hosts 內容,發現'192.1.0.103' 以前指定了其它的伺服器,直接刪除對應的其它伺服器行。
問題解決。
)
還有一個有趣的問題,在RAC1中配置了ssh 對等訪問,系統會自動更新到其它的RAC節點中,比如我這裡有RAC2;
在單機上先安裝一個GRID(ASM),再安裝ORACLE.
1.3 安裝GRID
【】為獨立伺服器配置ORACLE GRID INFRASTRUCTURE
安裝此項選擇,還要選擇一個ASM磁碟,是開始時沒想到的。後來另外分出兩個分割槽做ASM特徵盤,
有點象RAC中的RAC表決盤(或OCR磁碟)。
ora.asm ora.asm.type ONLINE ONLINE dg1
ora.cssd ora.cssd.type ONLINE ONLINE dg1
ora.diskmon ora....on.type OFFLINE OFFLINE
ora.evmd ora.evm.type ONLINE ONLINE dg1
ora.ons ora.ons.type OFFLINE OFFLINE
[[email protected] ~]$
1.3,1.4 兩個安裝參考:
http://blog.csdn.net/miyatang/article/details/6659839
先前測試的配置日誌(http://blog.csdn.net/miyatang/article/details/9979579)
二、資料庫配置
2.1 監聽/ASM 配置
2.1.1 listener.ora
[[email protected] admin]$ cat listener.ora
# listener.ora Network Configuration File: /opt/app/oracle/product/11.2.0/network/admin/listener.ora
# Generated by Oracle configuration tools.
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.1.0.103)(PORT = 1521))
)
)
2.1.2 tnsnames.ora
[[email protected] admin]$ cat tnsnames.ora
# tnsnames.ora Network Configuration File: /opt/app/oracle/product/11.2.0/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.
RACDB1 =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.1.0.101)(PORT = 1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.1.0.111)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = racdb)
(INSTANCE_NAME = racdb1)
)
)
RACDB =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = rac-scan)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = racdb)
)
)
RACDB2 =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.1.0.102)(PORT = 1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.1.0.112)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = racdb)
(INSTANCE_NAME = racdb2)
)
)
stbdb =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.1.0.103)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = stbdb)
)
)
把stbdb 部分插入到兩個節點的 tnsnames.ora 檔案中。
2.1.3 grid 使用者下,使用asmca 建立 +DATA,+RECOVERY 兩個ASM 磁碟組。
測試檢視ASM 磁碟組:
[[email protected] grid]$ asmcmd
Connected to an idle instance.
ASMCMD> ls
ASMCMD-8102: no connection to ASM; command requires ASM to run
修改grid 使用者下的.bash_profile
ORACLE_SID=+ASM; export ORACLE_SID (原為:ORACLE_SID=+ASM1; 此內容為RAC中拷貝而來有兩個例項ASM1,ASM2.)
PATH=$ORACLE_HOME/bin:$PATH; export PATH
修改後問題解決:
[[email protected] grid]$ asmcmd
ASMCMD> ls
CRS/
DATA/
RECOVERY/
ASMCMD> exit
2.2.配置引數:
2.2.1、開啟Forced Logging模式
SQL> alter database force logging;
Database altered.
2.2.2
SQL> alter system set log_archive_config='DG_CONFIG=(stbdb,racdb)';
SQL> ALTER SYSTEM SET LOG_ARCHIVE_MAX_PROCESSES=30;
SQL> ALTER SYSTEM SET REMOTE_LOGIN_PASSWORDFILE=EXCLUSIVE SCOPE=SPFILE;
SQL> ALTER SYSTEM SET FAL_SERVER=stbdb;
SQL> alter system set FAL_CLIENT=racdb;
SQL> alter system set standby_file_management=auto;
ALTER SYSTEM SET LOG_ARCHIVE_DEST_2='SERVICE=stbdb LGWR SYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=stbdb' scope=both;
ALTER SYSTEM SET LOG_ARCHIVE_DEST_STATE_2=DEFER;
--先設定成不活動的,後面再修改成: ENABLE;
--ALTER SYSTEM SET LOG_ARCHIVE_DEST_STATE_2 = ENABLE scope=both;
#新增STANDBY LOGFILE:
select group#,THREAD#,l.MEMBERS,l.STATUS from v$log l
GROUP# THREAD# MEMBERS STATUS
1 1 1 2 INACTIVE
2 2 1 2 CURRENT
3 3 2 2 CURRENT
4 4 2 2 ACTIVE
5 5 1 2 ACTIVE
6 6 2 2 ACTIVE
alter database add STANDBY logfile thread 1 group 7 ;
alter database add STANDBY logfile thread 1 group 8 ;
alter database add STANDBY logfile thread 1 group 9 ;
alter database add STANDBY logfile thread 2 group 10 ;
alter database add STANDBY logfile thread 2 group 11 ;
alter database add STANDBY logfile thread 2 group 12 ;
#2.2 生成pfile,並修改。
SQL> create pfile='/tmp/initstbdb.ora' from spfile;
1.修改
*.audit_file_dest='/opt/app/oracle/admin/racdb/adump'
修改後:
*.audit_file_dest='/opt/app/oracle/admin/stbdb/adump'
建立目錄 :
mkdir -p /opt/app/oracle/admin/stbdb/adump
chown oracle:oinstall /opt/app/oracle/admin/stbdb/adump
2.新增以下內容:
*.db_file_name_convert='+DATA/racdb/datafile','+DATA/stbdb/datafile','+DATA/racdb/tempfile','+DATA/stbdb/tempfile'
*.LOG_FILE_NAME_CONVERT='+DATA/racdb/onlinelog','+DATA/stbdb/onlinelog','+RECOVERY/racdb/onlinelog' ,'+RECOVERY/stbdb/onlinelog'
修改前的 initstbdb.ora
racdb1.__db_cache_size=13623099392
racdb2.__db_cache_size=13623099392
racdb2.__java_pool_size=67108864
racdb1.__java_pool_size=67108864
racdb2.__large_pool_size=67108864
racdb1.__large_pool_size=67108864
racdb1.__oracle_base='/opt/app/oracle'#ORACLE_BASE set from environment
racdb2.__oracle_base='/opt/app/oracle'#ORACLE_BASE set from environment
racdb2.__pga_aggregate_target=9462349824
racdb1.__pga_aggregate_target=9462349824
racdb2.__sga_target=17582522368
racdb1.__sga_target=17582522368
racdb2.__shared_io_pool_size=0
racdb1.__shared_io_pool_size=0
racdb1.__shared_pool_size=3556769792
racdb2.__shared_pool_size=3690987520
racdb2.__streams_pool_size=0
racdb1.__streams_pool_size=67108864
*.audit_file_dest='/opt/app/oracle/admin/racdb/adump'
*.audit_trail='NONE'
*.cluster_database=true
*.compatible='11.2.0.0.0'
*.control_files='+DATA/racdb/controlfile/current.267.812303153','+RECOVERY/racdb/controlfile/current.3283.812303153'
*.db_block_size=8192
*.db_create_file_dest='+DATA'
*.db_domain=''
*.db_flashback_retention_target=1440
*.db_name='racdb'
*.db_recovery_file_dest='+RECOVERY'
*.db_recovery_file_dest_size=3221225472000
*.diagnostic_dest='/opt/app/oracle'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=racdbXDB)'
*.fal_client='RACDB'
*.fal_server='DGDB'
racdb2.instance_number=2
racdb1.instance_number=1
*.log_archive_config='DG_CONFIG=(dgdb,racdb)'
*.log_archive_dest_2='SERVICE=dgdb LGWR ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=dgdb'
*.log_archive_dest_state_2='DEFER'
*.log_archive_format='%t_%s_%r.dbf'
*.log_archive_max_processes=30
racdb1.memory_max_target=29360128000
*.memory_target=27031240704
*.nls_language='SIMPLIFIED CHINESE'
*.nls_territory='CHINA'
*.open_cursors=5000
*.processes=8000
*.remote_listener='rac-scan:1521'
*.remote_login_passwordfile='EXCLUSIVE'
*.resource_manager_plan=''
*.session_cached_cursors=100
*.sessions=5000
*.standby_file_management='MANUAL'
racdb2.thread=2
racdb1.thread=1
racdb2.undo_tablespace='UNDOTBS2'
racdb1.undo_tablespace='UNDO_TBS01'
[[email protected] dbs]$
修改後的initstbdb.ora
[[email protected] dbs]$ cat initstbdb.ora
stbdb.__db_cache_size=13623099392
stbdb.__java_pool_size=67108864
stbdb.__large_pool_size=67108864
stbdb.__oracle_base='/opt/app/oracle'#ORACLE_BASE set from environment
stbdb.__pga_aggregate_target=9462349824
stbdb.__sga_target=17582522368
stbdb.__shared_io_pool_size=0
stbdb.__shared_pool_size=3556769792
stbdb.__streams_pool_size=67108864
*.audit_file_dest='/opt/app/oracle/admin/stbdb/adump'
*.audit_trail='NONE'
*.compatible='11.2.0.0.0'
*.control_files='+DATA/racdb/controlfile/current.267.812303153','+RECOVERY/racdb/controlfile/current.3283.812303153'
*.db_block_size=8192
*.db_create_file_dest='+DATA'
*.db_domain=''
*.db_flashback_retention_target=1440
*.db_name='racdb'
db_unique_name='stbdb'
*.db_recovery_file_dest='+RECOVERY'
*.db_recovery_file_dest_size=900000000000
*.diagnostic_dest='/opt/app/oracle'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=stbdb)'
*.fal_client='STBDB'
*.fal_server='RACDB1,RACDB2'
stbdb.instance_number=1
*.db_file_name_convert='+DATA/racdb/datafile','+DATA/stbdb/datafile','+DATA/racdb/tempfile','+DATA/stbdb/tempfile'
*.LOG_FILE_NAME_CONVERT='+DATA/racdb/onlinelog','+DATA/stbdb/onlinelog','+RECOVERY/racdb/onlinelog' ,'+RECOVERY/stbdb/onlinelog'
*.log_archive_config='DG_CONFIG=(dgdb,racdb)'
*.log_archive_dest_2='SERVICE=dgdb LGWR ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=dgdb'
*.log_archive_dest_state_2='DEFER'
*.log_archive_format='%t_%s_%r.dbf'
*.log_archive_max_processes=30
stbdb.memory_max_target=29360128000
*.memory_target=27031240704
*.nls_language='SIMPLIFIED CHINESE'
*.nls_territory='CHINA'
*.open_cursors=5000
*.processes=8000
*.remote_listener='stbdb:1521'
*.remote_login_passwordfile='EXCLUSIVE'
*.resource_manager_plan=''
*.session_cached_cursors=100
*.sessions=5000
*.standby_file_management='AUTO'
thread=1
undo_tablespace='UNDOTBS1'
#2.3建立控制檔案 :
切換兩次日誌及做兩次歸檔
SQL> alter system switch logfile;
System altered.
SQL> alter system switch logfile;
System altered.
SQL> alter system archive log current;
System altered.
SQL> alter system archive log current;
System altered.
SQL> alter database create standby controlfile as '/tmp/control01.ctl';
Database altered.
#2.4建立密碼檔案
[[email protected] ~]$ orapwd file=/tmp/orapwstbdb.ora password=sa force=y ignorecase=y
#2.5把檔案拷貝到 dg1 伺服器:
scp /tmp/orapwstbdb.ora dg1:/opt/app/oracle/product/11.2.0/dbs/orapwstbdb.ora
scp /tmp/inittdb.ora dg1:/tmp/inittdb.ora
#2.6 在STANDBY 端
SQL> create spfile from pfile='/tmp/inittdb.ora';
File created.
SQL> startup nomount;
[[email protected] dbs]$ rman target sys/[email protected] auxiliary sys/[email protected] nocatalog
rman>duplicate target database for standby from active database nofilenamecheck;
三、DATAGUARD 開啟
SQL> alter database recover managed standby database disconnect from session;
Database altered.
# 開啟STANDBY 資料庫
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE;
#啟用STANDBY資料庫,進入RECOVER模式:
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE DISCONNECT FROM SESSION;
#啟動到只讀模式:
alter database open read only;
#轉換到REAL-TIME模式下:
--alter database recover managed standby database cancel;
--ALTER DATABASE OPEN;
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE USING CURRENT LOGFILE DISCONNECT from session;
四、測試驗證
#PRIMARY 端:
SQL>
SQL> select thread#,sequence#,status from v$log;
THREAD# SEQUENCE# STATUS
---------- ---------- ----------------
1 57930 CURRENT
1 57929 INACTIVE
2 43251 INACTIVE
2 43252 ACTIVE
1 57928 INACTIVE
2 43253 CURRENT
6 rows selected.
SQL>
#STANDBY 端
SQL> select archived_thread#,archived_seq#,APPLIED_THREAD#,APPLIED_SEQ# from v$archive_dest_status;
ARCHIVED_THREAD# ARCHIVED_SEQ# APPLIED_THREAD# APPLIED_SEQ#
---------------- ------------- --------------- ------------
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
2 43252 2 43252
RAC+單例項DATAGUARD 配置
RAC 兩節點:
192.1.0.101 rac1
192.1.0.102 rac2
儲存:ASM
DB_UNIQUE_NAME= racdb
例項:racdb1; racdb2;
DG:
192.1.0.103 dg1
儲存 :ASM
資料庫名: racdb
DB_UNIQUE_NAME=stbdb;
一、系統準備
1.1 DG 磁碟分割槽:
本地磁碟,磁碟分割槽ASM DISK 對照表
磁碟分割槽 磁碟大小 RAID ASM NAME ASM GROUPDISKNAME
-----------------------------------------------------------------
/dev/sdb
/dev/sdb1 300 GB RAID5 RECOVERY1 +RECOVERY
/dev/sdb2 300 GB RAID5 RECOVERY2 +RECOVERY
/dev/sdb3 4023.1 GB RAID5 RECOVERY3 +RECOVERY
/dev/sdc1 899.5 MB RAID0 DATA1 +DATA
/dev/sdd1 899.5 GB RAID0 DATA2 +DATA
/dev/sde1 899.5 GB RAID0 DATA3 +DATA
/dev/sdf1 899.5 GB RAID0 DATA4 +DATA
/dev/sdg1 899.5 GB RAID0 DATA5 +DATA
/dev/sdb 為多個小盤合併成為一個RAID5的磁碟,因考慮到多個小盤(8*146G)多分割槽不好管理,
同時這幾個多個小盤已使用了2年左右,合併一起做RAID5也可以做個容錯處理。
1.2 做一個SSH對待訪問
#在dg1上執行建立私匙,以方便拷貝檔案
# su - oracle
$ mkdir ~/.ssh
$ ssh-keygen -t rsa
$ ssh-keygen -t dsa
#將dg1的加入
$ ssh dg1 cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
$ ssh dg1 cat ~/.ssh/id_dsa.pub >> ~/.ssh/authorized_keys
$ scp ~/.ssh/authorized_keys dg1:~/.ssh/authorized_keys
(遇到一個問題:
[
Warning: the RSA host key for 'dg1' differs from the key for the IP address '192.1.0.103'
Offending key for IP in /home/oracle/.ssh/known_hosts:15
Matching host key in /home/oracle/.ssh/known_hosts:17
Are you sure you want to continue connecting (yes/no)? yes
2013年 10月 12日 星期六 11:39:08 CST
解決方法:
檢視known_hosts 內容,發現'192.1.0.103' 以前指定了其它的伺服器,直接刪除對應的其它伺服器行。
問題解決。
)
還有一個有趣的問題,在RAC1中配置了ssh 對等訪問,系統會自動更新到其它的RAC節點中,比如我這裡有RAC2;
在單機上先安裝一個GRID(ASM),再安裝ORACLE.
1.3 安裝GRID
【】為獨立伺服器配置ORACLE GRID INFRASTRUCTURE
安裝此項選擇,還要選擇一個ASM磁碟,是開始時沒想到的。後來另外分出兩個分割槽做ASM特徵盤,
有點象RAC中的RAC表決盤(或OCR磁碟)。
安裝完成GRID後,檢視狀態如下:
[[email protected] ~]$ crs_stat -t
Name Type Target State Host
------------------------------------------------------------
ora.CRS.dg ora....up.type ONLINE ONLINE dg1
ora.DATA.dg ora....up.type ONLINE ONLINE dg1
ora....ER.lsnr ora....er.type ONLINE ONLINE dg1
ora....VERY.dg ora....up.type ONLINE ONLINE dg1
ora.asm ora.asm.type ONLINE ONLINE dg1
ora.cssd ora.cssd.type ONLINE ONLINE dg1
ora.diskmon ora....on.type OFFLINE OFFLINE
ora.evmd ora.evm.type ONLINE ONLINE dg1
ora.ons ora.ons.type OFFLINE OFFLINE
[[email protected] ~]$
(紅色部分為新增的ASM 磁碟組)
1.3,1.4 兩個安裝參考:
http://blog.csdn.net/miyatang/article/details/6659839
先前測試的配置日誌(http://blog.csdn.net/miyatang/article/details/9979579)
二、資料庫配置
2.1 監聽/ASM 配置
2.1.1 listener.ora
[[email protected] admin]$ cat listener.ora
# listener.ora Network Configuration File: /opt/app/oracle/product/11.2.0/network/admin/listener.ora
# Generated by Oracle configuration tools.
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.1.0.103)(PORT = 1521))
)
)
2.1.2 tnsnames.ora
[[email protected] admin]$ cat tnsnames.ora
# tnsnames.ora Network Configuration File: /opt/app/oracle/product/11.2.0/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.
RACDB1 =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.1.0.101)(PORT = 1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.1.0.111)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = racdb)
(INSTANCE_NAME = racdb1)
)
)
RACDB =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = rac-scan)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = racdb)
)
)
RACDB2 =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.1.0.102)(PORT = 1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.1.0.112)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = racdb)
(INSTANCE_NAME = racdb2)
)
)
stbdb =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.1.0.103)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = stbdb)
)
)
把stbdb 部分插入到兩個節點的 tnsnames.ora 檔案中。
2.1.3 grid 使用者下,使用asmca 建立 +DATA,+RECOVERY 兩個ASM 磁碟組。
測試檢視ASM 磁碟組:
[[email protected] grid]$ asmcmd
Connected to an idle instance.
ASMCMD> ls
ASMCMD-8102: no connection to ASM; command requires ASM to run
修改grid 使用者下的.bash_profile
ORACLE_SID=+ASM; export ORACLE_SID (原為:ORACLE_SID=+ASM1; 此內容為RAC中拷貝而來有兩個例項ASM1,ASM2.)
PATH=$ORACLE_HOME/bin:$PATH; export PATH
修改後問題解決:
[[email protected] grid]$ asmcmd
ASMCMD> ls
CRS/
DATA/
RECOVERY/
ASMCMD> exit
2.2.配置引數:
2.2.1、開啟Forced Logging模式
SQL> alter database force logging;
Database altered.
2.2.2
SQL> alter system set log_archive_config='DG_CONFIG=(stbdb,racdb)';
SQL> ALTER SYSTEM SET LOG_ARCHIVE_MAX_PROCESSES=30;
SQL> ALTER SYSTEM SET REMOTE_LOGIN_PASSWORDFILE=EXCLUSIVE SCOPE=SPFILE;
SQL> ALTER SYSTEM SET FAL_SERVER=stbdb;
SQL> alter system set FAL_CLIENT=racdb;
SQL> alter system set standby_file_management=auto;
ALTER SYSTEM SET LOG_ARCHIVE_DEST_2='SERVICE=stbdb LGWR SYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=stbdb' scope=both;
ALTER SYSTEM SET LOG_ARCHIVE_DEST_STATE_2=DEFER;
--先設定成不活動的,後面再修改成: ENABLE;
--ALTER SYSTEM SET LOG_ARCHIVE_DEST_STATE_2 = ENABLE scope=both;
#新增STANDBY LOGFILE:
select group#,THREAD#,l.MEMBERS,l.STATUS from v$log l
GROUP# THREAD# MEMBERS STATUS
1 1 1 2 INACTIVE
2 2 1 2 CURRENT
3 3 2 2 CURRENT
4 4 2 2 ACTIVE
5 5 1 2 ACTIVE
6 6 2 2 ACTIVE
alter database add STANDBY logfile thread 1 group 7 ;
alter database add STANDBY logfile thread 1 group 8 ;
alter database add STANDBY logfile thread 1 group 9 ;
alter database add STANDBY logfile thread 2 group 10 ;
alter database add STANDBY logfile thread 2 group 11 ;
alter database add STANDBY logfile thread 2 group 12 ;
#2.2 生成pfile,並修改。
SQL> create pfile='/tmp/initstbdb.ora' from spfile;
1.修改
*.audit_file_dest='/opt/app/oracle/admin/racdb/adump'
修改後:
*.audit_file_dest='/opt/app/oracle/admin/stbdb/adump'
建立目錄 :
mkdir -p /opt/app/oracle/admin/stbdb/adump
chown oracle:oinstall /opt/app/oracle/admin/stbdb/adump
2.新增以下內容:
*.db_file_name_convert='+DATA/racdb/datafile','+DATA/stbdb/datafile','+DATA/racdb/tempfile','+DATA/stbdb/tempfile'
*.LOG_FILE_NAME_CONVERT='+DATA/racdb/onlinelog','+DATA/stbdb/onlinelog','+RECOVERY/racdb/onlinelog' ,'+RECOVERY/stbdb/onlinelog'
修改前的 initstbdb.ora
racdb1.__db_cache_size=13623099392
racdb2.__db_cache_size=13623099392
racdb2.__java_pool_size=67108864
racdb1.__java_pool_size=67108864
racdb2.__large_pool_size=67108864
racdb1.__large_pool_size=67108864
racdb1.__oracle_base='/opt/app/oracle'#ORACLE_BASE set from environment
racdb2.__oracle_base='/opt/app/oracle'#ORACLE_BASE set from environment
racdb2.__pga_aggregate_target=9462349824
racdb1.__pga_aggregate_target=9462349824
racdb2.__sga_target=17582522368
racdb1.__sga_target=17582522368
racdb2.__shared_io_pool_size=0
racdb1.__shared_io_pool_size=0
racdb1.__shared_pool_size=3556769792
racdb2.__shared_pool_size=3690987520
racdb2.__streams_pool_size=0
racdb1.__streams_pool_size=67108864
*.audit_file_dest='/opt/app/oracle/admin/racdb/adump'
*.audit_trail='NONE'
*.cluster_database=true
*.compatible='11.2.0.0.0'
*.control_files='+DATA/racdb/controlfile/current.267.812303153','+RECOVERY/racdb/controlfile/current.3283.812303153'
*.db_block_size=8192
*.db_create_file_dest='+DATA'
*.db_domain=''
*.db_flashback_retention_target=1440
*.db_name='racdb'
*.db_recovery_file_dest='+RECOVERY'
*.db_recovery_file_dest_size=3221225472000
*.diagnostic_dest='/opt/app/oracle'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=racdbXDB)'
*.fal_client='RACDB'
*.fal_server='DGDB'
racdb2.instance_number=2
racdb1.instance_number=1
*.log_archive_config='DG_CONFIG=(dgdb,racdb)'
*.log_archive_dest_2='SERVICE=dgdb LGWR ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=dgdb'
*.log_archive_dest_state_2='DEFER'
*.log_archive_format='%t_%s_%r.dbf'
*.log_archive_max_processes=30
racdb1.memory_max_target=29360128000
*.memory_target=27031240704
*.nls_language='SIMPLIFIED CHINESE'
*.nls_territory='CHINA'
*.open_cursors=5000
*.processes=8000
*.remote_listener='rac-scan:1521'
*.remote_login_passwordfile='EXCLUSIVE'
*.resource_manager_plan=''
*.session_cached_cursors=100
*.sessions=5000
*.standby_file_management='MANUAL'
racdb2.thread=2
racdb1.thread=1
racdb2.undo_tablespace='UNDOTBS2'
racdb1.undo_tablespace='UNDO_TBS01'
[[email protected] dbs]$
修改後的initstbdb.ora
[[email protected] dbs]$ cat initstbdb.ora
stbdb.__db_cache_size=13623099392
stbdb.__java_pool_size=67108864
stbdb.__large_pool_size=67108864
stbdb.__oracle_base='/opt/app/oracle'#ORACLE_BASE set from environment
stbdb.__pga_aggregate_target=9462349824
stbdb.__sga_target=17582522368
stbdb.__shared_io_pool_size=0
stbdb.__shared_pool_size=3556769792
stbdb.__streams_pool_size=67108864
*.audit_file_dest='/opt/app/oracle/admin/stbdb/adump'
*.audit_trail='NONE'
*.compatible='11.2.0.0.0'
*.control_files='+DATA/racdb/controlfile/current.267.812303153','+RECOVERY/racdb/controlfile/current.3283.812303153'
*.db_block_size=8192
*.db_create_file_dest='+DATA'
*.db_domain=''
*.db_flashback_retention_target=1440
*.db_name='racdb'
db_unique_name='stbdb'
*.db_recovery_file_dest='+RECOVERY'
*.db_recovery_file_dest_size=900000000000
*.diagnostic_dest='/opt/app/oracle'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=stbdb)'
*.fal_client='STBDB'
*.fal_server='RACDB1,RACDB2'
stbdb.instance_number=1
*.db_file_name_convert='+DATA/racdb/datafile','+DATA/stbdb/datafile','+DATA/racdb/tempfile','+DATA/stbdb/tempfile'
*.LOG_FILE_NAME_CONVERT='+DATA/racdb/onlinelog','+DATA/stbdb/onlinelog','+RECOVERY/racdb/onlinelog' ,'+RECOVERY/stbdb/onlinelog'
*.log_archive_config='DG_CONFIG=(dgdb,racdb)'
*.log_archive_dest_2='SERVICE=dgdb LGWR ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=dgdb'
*.log_archive_dest_state_2='DEFER'
*.log_archive_format='%t_%s_%r.dbf'
*.log_archive_max_processes=30
stbdb.memory_max_target=29360128000
*.memory_target=27031240704
*.nls_language='SIMPLIFIED CHINESE'
*.nls_territory='CHINA'
*.open_cursors=5000
*.processes=8000
*.remote_listener='stbdb:1521'
*.remote_login_passwordfile='EXCLUSIVE'
*.resource_manager_plan=''
*.session_cached_cursors=100
*.sessions=5000
*.standby_file_management='AUTO'
thread=1
undo_tablespace='UNDOTBS1'
#2.3建立控制檔案 :
切換兩次日誌及做兩次歸檔
SQL> alter system switch logfile;
System altered.
SQL> alter system switch logfile;
System altered.
SQL> alter system archive log current;
System altered.
SQL> alter system archive log current;
System altered.
SQL> alter database create standby controlfile as '/tmp/control01.ctl';
Database altered.
#2.4建立密碼檔案
[[email protected] ~]$ orapwd file=/tmp/orapwstbdb.ora password=sa force=y ignorecase=y
#2.5把檔案拷貝到 dg1 伺服器:
scp /tmp/orapwstbdb.ora dg1:/opt/app/oracle/product/11.2.0/dbs/orapwstbdb.ora
scp /tmp/inittdb.ora dg1:/tmp/inittdb.ora
#2.6 在STANDBY 端
SQL> create spfile from pfile='/tmp/inittdb.ora';
File created.
SQL> startup nomount;
#2.7複製資料庫
(執行命令要在PRIMARY 中的某一個節點中進行,不然會出錯)
[[email protected] dbs]$ rman target sys/[email protected] auxiliary sys/[email protected] nocatalog
rman>duplicate target database for standby from active database nofilenamecheck;
三、DATAGUARD 開啟
SQL> alter database recover managed standby database disconnect from session;
Database altered.
# 開啟STANDBY 資料庫
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE;
#啟用STANDBY資料庫,進入RECOVER模式:
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE DISCONNECT FROM SESSION;
#啟動到只讀模式:
alter database open read only;
#轉換到REAL-TIME模式下:
--alter database recover managed standby database cancel;
--ALTER DATABASE OPEN;
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE USING CURRENT LOGFILE DISCONNECT from session;
四、測試驗證
#PRIMARY 端:
SQL>
SQL> select thread#,sequence#,status from v$log;
THREAD# SEQUENCE# STATUS
---------- ---------- ----------------
1 57930 CURRENT
1 57929 INACTIVE
2 43251 INACTIVE
2 43252 ACTIVE
1 57928 INACTIVE
2 43253 CURRENT
6 rows selected.
SQL>
#STANDBY 端
SQL> select archived_thread#,archived_seq#,APPLIED_THREAD#,APPLIED_SEQ# from v$archive_dest_status;
ARCHIVED_THREAD# ARCHIVED_SEQ# APPLIED_THREAD# APPLIED_SEQ#
---------------- ------------- --------------- ------------
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
2 43252 2 43252