dg搭建
主库准备:
select name,log_mode,force_logging from v$database;
打开归档日志:
alter system set log_archive_dest_1='location=+ARCH' sid='*';
shutdown immediate;
startup nomount;
alter database archivelog;
startup;
打开强制日志:
alter database force logging;
select INST_ID,name,force_logging from gv$database;
主备,添加修改standby日志组,一个实例的standby都要比redo多一组
alter database add standby logfile THREAD 1 group 16 size 1024M;
alter database add standby logfile THREAD 2 group 17 size 1024M;
alter database drop logfile group #;
添加修改redo
alter database drop standby logfile group #;
alter database add logfile thread thread# group GROUP# ('$logfile') size 1024m;
备库打开,standby自动管理
alter system set standby_file_management=auto;
检查redo和standby日志组
select GROUP#, THREAD# ,BYTES/1024/1024/1024 G ,STATUS ,MEMBERS from v$log order by 2;
select GROUP#, THREAD# ,BYTES/1024/1024/1024 G ,STATUS from v$standby_log;
主库复制密码文件到本地
asmcmd
ASMCMD> cd +DATA/ORCL/PASSWORD
ASMCMD> ls
pwdtccs.256.XXX
ASMCMD> pwcopy +DATA/ORCL/PASSWORD/pwdorcl.256.XXX /home/grid/
或
ASMCMD> pwcopy pwdorcl.256.XXX /home/grid/
传输密码文件到备库
scp /home/grid/pwdorcl.256.XXX xxx.xxx.xxx.xxx:/home/grid/
通过pwcopy复制密码文件到备库ASM 下
ASMCMD> pwcopy /home/grid/pwdorcl.256.XXX +DATA/ORCL/PASSWORD --dbuniquename orclstb
主库进行修改参数
SQL> alter system set LOG_ARCHIVE_CONFIG='DG_CONFIG=(XXXlpjc, XXXadg)';
System altered.
SQL> alter system set LOG_ARCHIVE_DEST_1='LOCATION=+ARCH VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=XXXlpjc';
System altered.
SQL> alter system set LOG_ARCHIVE_DEST_2='SERVICE=XXXadg LGWR ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=XXXadg';
System altered.
SQL> alter system set LOG_ARCHIVE_DEST_STATE_1=ENABLE;
System altered.
SQL> alter system set LOG_ARCHIVE_DEST_STATE_2=ENABLE;
System altered.
SQL> alter system set standby_file_management=auto;
System altered.
SQL> alter system set FAL_SERVER=XXXadg;
System altered.
SQL> alter system set FAL_CLIENT=XXXlpjc;
System altered.
如需进行地址转换
alter system set db_file_name_convert='+DATA','+DATA' scope=spfile;
alter system set log_file_name_convert='+ARCH','+DATA' scope=spfile;
–该参数需要重启,备库时生效
传输到备库,用pfile启动到nomount
create pfile='/home/oracle/initorclstb.ora' from spfile;
备库修改参数
备库添加监听静态注册
alter system set LOG_ARCHIVE_CONFIG='DG_CONFIG=(XXXadg,XXXlpjc)';
alter system set LOG_ARCHIVE_DEST_1='LOCATION=+ARCH VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=XXXadg';
alter system set LOG_ARCHIVE_DEST_2='SERVICE=XXXlpjc LGWR ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=XXXlpjc';
alter system set LOG_ARCHIVE_DEST_STATE_1=ENABLE;
alter system set LOG_ARCHIVE_DEST_STATE_2=ENABLE;
alter system set FAL_SERVER=XXXlpjc;
alter system set FAL_CLIENT=XXXadg;
alter system set standby_file_management=auto;
监听
备库在listener.ora中添加:
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(SID_NAME = PLSExtProc)
(ORACLE_HOME = /u01/app/oracle/product/19.0.0.0/dbhome_1)
(PROGRAM = extproc)
)
(SID_DESC =
(GLOBAL_DBNAME = orclstb)
(ORACLE_HOME = /u01/app/oracle/product/19.0.0.0/dbhome_1)
(SID_NAME = XXXstb)
)
)
主备添加监听,ur=a,备库的adg监听必须添加防止监听状态block
XXXADG =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = XXXadg)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = XXXadg)
( UR = A )
)
)
XXXLPJC =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = XXX)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = XXXlpjc)
( UR = A )
)
)
如备库db没有添加到crs中
srvctl add database -d XXXadg -o /u01/app/oracle/product/19.0.0.0/dbhome_1 -p '+DATA/XXXADG/PARAMETERFILE/spfile.287.1137863237' -pwfile '+DATA/XXXADG/PASSWORD/pwdorclstb.257.1076153149 ' -i XXXadg -y AUTOMATIC -r physical_standby
备库RAC,需要把两个实例也加到集群管理,否则数据库无法跟随集群启动:
srvctl add instance -d XXX -i orcl1 -n XXX
srvctl add instance -d XXX -i orcl2 -n XXX
注册后,即便实例是启动的,在集群资源中同样显示未启动,需要执行以下命令:
srvctl start database -d XXX
添加密码文件
srvctl modify database –d XXX –pwfile
恢复
duplicate恢复
vi rman.rbv
duplicate target database for standby from active database nofilenamecheck;
vi bak.sh
rman target sys/oracle@orcl auxiliary sys/oracle@xx.xx.xx.xx:1521/orclstb cmdfile=/home/oracle/rman.rbv log=/home/oracle/rman.log append
nohup sh /home/oracle/bak.sh &
tail -111f rman.log
备份片生成备库
备份主库:
rman target /
configure channel device type disk format '/home/oracle/rmanbk/%d_%I_%s_%p.bkp';
backup as compressed backupset database include current controlfile for standby plus archivelog;
将备份传输至备库
[oracle@up rmanbk]$ scp orcl_3078169696_* xxx.xxx.xxx.xxx:/home/oracle/rmanbk/
列出控制文件
rman target /
list backup of controlfile;
备库恢复控制文件
rman target /
restore standby controlfile from '/home/oracle/rmanbk/orcl_XXXX.bkp';
sql 'alter database mount';
进行数据恢复
run {
allocate channel c1 type disk;
allocate channel c2 type disk;
allocate channel c3 type disk;
allocate channel c4 type disk;
restore database;
recover database;
release channel c1;
release channel c2;
release channel c3;
release channel c4;
}
备库相关命令
–1.查询主备的同步情况
set linesize 150;
set pagesize 20;
column name format a13;
column value format a20;
column unit format a30;
column TIME_COMPUTED format a30;
select name,value,unit,time_computed from v$dataguard_stats where name in (‘transport lag’,’apply lag’);
备库查询
alter session set nls_date_format=’yyyy-mm-dd hh24:mi:ss’;
select THREAD#,count(FIRST_TIME) from v$archived_log where APPLIED=’NO’ group by THREAD#;
select THREAD#,min(FIRST_TIME) from v$archived_log where APPLIED=’NO’ group by THREAD#;
select THREAD#,min(SEQUENCE#) from v$archived_log where APPLIED=’NO’ group by THREAD#;
select BACKUP_COUNT from v$archived_log where THREAD#=&1 and SEQUENCE#=&2;
–2.查询备库的进程状态
SELECT PROCESS, STATUS,SEQUENCE#,thread# FROM V$MANAGED_STANDBY;
–3.查询备库的角色
set linesize 150;
column DBNAME format a6;
column DBUNAME format a10;
column cftype format a8;
column OPEN_MODE format a20;
column DATABASE_ROLE format a18;
select name dbname,db_unique_name dbuname,controlfile_type cftype,database_role,open_mode from v$database;
–4.查询备库的日志应用模式
SELECT RECOVERY_MODE FROM V$ARCHIVE_DEST_STATUS WHERE DEST_ID=1;
RECOVERY_MODE
———————————————————————
MANAGED REAL TIME APPLYs
–5.开启日志应用进程:
–应用stanby 实时同步
SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE USING CURRENT LOGFILE DISCONNECT;
Database altered.
并行应用日志:
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE using current logfile DISCONNECT FROM SESSION parallel 8;
–6.取消日志应用
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE CANCEL;
–7. 查看ADG日志差:
SELECT /*+rule*/ ARCH.THREAD# “Thread”,
ARCH.SEQUENCE# “Last Sequence Received”,
APPL.SEQUENCE# “Last Sequence Applied”,
(ARCH.SEQUENCE# – APPL.SEQUENCE#) “Difference”
FROM (SELECT THREAD#, SEQUENCE#
FROM V$ARCHIVED_LOG
WHERE (THREAD#, FIRST_CHANGE#) IN
(SELECT THREAD#, MAX(FIRST_CHANGE#)
FROM V$ARCHIVED_LOG
GROUP BY THREAD#)
GROUP BY THREAD#, SEQUENCE#) ARCH,
(SELECT THREAD#, SEQUENCE#
FROM V$LOG_HISTORY
WHERE (THREAD#, FIRST_CHANGE#) IN
(SELECT THREAD#, MAX(FIRST_CHANGE#)
FROM V$LOG_HISTORY
GROUP BY THREAD#)) APPL
WHERE ARCH.THREAD# = APPL.THREAD#
ORDER BY 1;
服务器托管,北京服务器托管,服务器租用 http://www.fwqtg.net
机房租用,北京机房租用,IDC机房托管, http://www.fwqtg.net
相关推荐: 看动画,轻松学习23种C++设计模式-我闻琵琶已叹息
download:看动画,轻松学习23种C++设计模式 如听仙乐耳暂明音乐,心灵,美好生活人们常说“音乐是一种语言”,因为它不分国界、不分种族,能够用独特的方式传达情感和思想。在快节奏的现代生活中,很多人都深受各种压力的困扰,而寻找一个可以让自己放松、愉悦心情…