您好,登錄后才能下訂單哦!
Oracle DataGuard是Oracle自帶的數據同步功能,基本原理是將日志文件從原數據庫傳輸到目標數據庫,然后在目標數據庫上應用這些日志文件,從而使目標數據庫與源數據庫保持同步,是一種數據庫級別的高可用性方案。
oracle dg 搭建方法兩種:
1.DB停機,拷貝所以文件到DG庫,影響業務
2.DB不停機,rman熱備方式拷貝到DG庫,不影響業務。
oracle dg 模式三種:
1.最大保護
這種模式是默認的數據保護模式,在不影響源數據庫性能的條件下提供盡可能高的數
據保護等級。在該種模式下,一旦日志數據寫到源數據庫的聯機日志文件,事務即可提交,不必等待日志寫到目標數據庫,如果網絡帶寬充足,該種模式可提供類似于最大可用模式的數據保護等級。
2.最大可用性
這種模式和”最大保護”基本上差不多。正常情況下,主備庫之間是同步的。
當網絡或者備庫出現問題時,不會影響到主庫的當機,主庫會自動轉換庫”最大性能”模式,等待備庫可用時,將歸檔傳輸到備庫做恢復。
3.最大性能
這種模式保證主庫性能最大化,主備庫之間數據是異步傳輸的。即,主備日志歸檔以
后才會傳輸到備用庫,在備庫上使用歸檔日志文件做恢復操作。
熱備方式搭建DG庫:
主庫配置:
startup mount;
開啟歸檔:
alter database archivelog;
開啟強制歸檔force logging(默認0秒):
alter database force logging;
開啟閃回(前提開啟歸檔):
設置閃回區大小:#alter system set db_recovery_file_dest_size='5G';
設置閃回區目錄:#alter system set db_recovery_file_dest='/data/db_recovery_file_dest/';
開啟閃回:alter database flashback on;
#設置歸檔日志,默認位置 USE_DB_RECOVERY_FILE_DEST,查詢位置show parameter DB_RECOVERY_FILE_DEST :
#alter system set log_archive_dest_1='location=/data/JINGYU/archivelog';
#設置強制歸檔時間為30分鐘:
#alter system set archive_lag_target=1800;
查看是否開啟:
archive log list;
select FLASHBACK_ON from v$database;
select force_logging from v$database;
添加STANDBY 日志文件:
查詢主庫在線日志的大小和組數:
select group#,bytes/1024/1024 from v$log;
查詢備庫在線日志的大小和組數:
select group#,bytes/1024/1024 from v$standby_log;
創建standby logfile(主庫log+1)
alter database add standby logfile group 4 '/data/zy/onlinelog/redo11_stb01.log' size 50M;
alter database add standby logfile group 5 '/data/zy/onlinelog/redo11_stb02.log' size 50M;
alter database add standby logfile group 6 '/data/zy/onlinelog/redo11_stb03.log' size 50M;
alter database add standby logfile group 7 '/data/zy/onlinelog/redo11_stb04.log' size 50M;
參數文件修改:
cat >> alterspfile.sql <<EOF
alter system set log_archive_config='DG_CONFIG=(primary,standby)';
alter system set log_archive_dest_2='SERVICE=standby arch VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=standby' scope=spfile;
alter system set log_archive_dest_state_1='enable';
alter system set log_archive_dest_state_2='enable';
alter system set db_file_name_convert='/data/zy/datafile','/data/zy/datafile' scope=spfile;
alter system set log_file_name_convert='/data/zy/onlinelog','/data/zy/onlinelog' scope=spfile;
alter system set fal_client='primary';
alter system set fal_server='standby';
alter system set standby_file_management='AUTO';
EOF
mkdir /data/zy/onlinelog /data/zy/datafile -p
chown oracle.oinstall /data/zy/onlinelog /data/zy/datafile -R
shutdown immediate
startup
配置監聽,TNS文件:
動態:listener.ora--測試數據庫啟動到nomount狀態監聽
LISTENER=(DESCRIPTION_LIST=(DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1521))(ADDRESS=(PROTOCOL=TCP)(HOST=2.2.2.11)(PORT=1521))))
ADR_BASE_LISTENER=/u01/app/oracle
靜態:listener.ora
SID_LIST_LISTENER=(SID_LIST=(SID_DESC=(GLOBAL_DBNAME=zy)(ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1)(SID_NAME=jingyu)))
TNS文件配置:tnsnames.ora--類似hosts,指定實例名與IP解析
primary=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.64.50)(PORT=1521))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=zy)))
standby=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.64.60)(PORT=1521))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=zy)))
lsnrctl stop ; lsnrctl start ;
創建pfile并拷貝到standby
create pfile='/tmp/initzy.ora' from spfile;
scp /tmp/initzy.ora 2.2.2.11:/u01/app/oracle/product/11.2.0/dbhome_1/dbs
拷貝密碼文件到standby
scp orapwjingyu 2.2.2.11:/u01/app/oracle/product/11.2.0/dbhome_1/dbs
備庫配置:
修改pfile文件:
*.fal_client='standby'
*.fal_server='primary'
*.log_archive_dest_2='SERVICE=primary VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=primary'
#修改密碼文件
#mv orapwjingyu orapwjingyus
創建pfile配置里相應文件夾
mkdir -p /u01/app/oracle/admin/zy/adump
mkdir -p /u01/app/oracle/oradata/zy/
mkdir -p /u01/app/oracle/fast_recovery_area/zy/
mkdir -p /data/zy/datafile
mkdir -p /u01/app/oracle/fast_recovery_area
mkdir -p /data/zy/onlinelog
chown oracle.oinstall /u01/app/oracle/admin/zy/adump /u01/app/oracle/oradata/zy/ /u01/app/oracle/fast_recovery_area/zy/ /data/zy/datafile /u01/app/oracle/fast_recovery_area /data/zy/onlinelog
修改監聽文件
SID_LIST_LISTENER=(SID_LIST=(SID_DESC=(GLOBAL_DBNAME=zy)(ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1)(SID_NAME=jingyu)))
LISTENER=(DESCRIPTION_LIST=(DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1521))(ADDRESS=(PROTOCOL=TCP)(HOST=2.2.2.11)(PORT=1521))))
ADR_BASE_LISTENER = /u01/app/oracle
修改TNS
primary=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=2.2.2.10)(PORT=1521))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=zy)))
standby=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=2.2.2.11)(PORT=1521))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=zy)))
lsnrctl stop ; lsnrctl start ;
啟動數據庫到nomount狀態
startup nomount pfile='/u01/app/oracle/product/11.2.0/db_1/dbs/initjingyus.ora';
create spfile from pfile; #創建spfile
驗證監聽和TNS配置
tnsping primaryt
tnsping standby
主備執行
sqlplus sys/oracle@primary as sysdba
sqlplus sys/oracle@standby as sysdba
備庫數據恢復:
rman target sys/oracle@primary auxiliary sys/oracle@standby
duplicate target database for standby nofilenamecheck dorecover;
rman>duplicate target database for standby from active database nofilenamecheck;
Finished Duplicate Db at 2018-06-25 xx xx xx ---------------正常完成.
備庫開啟歸檔,閃回,強制歸檔。
startup nomount
alter database mount standby database;
alter database archivelog;
alter system set db_recovery_file_dest_size='5G';
alter database flashback on;
alter database open read only;
alter database recover managed standby database using current logfile disconnect from session; #開啟實時同步
驗證:
歸檔日志有無報錯
select dest_name,error from v$archive_dest;
查詢主庫最大歸檔序號(scn)一致即歸檔同步成功。
select max(sequence#) from v$archived_log;
日志切換
alter system archive log current;
select max(sequence#) from v$archived_log;
創建測試表:
切換測試
3.5.1 switchover
switchover是用戶有計劃的進行停機切換,能夠保證不丟失數據,下面我們來看下switchover是怎樣操作的:
主庫上操作:
select switchover_status,database_role from v$database;
SWITCHOVER_STATUS DATABASE_ROLE
-------------------- ----------------
TO STANDBY PRIMARY
SQL>
注意:上面查詢結果為TO STANDBY 或 SESSIONS ACTIVE表明可以進行切換
SQL> alter database commit to switchover to physical standby;
Databasealtered.
SQL> startup mount
ORACLE instance started.
Total System Global Area 688959488 bytes
Fixed Size 2256432 bytes
Variable Size 566231504 bytes
Database Buffers 117440512 bytes
Redo Buffers 3031040 bytes
Database mounted.
SQL> select database_role from v$database;
DATABASE_ROLE
----------------
PHYSICAL STANDBY
備庫上操作:
SQL> select switchover_status,database_role from v$database;
SWITCHOVER_STATUS DATABASE_ROLE
------------------------------------
TO PRIMARY PHYSICAL STANDBY
SQL>
注意:上面查詢結果顯示為TO PRIMARY 或 SESSIONS ACTIVE表明可以切換成主庫;
現在可以把備庫切換成主庫:
SQL> alter database commit to switchover to primary with session shutdown;
Database altered.
SQL> alter database open;
Database altered.
SQL> select switchover_status,database_role,open_mode from v$database;
SWITCHOVER_STATUS DATABASE_ROLE OPEN_MODE
-------------------- ------------------------------------
SESSIONS ACTIVE PRIMARY READ WRITE
記住:這時候需要在現在的備庫(原先的主庫)開啟實時同步
SQL> alter database open;
Database altered.
SQL> alter database recover managed standby database using current logfile disconnect from session;
Database altered.
到此DG switover切換完成,驗證方法同上。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。