環境:Single Instance -> RAC
Single Instance:
- db_name=demo
- db_unique_name=demo
- instance_name=demo
- service_names=demo
RAC(2 nodes):
- db_name=demo
- db_unique_name=demorac
- instance_name=jydb1、jydb2
- service_names=demorac
上述為這裡我做為演示環境的基本規劃。
本文作為step by step的快速指導手冊,方便快速部署此類ADG環境。
依據之前的文章
歷史文章步驟已經很全且描述的很細緻,本篇複用之前的章節風格,儘可能簡潔化,方便熟練後直接引用。
關於前兩部分:這裡預設準備就緒:
- Single Instance作為初始的primary端,已經安裝好19.16的軟體和資料庫
- RAC作為初始的standby端,已經安裝好19.16的軟體
對於後面的章節,列舉如下:
3.主庫配置
3.1 資料庫歸檔模式
sqlplus / as sysdba
startup mount
alter database archivelog;
alter database open;
3.2 Force Logging
alter database force logging;
select FORCE_LOGGING FROM V$DATABASE;
3.3 主庫引數檔案修改
使用下面語句查詢現在DG相關引數的設定情況:
set linesize 500
col value for a70
col name for a50
select name, value
from v$parameter
where name in ('db_name','db_unique_name','log_archive_config', 'log_archive_dest_1','log_archive_dest_2',
'log_archive_dest_state_1','log_archive_dest_state_2', 'remote_login_passwordfile',
'log_archive_format','log_archive_max_processes','fal_server','db_file_name_convert',
'log_file_name_convert', 'standby_file_management');
修改引數值:
alter system set log_archive_config= 'DG_CONFIG=(demo,demorac)';
alter system set log_archive_dest_1='LOCATION=USE_DB_RECOVERY_FILE_DEST VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=demo';
alter system set log_archive_dest_2='SERVICE=demorac VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=demorac';
alter system set log_archive_dest_state_1=enable;
alter system set log_archive_dest_state_2=enable;
alter system set FAL_SERVER='demorac';
alter system set db_file_name_convert='+DATADG/demorac','/flash/oradata/DEMO' scope=spfile;
alter system set log_file_name_convert='+DATADG/demorac','/flash/oradata/DEMO','+ARCHDG/DEMORAC','/flash/fast_recovery_area/DEMO' scope=spfile;
alter system set standby_file_management=AUTO;
3.4 建立SRLs
select member from v$logfile;
alter database add standby logfile thread 1 group 11 '/flash/oradata/DEMO/standby_group_11.log' size 209715200;
alter database add standby logfile thread 1 group 12 '/flash/oradata/DEMO/standby_group_12.log' size 209715200;
alter database add standby logfile thread 1 group 13 '/flash/oradata/DEMO/standby_group_13.log' size 209715200;
alter database add standby logfile thread 1 group 14 '/flash/oradata/DEMO/standby_group_14.log' size 209715200;
alter database add standby logfile thread 2 group 21 '/flash/oradata/DEMO/standby_group_21.log' size 209715200;
alter database add standby logfile thread 2 group 22 '/flash/oradata/DEMO/standby_group_22.log' size 209715200;
alter database add standby logfile thread 2 group 23 '/flash/oradata/DEMO/standby_group_23.log' size 209715200;
alter database add standby logfile thread 2 group 24 '/flash/oradata/DEMO/standby_group_24.log' size 209715200;
select * from v$standby_log;
3.5 備份資料庫
採用duplicate方式建立備庫,無需手工備份資料庫。
3.6 建立備庫引數檔案
create pfile='pfile_for_standby.txt' from spfile;
預設存在$ORACLE_HOME/dbs目錄下。
3.7 更新tnsnames.ora檔案
DEMO =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.4)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = demo)
)
)
LISTENER_DEMO =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.4)(PORT = 1521))
DEMORAC =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.15)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = demorac)
)
)
DEMORAC1 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.13)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = demorac)
(SID = jydb1)
)
)
DEMORAC2 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.14)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = demorac)
(SID = jydb2)
)
)
LISTENER_DEMORAC1 =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.13)(PORT = 1521))
LISTENER_DEMORAC2 =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.14)(PORT = 1521))
這裡需要注意service_name,sid的配置符合部署環境要求,然後同步該檔案到備庫:
[oracle@bogon admin]$ scp tnsnames.ora 192.168.1.11:/u01/app/oracle/product/19.3.0/db_1/network/admin
[oracle@bogon admin]$ scp tnsnames.ora 192.168.1.12:/u01/app/oracle/product/19.3.0/db_1/network/admin
4.備庫配置
4.1 複製主庫引數檔案
複製主庫引數檔案到備庫所有節點:
[oracle@bogon dbs]$ scp pfile_for_standby.txt 192.168.1.11:/u01/app/oracle/product/19.3.0/db_1/dbs
[oracle@bogon dbs]$ scp pfile_for_standby.txt 192.168.1.12:/u01/app/oracle/product/19.3.0/db_1/dbs
4.2 複製密碼檔案
複製主庫密碼檔案到備庫所有節點:
[oracle@bogon dbs]$ scp orapwdemo 192.168.1.11:/u01/app/oracle/product/19.3.0/db_1/dbs/orapwjydb1
[oracle@bogon dbs]$ scp orapwdemo 192.168.1.12:/u01/app/oracle/product/19.3.0/db_1/dbs/orapwjydb2
注意:
- 密碼檔案的命名方式
orapw<sid>
; - 如果主庫也是RAC,那需要pwcopy命令從ASM磁碟組中複製到檔案系統上,這裡主庫是單例項,不需要。
4.3 建立備庫需要的目錄
# Using Oracle User, On all nodes:
mkdir -p /u01/app/oracle/admin/demorac/adump
4.4 修改備庫引數檔案
*.audit_file_dest='/u01/app/oracle/admin/demorac/adump'
*.audit_trail='db'
*.compatible='19.0.0'
*.control_files='+DATADG'
#*.control_files='+DATADG/DEMORAC/CONTROLFILE/current.256.1127325539'#Restore Controlfile
*.db_block_size=8192
*.db_file_name_convert='/flash/oradata/DEMO','+DATADG/DEMORAC'
*.db_name='demo'
*.db_unique_name='demorac'
*.db_recovery_file_dest='+ARCHDG'
*.db_recovery_file_dest_size=15360m
*.diagnostic_dest='/u01/app/oracle'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=demoracXDB)'
*.enable_pluggable_database=true
*.fal_server='demo'
jydb1.local_listener='LISTENER_DEMORAC1'
jydb2.local_listener='LISTENER_DEMORAC2'
*.remote_listener='db01rac-scan:1521'
*.log_archive_config='DG_CONFIG=(demo,demorac)'
*.log_archive_dest_1='LOCATION=USE_DB_RECOVERY_FILE_DEST VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=demorac'
*.log_archive_dest_2='SERVICE=demo VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=demo'
*.log_archive_dest_state_1='ENABLE'
*.log_archive_dest_state_2='ENABLE'
*.log_file_name_convert='/flash/oradata/DEMO','+DATADG/DEMORAC','/flash/fast_recovery_area/DEMO','+ARCHDG/DEMORAC'
*.nls_language='AMERICAN'
*.nls_territory='AMERICA'
*.open_cursors=300
*.pga_aggregate_target=2048m
*.processes=2560
*.remote_login_passwordfile='EXCLUSIVE'
*.sga_target=4096m
*.standby_file_management='AUTO'
*.cluster_database=TRUE
jydb1.instance_number=1
jydb2.instance_number=2
jydb1.thread=1
jydb2.thread=2
jydb1.undo_tablespace='UNDOTBS1'
jydb2.undo_tablespace='UNDOTBS2'
注意:這裡新增了新的引數,比如:cluster_database、db_unique_name、remote_listener、jydb1.、jydb2. 等引數,另外按照ADG要求修改之前相關配置,檢查確認符合要求即可。
4.5 複製tnsnames.ora檔案
在3.7步驟中已同步完成,檢查已同步成功即可。
4.6 建立ASM相關目錄
ASMCMD> mkdir +datadg/DEMORAC
ASMCMD> cd +datadg/DEMORAC
ASMCMD> mkdir PDBSEED PDB1 PDB2
注意:這裡測試過,如果不建立這些子目錄在duplicate時會報錯對應的目錄條目不存在。
5.備庫恢復資料庫
5.1 使用啟動例項到nomount狀態
sqlplus / as sysdba
startup nomount pfile=$ORACLE_HOME/dbs/pfile_for_standby.txt
5.2 初始化standby資料庫
使用duplicate命令建立standby資料庫,需要臨時配置靜態監聽。
靜態監聽配置:
[grid@db01rac1 admin]$ pwd
/u01/app/19.3.0/grid/network/admin
[grid@db01rac1 admin]$ vi listener.ora 尾部增加內容:
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = demorac)
(ORACLE_HOME = /u01/app/oracle/product/19.3.0/db_1)
(SID_NAME = jydb1)
)
)
[grid@db01rac1 admin]$ lsnrctl reload
[oracle@db01rac1 ~]$ sqlplus sys/oracle@demorac1 as sysdba
使用duplicate命令建立standby資料庫:
vi dup.sh
rman target sys/oracle@demo auxiliary sys/oracle@demorac1 <<EOF
DUPLICATE TARGET DATABASE FOR STANDBY from active database NOFILENAMECHECK;
EOF
[oracle@db01rac1 ~]$ nohup sh dup.sh &
[oracle@db01rac1 ~]$ tail -200f nohup.out
5.3 確認已建立ORLs和SRLs
# 新增RAC例項2的ORLs:
# SQL> recover managed standby database cancel;
alter system set standby_file_management=manual;
alter database add logfile thread 2 group 4 '+DATADG' size 209715200;
alter database add logfile thread 2 group 5 '+DATADG' size 209715200;
alter database add logfile thread 2 group 6 '+DATADG' size 209715200;
# recover managed standby database disconnect;
alter system set standby_file_management=auto;
SELECT MEMBER FROM V$LOGFILE;
# SRLs確認,可以選擇刪除重建符合要求的。
5.4 確認備庫tnsnames.ora
之前已從主庫同步過該配置檔案。
5.5 啟動MRP
RECOVER MANAGED STANDBY DATABASE DISCONNECT;
為了更直觀的確保實時同步,可建立一個測試表(選做)
# 建立測試表,驗證ADG同步狀態;
create table test (id number);
insert into test values(1);
commit;
select * from test;
5.6 建立spfile然後使用spfile啟動資料庫
指定RAC各個節點的引數檔案init
create spfile='+datadg' from pfile='$ORACLE_HOME/dbs/pfile_for_standby.txt';
[oracle@db01rac1 dbs]$ cat initjydb1.ora
spfile='+DATADG/DEMORAC/PARAMETERFILE/spfile.286.1127387689'
[oracle@db01rac2 dbs]$ cat initjydb2.ora
spfile='+DATADG/DEMORAC/PARAMETERFILE/spfile.286.1127387689'
在資料庫啟動時也可以在alert日誌中確認使用了正確的引數檔案。
6.檢查同步狀態
可以在備庫根據下面的SQL查詢相關的資訊:
col name for a22
col value for a22
col SOURCE_DB_UNIQUE_NAME for a10
set lines 180
select * from v$dataguard_stats;
同步狀態的結果類似如下:
SOURCE_DBID SOURCE_DB_ NAME VALUE UNIT TIME_COMPUTED DATUM_TIME CON_ID
----------- ---------- ---------------------- ---------------------- ------------------------------ ------------------------------ ------------------------------ ----------
0 transport lag +00 00:00:00 day(2) to second(0) interval 01/29/2023 17:48:12 01/29/2023 17:48:12 0
0 apply lag +00 00:00:00 day(2) to second(0) interval 01/29/2023 17:48:12 01/29/2023 17:48:12 0
0 apply finish time +00 00:00:00.000 day(2) to second(3) interval 01/29/2023 17:48:12 0
0 estimated startup time 11 second 01/29/2023 17:48:12 0
其他常用查詢語句:
select * from v$archive_gap;
select process, client_process, sequence#, status from v$managed_standby;
select sequence#, first_time, next_time, applied from v$archived_log;
select archived_thread#, archived_seq#, applied_thread#, applied_seq# from v$archive_dest_status;
select thread#, max (sequence#) from v$log_history group by thread#;
select thread#, max (sequence#) from v$archived_log where APPLIED='YES' group by thread#;
7.新增資源
最後我們需要把Standby RAC的資料庫和例項都新增到OCR中,使他們能夠方便被CRS所管理:
--oracle user:
crsctl stat res -t
srvctl add database -db demorac -dbname demo -oraclehome /u01/app/oracle/product/19.3.0/db_1 -dbtype RAC -spfile +DATADG/DEMORAC/PARAMETERFILE/spfile.286.1127387689 -role physical_standby -diskgroup DATADG,ARCHDG
srvctl add instance -db demorac -instance jydb1 -node db01rac1
srvctl add instance -db demorac -instance jydb2 -node db01rac2
srvctl start database -db demorac
新增完成後,crsctl stat res -t 顯示的資源可以看到我們的備庫資訊:
ora.demorac.db
1 ONLINE ONLINE db01rac1 Open,Readonly,HOME=/
u01/app/oracle/produ
ct/19.3.0/db_1,STABL
E
2 ONLINE ONLINE db01rac2 Open,Readonly,HOME=/
u01/app/oracle/produ
ct/19.3.0/db_1,STABL
E
至此,單例項Primary快速搭建Standby RAC已完成。