首页 > 其他分享 >scn增量备份恢复dataguard从库

scn增量备份恢复dataguard从库

时间:2023-04-23 14:35:57浏览次数:40  
标签:scn database NO dbf dataguard SQL YES 从库 u01

环境:
OS:Centos 7
DB:19.3.0.0

 

1.正常同步情况下的scn主从是一致的

主库查询:

SQL> select SEQUENCE#,FIRST_CHANGE#,NEXT_CHANGE#,APPLIED,STATUS from v$archived_log t where name='tnsslavea';

SEQUENCE# FIRST_CHANGE# NEXT_CHANGE# APPLIED    STATUS
--------- ------------- ------------ ---------- ----------
        6       2039053      2040717 YES        A
        7       2040717      2207453 YES        A
        8       2207453      2298178 YES        A
        9       2298178      2458419 YES        A
       10       2458419      2634622 YES        A
       11       2634622      2634641 YES        A
       12       2634641      2634648 YES        A

7 rows selected.

 

从库查询

SQL> select SEQUENCE#,FIRST_CHANGE#,NEXT_CHANGE#,APPLIED,STATUS from v$archived_log;

SEQUENCE# FIRST_CHANGE# NEXT_CHANGE# APPLIED    STATUS
--------- ------------- ------------ ---------- ----------
        6       2039053      2040717 YES        A
        7       2040717      2207453 YES        A
        8       2207453      2298178 YES        A
        9       2298178      2458419 YES        A
       10       2458419      2634622 IN-MEMORY  A
       11       2634622      2634641 YES        A
       12       2634641      2634648 YES        A

7 rows selected.

 

2.停掉从库
SQL> alter database recover managed standby database cancel;

Database altered.

SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.

 

3.主库上生成归档日志
SQL> alter system switch logfile;

System altered.

SQL> alter system switch logfile;

System altered.

SQL> alter system switch logfile;

System altered.

 

4.然后将主库生成的归档日志删除掉(这个时候是不会同步到从库的)
SQL> !rm /u01/archivelog/1_13_1134611537.dbf

SQL> !rm /u01/archivelog/1_14_1134611537.dbf

SQL> !rm /u01/archivelog/1_15_1134611537.dbf

 

5.尝试启动从库

SQL> startup
ORACLE instance started.

Total System Global Area 3019895288 bytes
Fixed Size                  8901112 bytes
Variable Size             620756992 bytes
Database Buffers         2382364672 bytes
Redo Buffers                7872512 bytes
Database mounted.
Database opened.
SQL> alter database recover managed standby database using current logfile disconnect from session;

Database altered.

SQL> SELECT * FROM V$ARCHIVE_GAP;

no rows selected

这个时候该查询没有数据,删除主库归档日志,oracle不认为这个是gap

主库查询归档应用情况

set linesize 1000;
column name format a48;
column SEQUENCE# format 99;
column APPLIED format a5;
column APPLIED format a5;

SQL> select name,SEQUENCE#,APPLIED,APPLIED from v$archived_log t order by SEQUENCE#;

NAME                                             SEQUENCE# APPLI APPLI
------------------------------------------------ --------- ----- -----
/u01/archivelog/1_5_1134611537.dbf                       5 NO    NO
/u01/archivelog/1_6_1134611537.dbf                       6 NO    NO
tnsslavea                                                6 YES   YES
/u01/archivelog/1_7_1134611537.dbf                       7 NO    NO
tnsslavea                                                7 YES   YES
tnsslavea                                                8 YES   YES
/u01/archivelog/1_8_1134611537.dbf                       8 NO    NO
/u01/archivelog/1_9_1134611537.dbf                       9 NO    NO
tnsslavea                                                9 YES   YES
tnsslavea                                               10 YES   YES
/u01/archivelog/1_10_1134611537.dbf                     10 NO    NO

NAME                                             SEQUENCE# APPLI APPLI
------------------------------------------------ --------- ----- -----
/u01/archivelog/1_11_1134611537.dbf                     11 NO    NO
tnsslavea                                               11 YES   YES
/u01/archivelog/1_12_1134611537.dbf                     12 NO    NO
tnsslavea                                               12 YES   YES
/u01/archivelog/1_13_1134611537.dbf                     13 NO    NO
/u01/archivelog/1_14_1134611537.dbf                     14 NO    NO
/u01/archivelog/1_15_1134611537.dbf                     15 NO    NO

18 rows selected.

 

发现13 14和15是没有归档到从库的

在从库上查询

SQL> set linesize 1000;
SQL> column name format a48;
SQL> column SEQUENCE# format 99;
SQL> column APPLIED format a5;
SQL> column APPLIED format a5;
SQL> select name,SEQUENCE#,APPLIED,APPLIED from v$archived_log t order by SEQUENCE#;

NAME                                             SEQUENCE# APPLI APPLI
------------------------------------------------ --------- ----- -----
/u01/archivelog/1_6_1134611537.dbf                       6 YES   YES
/u01/archivelog/1_7_1134611537.dbf                       7 YES   YES
/u01/archivelog/1_8_1134611537.dbf                       8 YES   YES
/u01/archivelog/1_9_1134611537.dbf                       9 YES   YES
/u01/archivelog/1_10_1134611537.dbf                     10 YES   YES
/u01/archivelog/1_11_1134611537.dbf                     11 YES   YES
/u01/archivelog/1_12_1134611537.dbf                     12 YES   YES

7 rows selected.

从库的归档只应用到了12

 

##################################恢复##########################################

1.设置源端log_archive_dest_state_2为defer
alter system set log_archive_dest_state_2=defer scope=both;

完成恢复后需要修改回来
alter system set log_archive_dest_state_2=enable scope=both;

2.备库上查询当前的scn
SQL> select to_char(current_scn) from v$database;

TO_CHAR(CURRENT_SCN)
----------------------------------------
2635413

或是查询从库已经应用了的最大归档日志记录的NEXT_CHANGE#
SQL> select t.NEXT_CHANGE#
2 from v$archived_log t
3 where t.SEQUENCE# =
4 (select max(SEQUENCE#) from v$archived_log where APPLIED = 'YES');

NEXT_CHANGE#
------------
2634648

本次实验实验第一种方法,即使用 2635413 在主库上进行增量备份

 

3.在主库上创建一个备库的控制文件
SQL>alter database create standby controlfile as '/home/oracle/standby.ctl';

 

4.确认主备GAP期间是否新增数据文件
SQL> select file# from v$datafile where creation_change# > =2635413;

no rows selected

主库根据备库scn号进行增量备份

rman target /
RMAN>run{
allocate channel c1 type disk;
allocate channel c2 type disk;
backup INCREMENTAL from scn 2635413 database format '/u01/rmanbak/incre_%U';
release channel c1;
release channel c2;
}

注意:如果存在新增数据文件,备库恢复时需要先restore新添加的数据文件。
c.将增量备份和控制文件拷贝到备库上

 

5.主库拷贝增量备份和控制文件你至备库
scp /u01/rmanbak/incre* [email protected]:/u01/rmanbak/
scp /home/oracle/standby.ctl [email protected]:/home/oracle/

注意:确认备库的磁盘空间是否足够存放。
d.使用新的控制文件将备库启动到mount状态

6.备库关闭数据库实例,开启至nomount状态
SQL>sqlplus / as sysdba
SQL>shutdown immediate
SQL>startup nomount

7.备库恢复新的控制文件
rman target /
RMAN>restore controlfile from '/home/oracle/standby.ctl';

8.备库开启到mount状态
SQL>alter database mount;

增量备份注册到RMAN的catalog,取消日志应用,恢复增量备份
确认备库已关闭DG同步进程


9.备库rman注册增量备份文件
rman target /
RMAN>catalog start with '/u01/rmanbak/';

10.备库开启恢复增量备份--done
RMAN>recover database noredo;

11.开启备库的恢复进程
SQL>sqlplus / as sysdba
SQL>alter database open;
SQL> alter database open;
alter database open
*
ERROR at line 1:
ORA-10458: standby database requires recovery
ORA-01152: file 1 was not restored from a sufficiently old backup
ORA-01110: data file 1: '/u01/app/oracle/oradata/slavea/system01.dbf'

这个时候打开数据库报错误,先应用日志后面再打开

SQL>alter database recover managed standby database using current logfile disconnect from session;

12.主库重新激活同步
SQL>sqlplus / as sysdba
SQL>ALTER SYSTEM SET LOG_ARCHIVE_DEST_STATE_2=enable;

 

13.打开数据库

SQL> alter database open;
alter database open
*
ERROR at line 1:
ORA-10456: cannot open standby database; media recovery session may be in
progress


SQL> alter database recover managed standby database cancel;

Database altered.

SQL> alter database open;

Database altered.

SQL> alter database recover managed standby database using current logfile disconnect from session;

 

说明:若goldengate是部署在adg的从库的话,做了增量恢复后,需要重新部署ogg
因为主库的归档13 14 15是丢失了的,那么从库也没有这几个归档日志,ogg找不到这些归档日志会报错误

2023-04-23 02:03:47  ERROR   OGG-02828  Not able to establish initial position for sequence 13, rba 3,472,912, Could 
not find archived log for sequence 13 thread 1 under default destinations SQL <SELECT  name   FROM v$archived_log   W
HERE sequence# = :1 AND         thread# = :2 AND         resetlogs_id = :3 AND         archived = 'YES' AND         d
eleted = 'NO' >, error retrieving redo file name for sequence 13, archived = 1, use_alternate = 0.

 

标签:scn,database,NO,dbf,dataguard,SQL,YES,从库,u01
From: https://www.cnblogs.com/hxlasky/p/17346453.html

相关文章

  • 28 27 | 主库出问题了,从库怎么办?
    在前面的第24、25和26篇文章中,我和你介绍了MySQL主备复制的基础结构,但这些都是一主一备的结构。大多数的互联网应用场景都是读多写少,因此你负责的业务,在发展过程中很可能先会遇到读性能的问题。而在数据库层解决读性能问题,就要涉及到接下来两篇文章要讨论的架构:一主多从。今天这......
  • 使用了enabled_PDBs_on_standby参数后,主库新增pdb后从库的操作
    环境:OS:Centos7DB:12.2.0.1拓扑:1主1从的dataguard 1.从库查看参数enabled_PDBs_on_standbySQL>showparametersenabled_PDBs_on_standbyNAMETYPEVALUE--------------------------------------------------------------......
  • Oracle Dataguard安装先决条件与注意事项
    业务方要求把一个单实例DB做成dg,由于之前是业务方自己安装管理的,过去检查一番,发现这个库软件居然不是企业版的。整理了几篇相关的官方文档链接给业务方,反馈Oracle标准版不支持dg。顺便也根据官方文档(19c)整理一份checklist,方便以后使用。一、硬件与OS要求1.主库与所有从库安装版本......
  • Dataguard原理
    Dataguard原理 1.DataGuard概要​OracleDataGuard是Oracle自带的数据同步功能,基本原理是将日志文件从原数据库传输到目标数据库,然后在目标数据库上应用这些日志文件,从而使目标数据库与源数据库保持同步,是一种数据库级别的高可用性方案。DataGuard可以提供Oracle数据库的......
  • 在awescnb主题下设置音乐外链
    一、主题环境(设置略)主题是:https://www.yuque.com/awescnb/user/tmpomo二、用某些网站在线获取音乐外链、歌词推荐刘志进实验室的音乐提取:https://music.liuzhijin.cn/1.进入在线网站搜索音乐,最好不要有会员和登录才能听的,一般有多个版本,找到一个免费听的就行。这里我选择其......
  • percona-toolkit工具:使用pt-table-checksum检查MySQL主从库的差异
    环境介绍CentOS7.6MySQL5.7PerconaToolkit3.4.0 下载并安装PerconaToolkit从WEB端下载https://www.percona.com/downloads或者通过wget下载[root]#wgethttps://downloads.percona.com/downloads/percona-toolkit/3.5.2/binary/redhat/7/x86_64/percona-toolkit-3.......
  • [CISCN 2019华北Day2]Web1
    [CISCN2019华北Day2]Web1提示了flag表中有flag列,我们只能提交id输入1和2都有文本输出,3的时候出现报错输入1’#出现以下图片所示情况,说明应该存在过滤我用fuzz跑一下,看一下哪些字符被过滤了发现空格,or,order,union以及报错注入的相关字符都被过滤了。但是select和from没有......
  • 群晖的docker设置MySQL从库功能
    群晖的docker设置MySQL从库功能主库与正常设置无区别,新建账号并授权拷贝binlog即可,注意密码强度,最好不要给任意IP访问权限;数据安全无小事以镜像为8.0.30为例在高级设置中添加环境变量即可MYSQL_ROOT_PASSWORD=e0a1021570daa600MYSQL_ALLOW_EMPTY_PASSWORD=no注意为方便修......
  • 博客园主题美化配置(Awescnb)
    平时比较喜欢捣鼓主题,但是没办法见一个爱一个,或者有时候就一个主题用腻了,想尝试另一个主题,此处记录下是为了切换是更快的还原当初的配置,同时可以给广大网友提供参考~当前主题为awescnb系列主题中的geek主题 Awescnb文档Awescnb作者博客配置步骤一、准备工作申请js......
  • 搭建redis主从复制集群环境时,当从库执行slaveof命令时报错“Error condition on socke
    问题描述:搭建redis主从复制集群环境时,当从库执行slaveof命令时报错“ErrorconditiononsocketforSYNC:Noroutetohost”,如下所示:操作系统:rhel7.964位数据库:redis6.2.6主机名:主库leo-redis626-a,从库leo-redis626-b.1、异常重现[[email protected]]#p......