首页 > 其他分享 >scn增量备份恢复dataguard从库(出现gap后主库有添加新的数据文件)

scn增量备份恢复dataguard从库(出现gap后主库有添加新的数据文件)

时间:2023-04-24 10:13:01浏览次数:40  
标签:scn database NO gap 库有 SQL YES dbf 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.添加数据文件

alter tablespace TBS_OGG add datafile '/u01/app/oracle/oradata/SLNNGK/tps_ogg02.dbf' size 10m;

 

6.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

该视图查询不出来,可以尝试使用如下的语句查询(在从库上查询)

select USERENV('Instance'), high.thread#, low.lsq, high.hsq
 from
  (select a.thread#, rcvsq, min(a.sequence#)-1 hsq
   from v$archived_log a,
        (select lh.thread#, lh.resetlogs_change#, max(lh.sequence#) rcvsq
           from v$log_history lh, v$database_incarnation di
          where lh.resetlogs_time = di.resetlogs_time
            and lh.resetlogs_change# = di.resetlogs_change#
            and di.status = 'CURRENT'
            and lh.thread# is not null
            and lh.resetlogs_change# is not null
            and lh.resetlogs_time is not null
         group by lh.thread#, lh.resetlogs_change#
        ) b
   where a.thread# = b.thread#
     and a.resetlogs_change# = b.resetlogs_change#
     and a.sequence# > rcvsq
   group by a.thread#, rcvsq) high,
 (select srl_lsq.thread#, nvl(lh_lsq.lsq, srl_lsq.lsq) lsq
   from
     (select thread#, min(sequence#)+1 lsq
      from
        v$log_history lh, x$kccfe fe, v$database_incarnation di
      where to_number(fe.fecps) <= lh.next_change#
        and to_number(fe.fecps) >= lh.first_change#
        and fe.fedup!=0 and bitand(fe.festa, 12) = 12
        and di.resetlogs_time = lh.resetlogs_time
        and lh.resetlogs_change# = di.resetlogs_change#
        and di.status = 'CURRENT'
      group by thread#) lh_lsq,
     (select thread#, max(sequence#)+1 lsq
      from
        v$log_history
      where (select min( to_number(fe.fecps))
             from x$kccfe fe
             where fe.fedup!=0 and bitand(fe.festa, 12) = 12)
      >= next_change#
      group by thread#) srl_lsq
   where srl_lsq.thread# = lh_lsq.thread#(+)
  ) low
 where low.thread# = high.thread#
 and lsq < = hsq
 and hsq > rcvsq

主库查询归档应用情况

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

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

NAME                                             SEQUENCE# APPLI standby_dest
------------------------------------------------ --------- ----- -----
/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是没有归档到从库的

 

在从库上查询

set linesize 1000;
column name format a48;
column SEQUENCE# format 99;
column APPLIED format a5;
column APPLIED format a5;
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)
----------------------------------------
2847423

 

或是查询从库已经应用了的最大归档日志记录的NEXT_CHANGE#

select t.NEXT_CHANGE#
  from v$archived_log t
 where t.SEQUENCE# =
       (select max(SEQUENCE#) from v$archived_log where APPLIED = 'YES');

NEXT_CHANGE#
------------
     2834318

 

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

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

 

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

FILE# NAME
---------- ------------------------------------------------
2 /u01/app/oracle/oradata/SLNNGK/tps_ogg02.dbf

 

主库根据备库scn号进行增量备份+新增数据文件备份

rman target /
RMAN>run{
allocate channel c1 type disk;
allocate channel c2 type disk;
backup datafile 2 format '/u01/rmanbak/datafile_%U.bak' tag 'datafile';
backup INCREMENTAL from scn 2847423 database format '/u01/rmanbak/incre_%U';
release channel c1;
release channel c2;
}

 

5.主库拷贝增量备份和控制文件你至备库

scp /u01/rmanbak/incre* [email protected]:/u01/rmanbak/
scp /u01/rmanbak/datafile* [email protected]:/u01/rmanbak/
scp /home/oracle/standby.ctl [email protected]:/home/oracle/

 

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;

 

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

 

10.备库开启恢复增量备份-
RMAN>restore datafile 2;
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;

 

标签:scn,database,NO,gap,库有,SQL,YES,dbf,u01
From: https://www.cnblogs.com/hxlasky/p/17348564.html

相关文章

  • 无法访问org.springframework.boot.SpringApplication
    用idea创建的springboot项目,版本不对。换成<parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.5.6</version><!--2.7.10-->&l......
  • scn增量备份恢复dataguard从库
    环境:OS:Centos7DB:19.3.0.0 1.正常同步情况下的scn主从是一致的主库查询:SQL>selectSEQUENCE#,FIRST_CHANGE#,NEXT_CHANGE#,APPLIED,STATUSfromv$archived_logtwherename='tnsslavea';SEQUENCE#FIRST_CHANGE#NEXT_CHANGE#APPLIEDSTATUS----------------......
  • 【MySQL】InnoDB中的GAP锁详解
    测试数据:CREATETABLE`lock_test`(`a`int(11)NOTNULLAUTO_INCREMENT,`b`int(11)NOTNULL,`c`int(11)NOTNULL,`d`int(11)NOTNULL,PRIMARYKEY(`a`),UNIQUEKEY`idx_b`(`b`),KEY`idx_c`(`c`))ENGINE=InnoDBDEFAULTCHARSET=latin1;IN......
  • 获取博客园的metablogapi
    注意:metablogapi为rpc服务,详细解释如下:https://www.cnblogs.com/mq0036/p/12766789.html如何获取:首先进入:https://i.cnblogs.com/settings然后拉到最下方,复制相应的metawebolg链接生成相应的metaweblog令牌......
  • java: 无法访问org.springframework.boot.SpringApplication
    在运行springboot项目中的Application.java时出现:错误的类文件: /D:/install/Maven/apache-maven-3.6.1/repository/org/springframework/boot/spring-boot/3.0.5/spring-boot-3.0.5.jar!/org/springframework/boot/SpringApplication.class   类文件具有错误的版本 61.0, ......
  • 在awescnb主题下设置音乐外链
    一、主题环境(设置略)主题是:https://www.yuque.com/awescnb/user/tmpomo二、用某些网站在线获取音乐外链、歌词推荐刘志进实验室的音乐提取:https://music.liuzhijin.cn/1.进入在线网站搜索音乐,最好不要有会员和登录才能听的,一般有多个版本,找到一个免费听的就行。这里我选择其......
  • [CISCN 2019华北Day2]Web1
    [CISCN2019华北Day2]Web1提示了flag表中有flag列,我们只能提交id输入1和2都有文本输出,3的时候出现报错输入1’#出现以下图片所示情况,说明应该存在过滤我用fuzz跑一下,看一下哪些字符被过滤了发现空格,or,order,union以及报错注入的相关字符都被过滤了。但是select和from没有......
  • 解决在创建springboot项目中遇到:Error:(3, 32) java: 无法访问org.springframework.bo
    解决在创建springboot项目中遇到:Error:(3,32)java:无法访问org.springframework.boot.SpringApplication File--->ProjectStructure    选择对应版本        File--->Settings--->Build,Execution,Deployment    修改对应版本 ......
  • 博客园主题美化配置(Awescnb)
    平时比较喜欢捣鼓主题,但是没办法见一个爱一个,或者有时候就一个主题用腻了,想尝试另一个主题,此处记录下是为了切换是更快的还原当初的配置,同时可以给广大网友提供参考~当前主题为awescnb系列主题中的geek主题 Awescnb文档Awescnb作者博客配置步骤一、准备工作申请js......
  • 记录kali中安装gaps
    之前的gaps坏掉了,直接删除重装了,这里简单记录一下1.下载安装文件个人推荐直接访问GitHub网址进行下载,网址:https://github.com/nemanja-m/gaps2.将下载得到的压缩包解压,进入gaps目录下cdgaps3.这时检查requirements.txt中各个模块的版本,保证和自己的pyhon3已安装的模块版本......