Oracle Dataguard(主库为单节点)配置详解(4):将主库复制到备库并启动同步

Oracle Dataguard(主库为单节点)配置详解(4):将主库复制到备库并启动同步

目录

一、在主库执行备份操作

1、在主库创建备份目录
shell 复制代码
[oracle@ora dbs]$ mkdir /home/oracle/bak0101
[oracle@ora dbs]$ ll /home/oracle/
总用量 76
drwxr-xr-x 2 oracle oinstall     6 1月   1 19:48 bak0101
-rwxr-xr-x 1 oracle oinstall 44551 12月 30 21:44 dbca.rsp
-rw-r--r-- 1 oracle oinstall 25283 12月 30 21:12 db_install.rsp
drwxr-xr-x 3 oracle oinstall   114 12月 30 20:52 soft
-rw-r--r-- 1 oracle oinstall  1386 1月   1 17:31 spfile1231.ora
2、使用 RMAN 命令全备数据库

(1)设置备份参数:备份到磁盘,使用 6 个通道

sql 复制代码
RMAN> configure device type disk parallelism 6 backup type to backupset;

using target database control file instead of recovery catalog
new RMAN configuration parameters:
CONFIGURE DEVICE TYPE DISK PARALLELISM 6 BACKUP TYPE TO BACKUPSET;
new RMAN configuration parameters are successfully stored

(2)设置备份参数:设置备份文件的位置及文件名格式

sql 复制代码
RMAN> configure channel device type disk format '/home/oracle/bak0101/%d_%I_%s_%p_%T.bkp';

new RMAN configuration parameters:
CONFIGURE CHANNEL DEVICE TYPE DISK FORMAT   '/home/oracle/bak0101/%d_%I_%s_%p_%T.bkp';
new RMAN configuration parameters are successfully stored

(3)备份控制文件

sql 复制代码
-- 备份成 standby 类型的控制文件
RMAN> backup current controlfile for standby format ='/home/oracle/bak0101/control_bak_%s.bak';

Starting backup at 01-JAN-25
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=40 device type=DISK
allocated channel: ORA_DISK_2
channel ORA_DISK_2: SID=44 device type=DISK
allocated channel: ORA_DISK_3
channel ORA_DISK_3: SID=38 device type=DISK
allocated channel: ORA_DISK_4
channel ORA_DISK_4: SID=43 device type=DISK
allocated channel: ORA_DISK_5
channel ORA_DISK_5: SID=1 device type=DISK
allocated channel: ORA_DISK_6
channel ORA_DISK_6: SID=42 device type=DISK
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
including standby control file in backup set
channel ORA_DISK_1: starting piece 1 at 01-JAN-25
channel ORA_DISK_1: finished piece 1 at 01-JAN-25
piece handle=/home/oracle/bak0101/control_bak_12.bak tag=TAG20250101T205548 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 01-JAN-25

(4)备份数据库

sql 复制代码
RMAN> backup as compressed backupset database;

Starting backup at 01-JAN-25
using channel ORA_DISK_1
using channel ORA_DISK_2
using channel ORA_DISK_3
using channel ORA_DISK_4
using channel ORA_DISK_5
using channel ORA_DISK_6
channel ORA_DISK_1: starting compressed full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00001 name=/usr/local/oradata/hisdb/system01.dbf
channel ORA_DISK_1: starting piece 1 at 01-JAN-25
channel ORA_DISK_2: starting compressed full datafile backup set
channel ORA_DISK_2: specifying datafile(s) in backup set
input datafile file number=00002 name=/usr/local/oradata/hisdb/sysaux01.dbf
channel ORA_DISK_2: starting piece 1 at 01-JAN-25
channel ORA_DISK_3: starting compressed full datafile backup set
channel ORA_DISK_3: specifying datafile(s) in backup set
input datafile file number=00003 name=/usr/local/oradata/hisdb/undotbs01.dbf
channel ORA_DISK_3: starting piece 1 at 01-JAN-25
channel ORA_DISK_4: starting compressed full datafile backup set
channel ORA_DISK_4: specifying datafile(s) in backup set
channel ORA_DISK_5: starting compressed full datafile backup set
channel ORA_DISK_5: specifying datafile(s) in backup set
input datafile file number=00004 name=/usr/local/oradata/hisdb/users01.dbf
channel ORA_DISK_5: starting piece 1 at 01-JAN-25
channel ORA_DISK_6: starting compressed full datafile backup set
channel ORA_DISK_6: specifying datafile(s) in backup set
including current SPFILE in backup set
channel ORA_DISK_6: starting piece 1 at 01-JAN-25
including current control file in backup set
channel ORA_DISK_4: starting piece 1 at 01-JAN-25
channel ORA_DISK_6: finished piece 1 at 01-JAN-25
piece handle=/home/oracle/bak0101/HISDB_2101731232_7_1_20250101.bkp tag=TAG20250101T195259 comment=NONE
channel ORA_DISK_6: backup set complete, elapsed time: 00:00:01
channel ORA_DISK_3: finished piece 1 at 01-JAN-25
piece handle=/home/oracle/bak0101/HISDB_2101731232_4_1_20250101.bkp tag=TAG20250101T195259 comment=NONE
channel ORA_DISK_3: backup set complete, elapsed time: 00:00:03
channel ORA_DISK_4: finished piece 1 at 01-JAN-25
piece handle=/home/oracle/bak0101/HISDB_2101731232_5_1_20250101.bkp tag=TAG20250101T195259 comment=NONE
channel ORA_DISK_4: backup set complete, elapsed time: 00:00:03
channel ORA_DISK_5: finished piece 1 at 01-JAN-25
piece handle=/home/oracle/bak0101/HISDB_2101731232_6_1_20250101.bkp tag=TAG20250101T195259 comment=NONE
channel ORA_DISK_5: backup set complete, elapsed time: 00:00:05
channel ORA_DISK_2: finished piece 1 at 01-JAN-25
piece handle=/home/oracle/bak0101/HISDB_2101731232_3_1_20250101.bkp tag=TAG20250101T195259 comment=NONE
channel ORA_DISK_2: backup set complete, elapsed time: 00:00:28
channel ORA_DISK_1: finished piece 1 at 01-JAN-25
piece handle=/home/oracle/bak0101/HISDB_2101731232_2_1_20250101.bkp tag=TAG20250101T195259 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:38
Finished backup at 01-JAN-25

(5)备份归档日志

sql 复制代码
--设置备份文件格式:
RMAN> configure channel device type disk format '/home/oracle/bak0101/arch_%d_%I_%s_%p_%T.bkp';

old RMAN configuration parameters:
CONFIGURE CHANNEL DEVICE TYPE DISK FORMAT   '/home/oracle/bak0101/%d_%I_%s_%p_%T.bkp';
new RMAN configuration parameters:
CONFIGURE CHANNEL DEVICE TYPE DISK FORMAT   '/home/oracle/bak0101/arch_%d_%I_%s_%p_%T.bkp';
new RMAN configuration parameters are successfully stored
released channel: ORA_DISK_1
released channel: ORA_DISK_2
released channel: ORA_DISK_3
released channel: ORA_DISK_4
released channel: ORA_DISK_5
released channel: ORA_DISK_6

-- 备份归档日志:
RMAN> backup as compressed backupset archivelog all;

Starting backup at 01-JAN-25
current log archived
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=43 device type=DISK
allocated channel: ORA_DISK_2
channel ORA_DISK_2: SID=38 device type=DISK
allocated channel: ORA_DISK_3
channel ORA_DISK_3: SID=40 device type=DISK
allocated channel: ORA_DISK_4
channel ORA_DISK_4: SID=44 device type=DISK
allocated channel: ORA_DISK_5
channel ORA_DISK_5: SID=45 device type=DISK
allocated channel: ORA_DISK_6
channel ORA_DISK_6: SID=46 device type=DISK
channel ORA_DISK_1: starting compressed archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=7 RECID=1 STAMP=1189224012
channel ORA_DISK_1: starting piece 1 at 01-JAN-25
channel ORA_DISK_2: starting compressed archived log backup set
channel ORA_DISK_2: specifying archived log(s) in backup set
input archived log thread=1 sequence=8 RECID=2 STAMP=1189272700
channel ORA_DISK_2: starting piece 1 at 01-JAN-25
channel ORA_DISK_3: starting compressed archived log backup set
channel ORA_DISK_3: specifying archived log(s) in backup set
input archived log thread=1 sequence=9 RECID=3 STAMP=1189272703
channel ORA_DISK_3: starting piece 1 at 01-JAN-25
channel ORA_DISK_4: starting compressed archived log backup set
channel ORA_DISK_4: specifying archived log(s) in backup set
input archived log thread=1 sequence=10 RECID=4 STAMP=1189281347
channel ORA_DISK_4: starting piece 1 at 01-JAN-25
channel ORA_DISK_2: finished piece 1 at 01-JAN-25
piece handle=/home/oracle/bak0101/arch_HISDB_2101731232_9_1_20250101.bkp tag=TAG20250101T195548 comment=NONE
channel ORA_DISK_2: backup set complete, elapsed time: 00:00:02
channel ORA_DISK_3: finished piece 1 at 01-JAN-25
piece handle=/home/oracle/bak0101/arch_HISDB_2101731232_10_1_20250101.bkp tag=TAG20250101T195548 comment=NONE
channel ORA_DISK_3: backup set complete, elapsed time: 00:00:02
channel ORA_DISK_4: finished piece 1 at 01-JAN-25
piece handle=/home/oracle/bak0101/arch_HISDB_2101731232_11_1_20250101.bkp tag=TAG20250101T195548 comment=NONE
channel ORA_DISK_4: backup set complete, elapsed time: 00:00:01
channel ORA_DISK_1: finished piece 1 at 01-JAN-25
piece handle=/home/oracle/bak0101/arch_HISDB_2101731232_8_1_20250101.bkp tag=TAG20250101T195548 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:04
Finished backup at 01-JAN-25

(6)查看备份文件信息

sql 复制代码
[oracle@ora bak0101]$ cd /home/oracle/bak0101
[oracle@ora bak0101]$ ll
总用量 308812
-rw-r----- 1 oracle oinstall  13821952 1月   1 20:57 arch_HISDB_2101731232_19_1_20250101.bkp
-rw-r----- 1 oracle oinstall   5672448 1月   1 20:57 arch_HISDB_2101731232_20_1_20250101.bkp
-rw-r----- 1 oracle oinstall     48640 1月   1 20:57 arch_HISDB_2101731232_21_1_20250101.bkp
-rw-r----- 1 oracle oinstall   2004992 1月   1 20:57 arch_HISDB_2101731232_22_1_20250101.bkp
-rw-r----- 1 oracle oinstall   1540608 1月   1 20:57 arch_HISDB_2101731232_23_1_20250101.bkp
-rw-r----- 1 oracle oinstall   9797632 1月   1 20:55 control_bak_12.bak
-rw-r----- 1 oracle oinstall 202989568 1月   1 20:57 HISDB_2101731232_13_1_20250101.bkp
-rw-r----- 1 oracle oinstall  76685312 1月   1 20:56 HISDB_2101731232_14_1_20250101.bkp
-rw-r----- 1 oracle oinstall   1359872 1月   1 20:56 HISDB_2101731232_15_1_20250101.bkp
-rw-r----- 1 oracle oinstall   1097728 1月   1 20:56 HISDB_2101731232_16_1_20250101.bkp
-rw-r----- 1 oracle oinstall   1097728 1月   1 20:56 HISDB_2101731232_17_1_20250101.bkp
-rw-r----- 1 oracle oinstall     98304 1月   1 20:56 HISDB_2101731232_18_1_20250101.bkp

二、把备份文件复制到备库

1、在备库上创建存放备份文件的目录
sql 复制代码
[oracle@oradg dbs]$ mkdir /home/oracle/bak11
2、把主库的备份文件复制到备库
sql 复制代码
[oracle@ora bak0101]$ scp * oracle@oradg:/home/oracle/bak11
oracle@oradg's password: 
arch_HISDB_2101731232_19_1_20250101.bkp       100%   13MB  13.2MB/s   00:00    
arch_HISDB_2101731232_20_1_20250101.bkp       100% 5540KB   5.4MB/s   00:00    
arch_HISDB_2101731232_21_1_20250101.bkp       100%   48KB  47.5KB/s   00:00    
arch_HISDB_2101731232_22_1_20250101.bkp       100% 1958KB   1.9MB/s   00:00    
arch_HISDB_2101731232_23_1_20250101.bkp       100% 1505KB   1.5MB/s   00:00    
control_bak_12.bak                            100% 9568KB   9.3MB/s   00:01    
HISDB_2101731232_13_1_20250101.bkp            100%  194MB  96.8MB/s   00:02    
HISDB_2101731232_14_1_20250101.bkp            100%   73MB  73.1MB/s   00:01    
HISDB_2101731232_15_1_20250101.bkp            100% 1328KB   1.3MB/s   00:01    
HISDB_2101731232_16_1_20250101.bkp            100% 1072KB   1.1MB/s   00:00    
HISDB_2101731232_17_1_20250101.bkp            100% 1072KB   1.1MB/s   00:00    
HISDB_2101731232_18_1_20250101.bkp            100%   96KB  96.0KB/s   00:00    
3、查看备库中的主库备份文件
sql 复制代码
[oracle@oradg dbs]$ cd /home/oracle/bak11
[oracle@oradg bak11]$ ll
总用量 308812
-rw-r----- 1 oracle oinstall  13821952 1月   1 20:58 arch_HISDB_2101731232_19_1_20250101.bkp
-rw-r----- 1 oracle oinstall   5672448 1月   1 20:58 arch_HISDB_2101731232_20_1_20250101.bkp
-rw-r----- 1 oracle oinstall     48640 1月   1 20:58 arch_HISDB_2101731232_21_1_20250101.bkp
-rw-r----- 1 oracle oinstall   2004992 1月   1 20:58 arch_HISDB_2101731232_22_1_20250101.bkp
-rw-r----- 1 oracle oinstall   1540608 1月   1 20:58 arch_HISDB_2101731232_23_1_20250101.bkp
-rw-r----- 1 oracle oinstall   9797632 1月   1 20:58 control_bak_12.bak
-rw-r----- 1 oracle oinstall 202989568 1月   1 20:58 HISDB_2101731232_13_1_20250101.bkp
-rw-r----- 1 oracle oinstall  76685312 1月   1 20:58 HISDB_2101731232_14_1_20250101.bkp
-rw-r----- 1 oracle oinstall   1359872 1月   1 20:58 HISDB_2101731232_15_1_20250101.bkp
-rw-r----- 1 oracle oinstall   1097728 1月   1 20:58 HISDB_2101731232_16_1_20250101.bkp
-rw-r----- 1 oracle oinstall   1097728 1月   1 20:58 HISDB_2101731232_17_1_20250101.bkp
-rw-r----- 1 oracle oinstall     98304 1月   1 20:58 HISDB_2101731232_18_1_20250101.bkp

三、在备库上恢复数据库

1、启动数据库到 nomount
sql 复制代码
SQL> startup nomount
ORACLE instance started.

Total System Global Area 1068937216 bytes
Fixed Size		    2260088 bytes
Variable Size		  331350920 bytes
Database Buffers	  729808896 bytes
Redo Buffers		    5517312 bytes
2、启动 rman,恢复控制文件,启动数据库到 mount

(1)查看备份的控制文件

sql 复制代码
[oracle@oradg ~]$ cd /home/oracle/bak11
[oracle@oradg bak11]$ ll
总用量 308812
-rw-r----- 1 oracle oinstall  13821952 1月   1 20:58 arch_HISDB_2101731232_19_1_20250101.bkp
-rw-r----- 1 oracle oinstall   5672448 1月   1 20:58 arch_HISDB_2101731232_20_1_20250101.bkp
-rw-r----- 1 oracle oinstall     48640 1月   1 20:58 arch_HISDB_2101731232_21_1_20250101.bkp
-rw-r----- 1 oracle oinstall   2004992 1月   1 20:58 arch_HISDB_2101731232_22_1_20250101.bkp
-rw-r----- 1 oracle oinstall   1540608 1月   1 20:58 arch_HISDB_2101731232_23_1_20250101.bkp
-rw-r----- 1 oracle oinstall   9797632 1月   1 20:58 control_bak_12.bak
-rw-r----- 1 oracle oinstall 202989568 1月   1 20:58 HISDB_2101731232_13_1_20250101.bkp
-rw-r----- 1 oracle oinstall  76685312 1月   1 20:58 HISDB_2101731232_14_1_20250101.bkp
-rw-r----- 1 oracle oinstall   1359872 1月   1 20:58 HISDB_2101731232_15_1_20250101.bkp
-rw-r----- 1 oracle oinstall   1097728 1月   1 20:58 HISDB_2101731232_16_1_20250101.bkp
-rw-r----- 1 oracle oinstall   1097728 1月   1 20:58 HISDB_2101731232_17_1_20250101.bkp
-rw-r----- 1 oracle oinstall     98304 1月   1 20:58 HISDB_2101731232_18_1_20250101.bkp

(2)恢复控制文件

sql 复制代码
RMAN> restore controlfile from '/home/oracle/bak11/control_bak_12.bak';

Starting restore at 01-JAN-25
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=20 device type=DISK

channel ORA_DISK_1: restoring control file
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
output file name=/usr/local/oradata/hisdbdg/control01.ctl
output file name=/usr/local/oracle/fast_recovery_area/hisdbdg/control02.ctl
Finished restore at 01-JAN-25

(3)启动数据库到 mount

sql 复制代码
SQL> alter database mount;

Database altered.
3、查看控制文件中的数据文件与临时文件信息
sql 复制代码
RMAN>  report schema;

released channel: ORA_DISK_1
Starting implicit crosscheck backup at 01-JAN-25
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=20 device type=DISK
allocated channel: ORA_DISK_2
channel ORA_DISK_2: SID=27 device type=DISK
allocated channel: ORA_DISK_3
channel ORA_DISK_3: SID=28 device type=DISK
allocated channel: ORA_DISK_4
channel ORA_DISK_4: SID=29 device type=DISK
allocated channel: ORA_DISK_5
channel ORA_DISK_5: SID=30 device type=DISK
allocated channel: ORA_DISK_6
channel ORA_DISK_6: SID=31 device type=DISK
Crosschecked 11 objects
Finished implicit crosscheck backup at 01-JAN-25

Starting implicit crosscheck copy at 01-JAN-25
using channel ORA_DISK_1
using channel ORA_DISK_2
using channel ORA_DISK_3
using channel ORA_DISK_4
using channel ORA_DISK_5
using channel ORA_DISK_6
Finished implicit crosscheck copy at 01-JAN-25

searching for all files in the recovery area
cataloging files...
no files cataloged

RMAN-06139: WARNING: control file is not current for REPORT SCHEMA
Report of database schema for database with db_unique_name HISDBDG

List of Permanent Datafiles
===========================
File Size(MB) Tablespace           RB segs Datafile Name
---- -------- -------------------- ------- ------------------------
1    0        SYSTEM               ***     /usr/local/oradata/hisdbdg/system01.dbf
2    0        SYSAUX               ***     /usr/local/oradata/hisdbdg/sysaux01.dbf
3    0        UNDOTBS1             ***     /usr/local/oradata/hisdbdg/undotbs01.dbf
4    0        USERS                ***     /usr/local/oradata/hisdbdg/users01.dbf

List of Temporary Files
=======================
File Size(MB) Tablespace           Maxsize(MB) Tempfile Name
---- -------- -------------------- ----------- --------------------
1    20       TEMP                 32767       /usr/local/oradata/hisdbdg/temp01.dbf
4、开始恢复数据库

(1)核对备份文件

sql 复制代码
RMAN> crosscheck backup;

using channel ORA_DISK_1
using channel ORA_DISK_2
using channel ORA_DISK_3
using channel ORA_DISK_4
using channel ORA_DISK_5
using channel ORA_DISK_6
crosschecked backup piece: found to be 'EXPIRED'
backup piece handle=/home/oracle/bak0101/control_bak_1.bak RECID=1 STAMP=1189281129
crosschecked backup piece: found to be 'EXPIRED'
backup piece handle=/home/oracle/bak0101/HISDB_2101731232_7_1_20250101.bkp RECID=2 STAMP=1189281181
crosschecked backup piece: found to be 'EXPIRED'
backup piece handle=/home/oracle/bak0101/HISDB_2101731232_4_1_20250101.bkp RECID=3 STAMP=1189281180
crosschecked backup piece: found to be 'EXPIRED'
backup piece handle=/home/oracle/bak0101/HISDB_2101731232_5_1_20250101.bkp RECID=4 STAMP=1189281182
crosschecked backup piece: found to be 'EXPIRED'
backup piece handle=/home/oracle/bak0101/HISDB_2101731232_6_1_20250101.bkp RECID=5 STAMP=1189281181
crosschecked backup piece: found to be 'EXPIRED'
backup piece handle=/home/oracle/bak0101/HISDB_2101731232_3_1_20250101.bkp RECID=6 STAMP=1189281179
crosschecked backup piece: found to be 'EXPIRED'
backup piece handle=/home/oracle/bak0101/HISDB_2101731232_2_1_20250101.bkp RECID=7 STAMP=1189281179
crosschecked backup piece: found to be 'EXPIRED'
backup piece handle=/home/oracle/bak0101/arch_HISDB_2101731232_10_1_20250101.bkp RECID=8 STAMP=1189281348
crosschecked backup piece: found to be 'EXPIRED'
backup piece handle=/home/oracle/bak0101/arch_HISDB_2101731232_11_1_20250101.bkp RECID=9 STAMP=1189281349
crosschecked backup piece: found to be 'EXPIRED'
backup piece handle=/home/oracle/bak0101/arch_HISDB_2101731232_9_1_20250101.bkp RECID=10 STAMP=1189281348
crosschecked backup piece: found to be 'EXPIRED'
backup piece handle=/home/oracle/bak0101/arch_HISDB_2101731232_8_1_20250101.bkp RECID=11 STAMP=1189281348
Crosschecked 11 objects

(2)删除失效的备份文件

sql 复制代码
RMAN> delete expired backup;

using channel ORA_DISK_1
using channel ORA_DISK_2
using channel ORA_DISK_3
using channel ORA_DISK_4
using channel ORA_DISK_5
using channel ORA_DISK_6

List of Backup Pieces
BP Key  BS Key  Pc# Cp# Status      Device Type Piece Name
------- ------- --- --- ----------- ----------- ----------
1       1       1   1   EXPIRED     DISK        /home/oracle/bak0101/control_bak_1.bak
2       2       1   1   EXPIRED     DISK        /home/oracle/bak0101/HISDB_2101731232_7_1_20250101.bkp
3       3       1   1   EXPIRED     DISK        /home/oracle/bak0101/HISDB_2101731232_4_1_20250101.bkp
4       4       1   1   EXPIRED     DISK        /home/oracle/bak0101/HISDB_2101731232_5_1_20250101.bkp
5       5       1   1   EXPIRED     DISK        /home/oracle/bak0101/HISDB_2101731232_6_1_20250101.bkp
6       6       1   1   EXPIRED     DISK        /home/oracle/bak0101/HISDB_2101731232_3_1_20250101.bkp
7       7       1   1   EXPIRED     DISK        /home/oracle/bak0101/HISDB_2101731232_2_1_20250101.bkp
8       8       1   1   EXPIRED     DISK        /home/oracle/bak0101/arch_HISDB_2101731232_10_1_20250101.bkp
9       9       1   1   EXPIRED     DISK        /home/oracle/bak0101/arch_HISDB_2101731232_11_1_20250101.bkp
10      10      1   1   EXPIRED     DISK        /home/oracle/bak0101/arch_HISDB_2101731232_9_1_20250101.bkp
11      11      1   1   EXPIRED     DISK        /home/oracle/bak0101/arch_HISDB_2101731232_8_1_20250101.bkp

Do you really want to delete the above objects (enter YES or NO)? yes
deleted backup piece
backup piece handle=/home/oracle/bak0101/control_bak_1.bak RECID=1 STAMP=1189281129
deleted backup piece
backup piece handle=/home/oracle/bak0101/HISDB_2101731232_7_1_20250101.bkp RECID=2 STAMP=1189281181
deleted backup piece
backup piece handle=/home/oracle/bak0101/HISDB_2101731232_4_1_20250101.bkp RECID=3 STAMP=1189281180
deleted backup piece
backup piece handle=/home/oracle/bak0101/HISDB_2101731232_5_1_20250101.bkp RECID=4 STAMP=1189281182
deleted backup piece
backup piece handle=/home/oracle/bak0101/HISDB_2101731232_6_1_20250101.bkp RECID=5 STAMP=1189281181
deleted backup piece
backup piece handle=/home/oracle/bak0101/HISDB_2101731232_3_1_20250101.bkp RECID=6 STAMP=1189281179
deleted backup piece
backup piece handle=/home/oracle/bak0101/HISDB_2101731232_2_1_20250101.bkp RECID=7 STAMP=1189281179
deleted backup piece
backup piece handle=/home/oracle/bak0101/arch_HISDB_2101731232_10_1_20250101.bkp RECID=8 STAMP=1189281348
deleted backup piece
backup piece handle=/home/oracle/bak0101/arch_HISDB_2101731232_11_1_20250101.bkp RECID=9 STAMP=1189281349
deleted backup piece
backup piece handle=/home/oracle/bak0101/arch_HISDB_2101731232_9_1_20250101.bkp RECID=10 STAMP=1189281348
deleted backup piece
backup piece handle=/home/oracle/bak0101/arch_HISDB_2101731232_8_1_20250101.bkp RECID=11 STAMP=1189281348
Deleted 11 EXPIRED objects

(3)重新核对备份文件

sql 复制代码
RMAN> crosscheck backup;

using channel ORA_DISK_1
using channel ORA_DISK_2
using channel ORA_DISK_3
using channel ORA_DISK_4
using channel ORA_DISK_5
using channel ORA_DISK_6
specification does not match any backup in the repository

(4)更新备份文件

sql 复制代码
RMAN> catalog start with '/home/oracle/bak11';

searching for all files that match the pattern /home/oracle/bak11

List of Files Unknown to the Database
=====================================
File Name: /home/oracle/bak11/arch_HISDB_2101731232_19_1_20250101.bkp
File Name: /home/oracle/bak11/arch_HISDB_2101731232_20_1_20250101.bkp
File Name: /home/oracle/bak11/arch_HISDB_2101731232_21_1_20250101.bkp
File Name: /home/oracle/bak11/arch_HISDB_2101731232_22_1_20250101.bkp
File Name: /home/oracle/bak11/arch_HISDB_2101731232_23_1_20250101.bkp
File Name: /home/oracle/bak11/control_bak_12.bak
File Name: /home/oracle/bak11/HISDB_2101731232_13_1_20250101.bkp
File Name: /home/oracle/bak11/HISDB_2101731232_14_1_20250101.bkp
File Name: /home/oracle/bak11/HISDB_2101731232_15_1_20250101.bkp
File Name: /home/oracle/bak11/HISDB_2101731232_16_1_20250101.bkp
File Name: /home/oracle/bak11/HISDB_2101731232_17_1_20250101.bkp
File Name: /home/oracle/bak11/HISDB_2101731232_18_1_20250101.bkp

Do you really want to catalog the above files (enter YES or NO)? yes
cataloging files...
cataloging done

List of Cataloged Files
=======================
File Name: /home/oracle/bak11/arch_HISDB_2101731232_19_1_20250101.bkp
File Name: /home/oracle/bak11/arch_HISDB_2101731232_20_1_20250101.bkp
File Name: /home/oracle/bak11/arch_HISDB_2101731232_21_1_20250101.bkp
File Name: /home/oracle/bak11/arch_HISDB_2101731232_22_1_20250101.bkp
File Name: /home/oracle/bak11/arch_HISDB_2101731232_23_1_20250101.bkp
File Name: /home/oracle/bak11/control_bak_12.bak
File Name: /home/oracle/bak11/HISDB_2101731232_13_1_20250101.bkp
File Name: /home/oracle/bak11/HISDB_2101731232_14_1_20250101.bkp
File Name: /home/oracle/bak11/HISDB_2101731232_15_1_20250101.bkp
File Name: /home/oracle/bak11/HISDB_2101731232_16_1_20250101.bkp
File Name: /home/oracle/bak11/HISDB_2101731232_17_1_20250101.bkp
File Name: /home/oracle/bak11/HISDB_2101731232_18_1_20250101.bkp

(5)查看备份集信息

sql 复制代码
RMAN> list backup of database;


List of Backup Sets
===================


BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
6       Full    193.57M    DISK        00:00:00     01-JAN-25      
        BP Key: 6   Status: AVAILABLE  Compressed: YES  Tag: TAG20250101T195259
        Piece Name: /home/oracle/bak11/HISDB_2101731232_2_1_20250101.bkp
  List of Datafiles in backup set 6
  File LV Type Ckp SCN    Ckp Time  Name
  ---- -- ---- ---------- --------- ----
  1       Full 1063667    01-JAN-25 /usr/local/oradata/hisdb/system01.dbf

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
7       Full    72.98M     DISK        00:00:00     01-JAN-25      
        BP Key: 7   Status: AVAILABLE  Compressed: YES  Tag: TAG20250101T195259
        Piece Name: /home/oracle/bak11/HISDB_2101731232_3_1_20250101.bkp
  List of Datafiles in backup set 7
  File LV Type Ckp SCN    Ckp Time  Name
  ---- -- ---- ---------- --------- ----
  2       Full 1063668    01-JAN-25 /usr/local/oradata/hisdb/sysaux01.dbf

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
8       Full    1.20M      DISK        00:00:00     01-JAN-25      
        BP Key: 8   Status: AVAILABLE  Compressed: YES  Tag: TAG20250101T195259
        Piece Name: /home/oracle/bak11/HISDB_2101731232_4_1_20250101.bkp
  List of Datafiles in backup set 8
  File LV Type Ckp SCN    Ckp Time  Name
  ---- -- ---- ---------- --------- ----
  3       Full 1063669    01-JAN-25 /usr/local/oradata/hisdb/undotbs01.dbf

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
10      Full    1.04M      DISK        00:00:00     01-JAN-25      
        BP Key: 10   Status: AVAILABLE  Compressed: YES  Tag: TAG20250101T195259
        Piece Name: /home/oracle/bak11/HISDB_2101731232_6_1_20250101.bkp
  List of Datafiles in backup set 10
  File LV Type Ckp SCN    Ckp Time  Name
  ---- -- ---- ---------- --------- ----
  4       Full 1063671    01-JAN-25 /usr/local/oradata/hisdb/users01.dbf

(6)恢复数据库

sql 复制代码
/*
run{
set newname for datafile  1  to  '/usr/local/oradata/hisdbdg/system01.dbf';
set newname for datafile  2  to  '/usr/local/oradata/hisdbdg/sysaux01.dbf';
set newname for datafile  4  to  '/usr/local/oradata/hisdbdg/undotbs01.dbf';
set newname for datafile  3  to  '/usr/local/oradata/hisdbdg/users01.dbf';
set newname for tempfile  1  to  '/usr/local/oracle/data/oradata/temp01';
restore database;
switch datafile all;
switch tempfile all;
recover database;
}
*/

RMAN> 

run{
set newname for datafile  1  to  '/usr/local/oradata/hisdbdg/system01.dbf';
set newname for datafile  2  to  '/usr/local/oradata/hisdbdg/sysaux01.dbf';
set newname for datafile  4  to  '/usr/local/oradata/hisdbdg/undotbs01.dbf';
set newname for datafile  3  to  '/usr/local/oradata/hisdbdg/users01.dbf';
set newname for tempfile  1  to  '/usr/local/oracle/data/oradata/temp01';
restore database;
switch datafile all;
switch tempfile all;
recover database;
11> }

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

Starting restore at 01-JAN-25
using channel ORA_DISK_1
using channel ORA_DISK_2
using channel ORA_DISK_3
using channel ORA_DISK_4
using channel ORA_DISK_5
using channel ORA_DISK_6

channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00001 to /usr/local/oradata/hisdbdg/system01.dbf
channel ORA_DISK_1: reading from backup piece /home/oracle/bak11/HISDB_2101731232_13_1_20250101.bkp
channel ORA_DISK_2: starting datafile backup set restore
channel ORA_DISK_2: specifying datafile(s) to restore from backup set
channel ORA_DISK_2: restoring datafile 00002 to /usr/local/oradata/hisdbdg/sysaux01.dbf
channel ORA_DISK_2: reading from backup piece /home/oracle/bak11/HISDB_2101731232_14_1_20250101.bkp
channel ORA_DISK_3: starting datafile backup set restore
channel ORA_DISK_3: specifying datafile(s) to restore from backup set
channel ORA_DISK_3: restoring datafile 00003 to /usr/local/oradata/hisdbdg/users01.dbf
channel ORA_DISK_3: reading from backup piece /home/oracle/bak11/HISDB_2101731232_15_1_20250101.bkp
channel ORA_DISK_4: starting datafile backup set restore
channel ORA_DISK_4: specifying datafile(s) to restore from backup set
channel ORA_DISK_4: restoring datafile 00004 to /usr/local/oradata/hisdbdg/undotbs01.dbf
channel ORA_DISK_4: reading from backup piece /home/oracle/bak11/HISDB_2101731232_17_1_20250101.bkp
channel ORA_DISK_4: piece handle=/home/oracle/bak11/HISDB_2101731232_17_1_20250101.bkp tag=TAG20250101T205640
channel ORA_DISK_4: restored backup piece 1
channel ORA_DISK_4: restore complete, elapsed time: 00:00:01
channel ORA_DISK_3: piece handle=/home/oracle/bak11/HISDB_2101731232_15_1_20250101.bkp tag=TAG20250101T205640
channel ORA_DISK_3: restored backup piece 1
channel ORA_DISK_3: restore complete, elapsed time: 00:00:07
channel ORA_DISK_1: piece handle=/home/oracle/bak11/HISDB_2101731232_13_1_20250101.bkp tag=TAG20250101T205640
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:25
channel ORA_DISK_2: piece handle=/home/oracle/bak11/HISDB_2101731232_14_1_20250101.bkp tag=TAG20250101T205640
channel ORA_DISK_2: restored backup piece 1
channel ORA_DISK_2: restore complete, elapsed time: 00:00:25
Finished restore at 01-JAN-25

datafile 3 switched to datafile copy
input datafile copy RECID=3 STAMP=1189287623 file name=/usr/local/oradata/hisdbdg/users01.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=4 STAMP=1189287623 file name=/usr/local/oradata/hisdbdg/undotbs01.dbf

renamed tempfile 1 to /usr/local/oracle/data/oradata/temp01 in control file

Starting recover at 01-JAN-25
using channel ORA_DISK_1
using channel ORA_DISK_2
using channel ORA_DISK_3
using channel ORA_DISK_4
using channel ORA_DISK_5
using channel ORA_DISK_6

starting media recovery

channel ORA_DISK_1: starting archived log restore to default destination
channel ORA_DISK_1: restoring archived log
archived log thread=1 sequence=11
channel ORA_DISK_1: reading from backup piece /home/oracle/bak11/arch_HISDB_2101731232_23_1_20250101.bkp
channel ORA_DISK_1: piece handle=/home/oracle/bak11/arch_HISDB_2101731232_23_1_20250101.bkp tag=TAG20250101T205722
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
archived log file name=/usr/local/oracle/fast_recovery_area/HISDBDG/archivelog/2025_01_01/o1_mf_1_11_mqbkg85f_.arc thread=1 sequence=11
channel default: deleting archived log(s)
archived log file name=/usr/local/oracle/fast_recovery_area/HISDBDG/archivelog/2025_01_01/o1_mf_1_11_mqbkg85f_.arc RECID=2 STAMP=1189287624
unable to find archived log
archived log thread=1 sequence=12
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 01/01/2025 21:40:25
RMAN-06054: media recovery requesting unknown archived log for thread 1 with sequence 12 and starting SCN of 1068028

恢复报错,把数据库恢复到 SCN=1068028:

sql 复制代码
RMAN> recover database until scn 1068028;

Starting recover at 01-JAN-25
using channel ORA_DISK_1
using channel ORA_DISK_2
using channel ORA_DISK_3
using channel ORA_DISK_4
using channel ORA_DISK_5
using channel ORA_DISK_6

starting media recovery
media recovery complete, elapsed time: 00:00:00

Finished recover at 01-JAN-25
5、数据库恢复完成,修改日志文件

(1)查看日志文件

sql 复制代码
SQL> select member from v$logfile;

MEMBER
--------------------------------------------------------------------------------
/usr/local/oradata/hisdbdg/redo03.log
/usr/local/oradata/hisdbdg/redo02.log
/usr/local/oradata/hisdbdg/redo01.log
/usr/local/oradata/hisdbdg/standby01.log
/usr/local/oradata/hisdbdg/standby02.log
/usr/local/oradata/hisdbdg/standby03.log
/usr/local/oradata/hisdbdg/standby04.log

7 rows selected.

(2)修改日志文件名(此步骤不用做)

sql 复制代码
/*
alter database rename file '/usr/local/oradata/hisdb/redo01.log' to '/usr/local/oradata/hisdbdg/redo01.log';
alter database rename file '/usr/local/oradata/hisdb/redo02.log' to '/usr/local/oradata/hisdbdg/redo02.log';
alter database rename file '/usr/local/oradata/hisdb/redo03.log' to '/usr/local/oradata/hisdbdg/redo03.log';

alter database rename file '/usr/local/oradata/hisdb/standby01.log' to '/usr/local/oradata/hisdbdg/standby01.log';
alter database rename file '/usr/local/oradata/hisdb/standby02.log' to '/usr/local/oradata/hisdbdg/standby02.log';
alter database rename file '/usr/local/oradata/hisdb/standby03.log' to '/usr/local/oradata/hisdbdg/standby03.log';
alter database rename file '/usr/local/oradata/hisdb/standby04.log' to '/usr/local/oradata/hisdbdg/standby04.log';
*/

SQL> alter database rename file '/usr/local/oradata/hisdb/redo01.log' to '/usr/local/oradata/hisdbdg/redo01.log';

Database altered.

SQL> alter database rename file '/usr/local/oradata/hisdb/redo02.log' to '/usr/local/oradata/hisdbdg/redo02.log';

Database altered.

SQL> alter database rename file '/usr/local/oradata/hisdb/redo03.log' to '/usr/local/oradata/hisdbdg/redo03.log';

Database altered.

SQL> alter database rename file '/usr/local/oradata/hisdb/standby01.log' to '/usr/local/oradata/hisdbdg/standby01.log';

Database altered.

SQL> alter database rename file '/usr/local/oradata/hisdb/standby02.log' to '/usr/local/oradata/hisdbdg/standby02.log';

Database altered.

SQL> alter database rename file '/usr/local/oradata/hisdb/standby03.log' to '/usr/local/oradata/hisdbdg/standby03.log';

Database altered.

SQL> alter database rename file '/usr/local/oradata/hisdb/standby04.log' to '/usr/local/oradata/hisdbdg/standby04.log';

Database altered.
6、启动数据库
sql 复制代码
SQL> alter database open;

Database altered.

四、开启实时同步

1、开启实时同步
sql 复制代码
SQL> alter database recover managed standby database using current logfile disconnect from session;

Database altered.
2、查看备库进程
sql 复制代码
SQL> select process, status, thread#,sequence#, block#, blocks from v$managed_standby;

PROCESS   STATUS	  THREAD#  SEQUENCE#	 BLOCK#     BLOCKS
--------- ------------ ---------- ---------- ---------- ----------
ARCH	  CONNECTED		0	   0	      0 	 0
ARCH	  CONNECTED		0	   0	      0 	 0
ARCH	  CONNECTED		0	   0	      0 	 0
ARCH	  CONNECTED		0	   0	      0 	 0
RFS	  IDLE			1	  38	   8009 	 1
RFS	  IDLE			0	   0	      0 	 0
RFS	  IDLE			0	   0	      0 	 0
RFS	  IDLE			0	   0	      0 	 0
MRP0	  APPLYING_LOG		1	  38	   8009     102400

9 rows selected.
3、查看主库进程信息
sql 复制代码
SQL> select process, status, thread#,sequence#, block#, blocks from v$managed_standby;

PROCESS   STATUS	  THREAD#  SEQUENCE#	 BLOCK#     BLOCKS
--------- ------------ ---------- ---------- ---------- ----------
ARCH	  CLOSING		1	  35	  32769        251
ARCH	  CLOSING		1	  37	  28672        799
ARCH	  CLOSING		1	  37	      1      29470
ARCH	  CLOSING		1	  34	  77825       2456
LNS	  	  WRITING       1	  38	   7895 	 1
4、查看备库信息
sql 复制代码
SQL> select open_mode,log_mode,open_mode ,database_role from v$database;

OPEN_MODE	     LOG_MODE	  OPEN_MODE	       DATABASE_ROLE
-------------------- ------------ -------------------- ----------------
READ ONLY WITH APPLY ARCHIVELOG   READ ONLY WITH APPLY PHYSICAL STANDBY
5、查看主库信息
sql 复制代码
SQL> select open_mode,log_mode,open_mode ,database_role from v$database;

OPEN_MODE	     LOG_MODE	  OPEN_MODE	       DATABASE_ROLE
-------------------- ------------ -------------------- ----------------
READ WRITE	     ARCHIVELOG   READ WRITE	       PRIMARY

五、数据同步验证

1、在主库执行以下 SQL
sql 复制代码
SQL> create table t01(id int primary key, name varchar2(20));

Table created.

insert into t01 values(1,'jack');

1 row created.

SQL> commit;

Commit complete.

SQL> select * from t01;

	ID NAME
---------- --------------------
	 1 jack
2、在备库执行以下 SQL查询数据
sql 复制代码
SQL> select * from t01;

	ID NAME
---------- --------------------
	 1 jack
相关推荐
老大白菜9 分钟前
第5章:索引和性能优化
数据库·mysql·性能优化
华年源码41 分钟前
基于springboot的房屋租赁系统(源码+数据库+文档)
java·数据库·spring boot·后端·毕业设计·源码·springboot
龙少954343 分钟前
【深入理解Mysql】
数据库·mysql
等一场春雨1 小时前
MySQL Binlog 监听方案
数据库·mysql·linq
唐梓航-求职中1 小时前
缓存-Redis-API-Redission-自动续期-watch dog
数据库·redis·缓存
唐梓航-求职中1 小时前
缓存-Redis-API-Redission-可重入锁-原理
数据库·redis·缓存
deadknight92 小时前
空间不足导致Oracle集群内存使用率暴增
数据库·oracle
杰建云1672 小时前
深圳跨境电商建站外贸电商建站哪家好?
数据库·网站建设·notepad++·网站·外贸建站
阿岳3162 小时前
MySQL使用触发器进行备份
android·数据库·mysql
散修-小胖子3 小时前
Centos源码安装MariaDB & 基于GTID主从部署(一遍过)
数据库·mariadb