您好,登錄后才能下訂單哦!
前言
前幾天朋友問了我一個問題,一個單節(jié)點(diǎn)RAC ,要做一套 Data Guard ,但是備庫能給數(shù)據(jù)庫的內(nèi)存只有主庫的一半左右,能不能成功。不知道,沒做過,試試唄。
一.概況
1. 涉及的技術(shù)點(diǎn)
1) RAC 作為 primary database , nonRAC 作為 standby database
2) 使用RMAN 作為數(shù)據(jù)庫的備份方式
3) 使用Backup-based duplication方式 創(chuàng)建備庫
4) 主庫使用ASM 存儲方式,備庫使用 filesystem 作為存儲
5) 使用standby logfile ,開啟日志實時更新
2. 主備庫信息表概要
|
Primary(RAC) |
Standby(fs) |
HOSTNAME |
yukki |
fuzhou |
ORACLE_SID |
cs1 |
stbcs1 |
DB_NAME |
cs |
cs |
DB_UNIQUE_NAME |
cs |
stby |
SERVICE_NAMES |
cs_pri |
cs_stb |
INSTANCE_NAME |
cs1 |
stbcs1 |
INSTANCE_NUMBER |
1 |
1 |
THREAD |
1 |
1 |
TEMPFILE_LOCATION |
+DATA/cs/tempfile |
/u01/db/oradata |
二. Primary 主庫配置
1. 查看 Managed Standby 組件
SYS@ cs1>select * from v$option where lower(parameter)='managed standby';
PARAMETER VALUE
---------------------------------------------------------------- ---------------------------------------------------------------
Managed Standby TRUE
# 請確保該值為 true
2. 檢查remote_login_passwordfile 的設(shè)置
SYS@ cs1>show parameter remote_login_passwordfile
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
remote_login_passwordfile string EXCLUSIVE
# 若該參數(shù)不為 exclusive ,則按照以下命令修改,并重啟使其生效
SYS@ cs1>alter system set remote_login=exclusive scope=spfile;
3. 檢查數(shù)據(jù)庫是否為歸檔模式
SYS@ cs1>archive log list
Database log mode Archive Mode
Automatic archival Enabled
Archive destination +DATA
Oldest online log sequence 87
Next log sequence to archive 89
Current log sequence 89
# 若為非歸檔模式,則需要干凈的關(guān)閉數(shù)據(jù)庫后,啟動到 mount 模式,修改為歸檔模式后再開庫
SYS@ cs1>shutdown immediate
SYS@ cs1>startup mount
SYS@ cs1>alter database archivelog;
SYS@ cs1>alter database open;
SYS@ cs1>select log_mode from v$database;
4. 檢查數(shù)據(jù)庫是否開啟force logging
SYS@ cs1>select name,force_logging from v$database;
NAME FOR
--------- ---
CS YES
# 若數(shù)據(jù)庫未開啟 force logging ,則
SYS@ cs1>alter database force logging;
SYS@ cs1>select name,force_logging from v$database;
SYS@ cs1>alter system archive log current;
5. 檢查主庫口令文件的MD5 值
[oracle@ yukki dbs]$ openssl md5 orapwcs1
MD5(orapwcs1)= 7836520c978614723e57330e12ccbe90
# 要確保主備庫口令文件的 MD5 值相同,即使 sys 的密鑰相同也不行
6. 主庫參數(shù)修改
SYS@ cs1>alter system set db_unique_name=cs scope=spfile;
SYS@ cs1>alter system set log_archive_config='dg_config=(cs,stby)';
SYS@ cs1>alter system set log_archive_dest_1='location=+DATA valid_for=(all_logfiles,all_roles) db_unique_name=cs';
SYS@ cs1>alter system set log_archive_dest_2='service=dbstandby async valid_for= (online_logfiles,primary_roles ) db_unique_name=stby';
SYS@ cs1>alter system set log_archive_dest_state_1=enable;
SYS@ cs1>alter system set log_archive_dest_state_ 2 =enable;
SYS@ cs1>alter system set log_archive_max_processes=30;
SYS@ cs1>alter system set fal_server=dbstandby;
SYS@ cs1>alter system set standby_file_management= auto ;
SYS@ cs1>alter system set db_file_name_convert=' +DATA /cs/datafile, /u01/db/oradata' scope=spfile;
SYS@ cs1>alter system set log_file_name_convert=' +DATA /cs/onlinelog, /u01/db/oradata'scope=spfile;
SYS@ cs1>alter system set service_names=cs_pri;
三. Standby 備庫配置
1. 準(zhǔn)備standby 的口令文件
# 拷貝主庫的口令文件傳至備庫的 $ORACLE_HOME/dbs 目錄下,并重命名為 orapwstbcs1
[oracle@ yukki dbs]$ scp orapwcs1 oracle@ fuzhou :$ORACLE_HOME/dbs
[oracle@fuzhou dbs]$ mv orapwcs1 orapwstbcs1
# 檢查備庫口令文件的 MD5 值,確保和主庫相同
[oracle@fuzhou dbs]$ openssl md5 orapwstbcs1
MD5(orapwstbcs1)= 7836520c978614723e57330e12ccbe90
2. 準(zhǔn)備standby 的參數(shù)文件
在主庫生成pfile ,并將其傳至備庫修改
SYS@ cs1>create pfile='/tmp/pfile2019110 1 ' from spfile;
[oracle@ yukki tmp]$ scp pfile2019110 1 oracle@fuzhou:/tmp /initstbcs1.ora
[oracle@fuzhou dbs]$ vi initstbcs1.ora
stbcs1._...
...
*.audit_file_dest='/u01/db/admin/cs/adump'
*.audit_trail='db'
*.compatible='11.2.0.4.0'
*.control_files='/u01/db/oradata/control01.ctl','/u01/db/oradata/control02.ctl'#Restore Controlfile
*.db_block_size=8192
*.db_create_file_dest='/u01/db/oradata'
*.db_domain=''
*.db_file_name_convert='+DATA/cs/datafile','/u01/db/oradata'
*.db_name='cs'
*.db_recovery_file_dest='/u01/db/fast_recovery_area'
*.db_recovery_file_dest_size=4385144832
*.db_unique_name='STBY'
*.diagnostic_dest='/u01/db'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=stbcsXDB)'
*.enable_goldengate_replication=TRUE
*.fal_server='DBPRIMARY'
*.log_archive_config='DG_CONFIG=(STBY,CS)'
*.log_archive_dest_1='location=/u01/db/arch valid_for=(all_logfiles,all_roles) db_unique_name=stby'
*.log_archive_dest_2='service=dbprimary async valid_for= (online_logfiles,primary_roles ) db_unique_name=cs'
*.log_archive_dest_state_1='ENABLE'
*.log_archive_dest_state_2='ENABLE'
*.log_archive_format='%t_%s_%r.dbf'
*.log_archive_max_processes=30
*.log_file_name_convert='+DATA/cs/onlinelog','/u01/db/oradata'
*.open_cursors=300
*.pga_aggregate_target=109715200
*.processes=150
*.remote_login_passwordfile='exclusive'
*.service_names='CS_STB'
*.sga_target=329145600
*.standby_file_management='AUTO'
*.undo_tablespace='UNDOTBS1'
# 此處需要注意的是由于實驗需求,備庫參數(shù)文件里的 sga_target 和 pga_aggregate_target 需修改為主庫的一半
# 在 11g 中取消的參數(shù):
*.standby_archive_dest
*.fal_client
3. 創(chuàng)建必要的目錄結(jié)構(gòu)
[oracle@ fuzhou ~]$ mkdir -p /u01/db/admin/cs/adump
[oracle@ fuzhou ~]$ mkdir -p /u01/db/oradata
[oracle@ fuzhou ~]$ mkdir -p /u01/db/arch
[oracle@ fuzhou ~]$ mkdir -p /u01/db/fast_recovery_area
4. 創(chuàng)建spfile ,并啟動 instance
[oracle@ fuzhou ~]$ export ORACLE_SID=stbcs1
[oracle@ fuzhou ~]$ sqlplus / as sysdba
SYS@ stbcs1>create spfile from pfile;
SYS@ stbcs1>startup nomount
SYS@ stbcs1>show parameter spfile
NAME TYPE VALUE
--------- -------- -------- -- ---------------------------------------------------- ------------------------
spfile string /u01/db/product/11204/dbhome_1/dbs/spfilestbcs1.ora
四. Backup-based duplication 復(fù)制 physical standby
1. listener.ora 配置
# 由于 standby 端只有 oracle 軟件,實例無法啟動到 mount 狀態(tài),此時 PMON 進(jìn)程無法完成自動注冊,故采用靜態(tài)監(jiān)聽。
主庫:
[grid@ yukki ~]$ cat /u01/11.2.0/grid/network/admin/listener.ora
LISTENER=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=IPC)(KEY=LISTENER)))) # line added by Agent
LISTENER_SCAN1=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=IPC)(KEY=LISTENER_SCAN1)))) # line added by Agent
ENABLE_GLOBAL_DYNAMIC_ENDPOINT_LISTENER_SCAN1=ON # line added by Agent
ENABLE_GLOBAL_DYNAMIC_ENDPOINT_LISTENER=ON # line added by Agent
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME= cs_pri)
(ORACLE_HOME = /u01/db/product/11204/dbhome_1)
(SID_NAME =cs1)
)
)
備庫:
[oracle@ fuzhou ~]$ cat /u01/db/product/11204/dbhome_1/network/admin/listener.ora
# listener.ora Network Configuration File: /u01/db/product/11204/dbhome_1/network/admin/listener.ora
# Generated by Oracle configuration tools.
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.3.66)(PORT = 1521))
)
)
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME= cs_stb)
(ORACLE_HOME = /u01/db/product/11204/dbhome_1)
(SID_NAME =stbcs1)
)
)
2. tnsnames.ora 配置
往主備庫的$ORACLE_HOME/network/admin/tnsnames.ora 中添加:
dbprimary =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.3.88)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = cs_pri)
)
)
dbstandby =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.3.66)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = cs_stb)
)
)
3. 備份primary 數(shù)據(jù)庫
1) 查看數(shù)據(jù)庫物理結(jié)構(gòu)
[oracle@ yukki ~]$ rman target /
Recovery Manager: Release 11.2.0.4.0 - Production on Mon Nov 4 17:40:28 2019
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
connected to target database: CS (DBID=1434125244)
RMAN> report schema;
using target database control file instead of recovery catalog
Report of database schema for database with db_unique_name CS
List of Permanent Datafiles
===========================
File Size(MB) Tablespace RB segs Datafile Name
---- -------- ------------ ------- ------------------------ -------------------------------------------------------------
1 750 SYSTEM *** +DATA/cs/datafile/system.256.1018198953
2 580 SYSAUX *** +DATA/cs/datafile/sysaux.257.1018198953
3 75 UNDOTBS1 *** +DATA/cs/datafile/undotbs1.258.1018198953
4 5 USERS *** +DATA/cs/datafile/users.259.1018198953
5 50 TEST *** +DATA/cs/datafile/test.dbf
List of Temporary Files
=======================
File Size(MB) Tablespace Maxsize(MB) Tempfile Name
---- -------- ------------ ----------- -------------------- ---------------------------------------------------------------
1 29 TEMP 32767 +DATA/cs/tempfile/temp.268.1018199043
2) 備份數(shù)據(jù)庫和控制文件
run{
sql 'alter system archive log current';
allocate channel c1 device type disk;
allocate channel c2 device type disk;
allocate channel c3 device type disk;
backup database filesperset 1 format '/backup/whole_%d_%U_%t.bus';
backup current controlfile for standby format '/backup/ctl_%d_%U_%t.bus';
release channel c1;
release channel c2;
release channel c3;
}
3) 備份歸檔日志
run{
sql 'alter system archive log current';
allocate channel c1 device type disk;
allocate channel c2 device type disk;
backup archivelog all format '/backup/ arch _%d_%U_%t.bus';
release channel c1;
release channel c2;
}
4) 將備份傳至備庫機(jī)
[oracle@ yukki ~]$ scp /backup/* oracle@fuzhou:/backup
4. 使用duplicate 進(jìn)行數(shù)據(jù)庫恢復(fù)
1) 創(chuàng)建腳本
[oracle@ yukki ~]$ vi duplicate.sh
connect target sys/oracle@dbprimary
connect auxiliary sys/oracle@dbstandby
run{
allocate channel c1 device type disk;
allocate channel c2 device type disk;
allocate channel c3 device type disk;
allocate auxiliary channel aux1 device type disk;
allocate auxiliary channel aux2 device type disk;
allocate auxiliary channel aux3 device type disk;
set until sequence=87 thread=1;
set newname for tempfile 1 to '/u01/db/oradata/temp01.dbf';
duplicate target database for standby nofilenamecheck dorecover;
release channel aux1;
release channel aux2;
release channel aux3;
release channel c1;
release channel c2;
release channel c3;
}
# 由于沒有 temp_file_name_convert 這個參數(shù),故在 duplicate 前需要給 tempfile set newname 操作
# 手動分配復(fù)制通道時,必須要加上 allocate auxiliary channel ,否則會提示 :
RMAN-05503: at least one auxiliary channel must be allocated to execute this command
#如果duplicate的時候使用關(guān)鍵詞from active database(通過網(wǎng)絡(luò)直傳不落地的active database duplication方式,不需要主庫的備份,節(jié)省了磁盤空間和傳輸備份的時間,但在復(fù)制的過程中對主庫有一定壓力,需要一定的網(wǎng)絡(luò)帶寬),則必須為主庫分配通道,否則會提示:
RMAN-06034: at least 1 channel must be allocated to execute this command
2) 使用nohup 調(diào)用腳本,使其在后臺運(yùn)行
[oracle@ yukki ~]$ nohup rman cmdfile=duplicate.sh >duplicate.log &
5. 啟動physical standby
SYS@ stbcs1>shutdown immediate;
SYS@ stbcs1>startup;
SYS@ stbcs1>recover managed standby database disconnect from session;
SYS@ stbcs1>select name,open_mode,database_role,protection_mode,switchover_status,controlfile_type from v$database;
NAME OPEN_MODE DATABASE_ROLE PROTECTION_MODE SWITCHOVER_STATUS CONTROL
------ -- ---------------- -- ------------- - ------ ------------ - ------- - - -------- -------------------------------------- ------------------------------- -------------
CS READ ONLY WITH APPLY PHYSICAL STANDBY MAXIMUM PERFORMANCE NOT ALLOWED STANDBY
五. DATAGUARD 使用 standby logfile
1. standby logfile 創(chuàng)建要求
# 確保主備庫的日志文件大小相同,建議備庫的 standby logfile 要比主庫的 redo logfile 多一組,目的是確保備庫隨時都有一組空閑日志可使用。
# 當(dāng)使用 rman 生成 controlfile for standby 的備份時, alert 日志中會有相關(guān)的提示信息,如下:
Clearing standby activation ID 1434109882 (0x557ac7ba)
The primary database controlfile was created using the
'MAXLOGFILES 192' clause.
There is space for up to 189 standby redo logfiles
Use the following SQL commands on the standby database to create
standby redo logfiles that match the primary database:
ALTER DATABASE ADD STANDBY LOGFILE 'srl1.f' SIZE 52428800;
ALTER DATABASE ADD STANDBY LOGFILE 'srl2.f' SIZE 52428800;
ALTER DATABASE ADD STANDBY LOGFILE 'srl3.f' SIZE 52428800;
ALTER DATABASE ADD STANDBY LOGFILE 'srl4.f' SIZE 52428800;
WARNING: OMF is enabled on this database. Creating a physical
standby controlfile, when OMF is enabled on the primary
database, requires manual RMAN intervention to resolve OMF
datafile pathnames.
NOTE: Please refer to the RMAN documentation for procedures
describing how to manually resolve OMF datafile pathnames.
2. 備庫添加standby logfile
# 首先查看主庫 online redo logfiles 的信息
SYS@ cs1>select group#,thread#,bytes from v$log;
GROUP# THREAD# BYTES
---------- ---------- ----------
1 1 52428800
2 1 52428800
3 1 52428800
# 確保主庫 ORLs 日志組大小相同,再配置 SRLs ,且在備庫添加 standby logfile 時,要先停掉 MRP 進(jìn)程:
SYS@ stbcs1> recover managed standby database cancel;
SYS@ stbcs1>alter database add standby logfile thread 1 group 11 '/u01/db/oradata/stb_redo01.log' size 52428800;
SYS@ stbcs1>alter database add standby logfile thread 1 group 12 '/u01/db/oradata/stb_redo0 2 .log' size 52428800;
SYS@ stbcs1>alter database add standby logfile thread 1 group 13 '/u01/db/oradata/stb_redo0 3 .log' size 52428800;
SYS@ stbcs1>alter database add standby logfile thread 1 group 14 '/u01/db/oradata/stb_redo0 4 .log' size 52428800;
# 由于主庫有三組 ORLs ,在創(chuàng)建 SRLs 的時候若不指定組數(shù),默認(rèn)會是 4-7 ,那么后續(xù)在主庫添加日志組的話就會產(chǎn)生混亂,故從第 11 組開始配置 standby redo logfiles 。
# 還有就是當(dāng)主庫多實例的時候,備庫也要配置上多個 thread ,目的是為了能開啟 real time apply ,但是如果備庫只創(chuàng)建了 thread 1 ,并不會影響 archive log 的傳輸和應(yīng)用,但是備庫并不會采用 real time apply ,主庫 online redo 無法做到實時傳輸應(yīng)用,只在歸檔切換后備庫才會應(yīng)用。
3. 主庫添加standby logfile
SYS@ cs1>alter database add standby logfile thread 1 group 1 1 '+DATA/cs/onlinelog/stb y_ redo01.log' size 52428800;
SYS@ cs1>alter database add standby logfile thread 1 group 1 2 '+DATA/cs/onlinelog/stb y_ redo0 2 .log' size 52428800;
SYS@ cs1>alter database add standby logfile thread 1 group 1 3 '+DATA/cs/onlinelog/stb y_ redo0 3 .log' size 52428800;
SYS@ cs1>alter database add standby logfile thread 1 group 1 4 '+DATA/cs/onlinelog/stb y_ redo0 4 .log' size 52428800;
# 在配置備庫的 standby logfile 的時候,也需要在主庫上預(yù)配置,目的是用于未來切換使用。
六. 部分參數(shù)說明
1. db_name
數(shù)據(jù)庫名稱,一套Data Guard 環(huán)境中,需要保持主備庫的 db_name 相同。
2. db_unique_name
DG 環(huán)境中用于區(qū)分主備庫的唯一名字,即使主備庫角色互換, db_unique_name 也不會更改。
3. log_archive_config
該參數(shù)通過dg_configs 設(shè)置同一個 Data Guard 環(huán)境中的所有 db_unique_name ,以逗號分隔,定義該參數(shù)能確保主備數(shù)據(jù)庫能夠發(fā)送或接收日志。
4. log_archive_dest_1
通過location 設(shè)置日志歸檔的本地路徑,主備庫需要定義各自的 Online Redo Log 的歸檔地址。本例 log_archive_dest_1='location=+DATA valid_for=(all_logfiles,all_roles) db_unique_name=cs' ,可以理解為對主庫( cs )而言,不管她是主庫還是備庫( all_roles ),她都會自己完成歸檔動作,并將日志歸檔于本地路徑 +DATA 下。
5. log_archive_dest_2
該參數(shù)僅當(dāng)數(shù)據(jù)庫角色為primary 時生效,指定 primary 傳輸 redo log 到該參數(shù)定義的 standby database 上,其中 service 的設(shè)置為 tnsnames.ora 中定義的 Oracle Net 名稱。 log_archive_dest_2 可以說是 dataguard 上最重要的參數(shù)之一,它定義了 redo log 的傳輸方式 (sync or async) 以及傳輸目標(biāo) ( 即 standby apply node) ,直接決定了 dataguard 的數(shù)據(jù)保護(hù)級別。
6. fal_server
fal 即 fatch archive log ,其值為 tnsnames.ora 中遠(yuǎn)端數(shù)據(jù)庫服務(wù)的 Oracle Net 名稱, fal_server 為備庫中設(shè)置的參數(shù),一旦備庫產(chǎn)生 gap ,會通過 fal_server 參數(shù)向主庫請求傳輸缺失的日志,當(dāng)然為了 switchover ,主庫上也要預(yù)配置該參數(shù)。
7. db_file_name_convert
定義主備庫的數(shù)據(jù)文件路徑轉(zhuǎn)換,遠(yuǎn)端在前,本地端在后。若有多個,逐一指明對映關(guān)系。
8. log_file_name_convert
定義主備庫在線日志文件路徑轉(zhuǎn)換,遠(yuǎn)端在前,本地端在后。若有多個,逐一指明對映關(guān)系。
9. standby_file_management
備庫參數(shù),用來控制是否主動將主庫增加表空間或數(shù)據(jù)文件的改動,傳播到物理備庫。
auto :主庫執(zhí)行的表空間創(chuàng)建操作會被傳播到物理備庫上執(zhí)行。
manual : default ,需要手工復(fù)制新創(chuàng)建的數(shù)據(jù)文件到物理備庫服務(wù)器。
10. service_name ( tnsnames.ora 中的參數(shù))
service_name 是在多實例出現(xiàn)后,為了方便應(yīng)用連接數(shù)據(jù)庫提出的參數(shù),該參數(shù)直接對應(yīng)數(shù)據(jù)庫而不是某個實例,故該參數(shù)與 sid 沒有直接關(guān)系,不必與 sid 一樣。當(dāng)服務(wù)器端 listener.ora 中配置了靜態(tài)監(jiān)聽后,客戶端 tnsnames.ora 中 service_name 與服務(wù)器端靜態(tài)監(jiān)聽中的 GLOBAL_DBNAME 相對應(yīng),且可不必與服務(wù)器端數(shù)據(jù)庫中 service_names 參數(shù)對應(yīng)。但若沒有配置靜態(tài)監(jiān)聽,客戶端 tnsnames.ora 里的 service_name 需要從服務(wù)器端數(shù)據(jù)庫中的 service_names 中取值。
以上,主備庫內(nèi)存不一致,可以搭建Data Guard 環(huán)境。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。