问题描述:主备两个库不在同一个机房,此时想从这一套库中在复制一套可读可写的新库出来。网络带宽要求比较高,需要从备库中使用备份在起一个新库,也要测试下使用duplicate从备库能够在复制一个新库。经过测试,使用备份和duplicate都可以从备库中恢复新库。
下面使用备份恢复新主库,跟rman恢复库区别不大,主要在恢复的时候指定好控制文件即可。
DG环境介绍一、备库执行备份二、在新主机执行恢复操作 2.1、恢复spfile 2.2、恢复控制文件 2.3、注册备份信息 2.4、还原数据文件 2.5、恢复数据库 2.6、激活备库为主库,并启动数据库
1.环境介绍
利用实时备库orclstd进行新主库orcl_new的恢复,使用rman进行备份恢复
IP |
oracle版本 |
oracle_sid |
db_unique_name |
角色 |
192.168.163.25 |
19.13 |
orcl |
orcl |
主库 |
192.168.163.45 |
19.13 |
orclstd |
orclstd |
备库 |
192.168.163.46 |
19.13 |
orcl_new |
orcl_new |
新主库 |
主库:
SQL> select open_mode,protection_mode,database_role,switchover_status from v$database; OPEN_MODE PROTECTION_MODE DATABASE_ROLE SWITCHOVER_STATUS -------------------- -------------------- ---------------- -------------------- READ WRITE MAXIMUM PERFORMANCE PRIMARY TO STANDBY
备库:
SQL> select open_mode,protection_mode,database_role,switchover_status from v$database; OPEN_MODE PROTECTION_MODE DATABASE_ROLE SWITCHOVER_STATUS -------------------- -------------------- ---------------- -------------------- READ ONLY WITH APPLY MAXIMUM PERFORMANCE PHYSICAL STANDBY NOT ALLOWED SQL> select process, status, thread#,sequence#, block#, blocks from v$managed_standby; PROCESS STATUS THREAD# SEQUENCE# BLOCK# BLOCKS --------- ------------ ---------- ---------- ---------- ---------- ARCH CONNECTED 0 0 0 0 DGRD ALLOCATED 0 0 0 0 DGRD ALLOCATED 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 0 0 0 RFS IDLE 1 41 874 1 RFS IDLE 0 0 0 0 MRP0 APPLYING_LOG 1 41 874 245760
10 rows selected.
2.备库全备
cat > /data/rman_backup_oradgphy_full.sh <<"EOF0" #!/bin/ksh rman target / log /data/backup/backup_oradgphy_full_$MYDATE.log append <<EOF run { sql 'alter session set nls_date_format="yyyy-mm-dd hh24:mi:ss"'; sql 'alter session set NLS_LANGUAGE="AMERICAN"'; allocate channel c1 type disk; allocate channel c2 type disk; backup as compressed backupset database format '/data/backup/FULL_%d_%U.full'; backup as compressed backupset archivelog from time 'sysdate-1' format '/data/backup/ARC_%d_%U.arc'; backup current controlfile format '/data/backup/standby_%U.ctl'; backup spfile format '/data/backup/spfile_%d_%U.ora'; release channel c1; release channel c2; } EOF EOF0
3.恢复数据库
[oracle@19c-test:~]>$rman target / Recovery Manager: Release 19.0.0.0.0 - Production on Sun Nov 13 14:50:02 2022 Version 19.13.0.0.0 Copyright (c) 1982, 2019, Oracle and/or its affiliates. All rights reserved. connected to target database (not started) --启动到nomount RMAN> startup nomount; startup failed: ORA-01078: failure in processing system parameters LRM-00109: could not open parameter file '/u01/app/oracle/product/19.0.0.0/dbhome_1/dbs/initorcl_new.ora' starting Oracle instance without parameter file for retrieval of spfile Oracle instance started Total System Global Area 1073737792 bytes Fixed Size 8904768 bytes Variable Size 276824064 bytes Database Buffers 780140544 bytes Redo Buffers 7868416 bytes
3.1恢复spfile
RMAN> restore spfile to pfile '/u01/app/oracle/product/19.0.0.0/dbhome_1/dbs/initorcl_new.ora' from '/data/backup/spfile_ORCL_1u1cnr92_62_1_1.ora'; Starting restore at 2022-11-13 14:50:31 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 spfile from AUTOBACKUP /data/backup/spfile_ORCL_1u1cnr92_62_1_1.ora channel ORA_DISK_1: SPFILE restore from AUTOBACKUP complete Finished restore at 2022-11-13 14:50:32
3.2编辑pfile
原pfile
[oracle@19c-test:dbs]>$cat initorcl_new.ora orclstd.__data_transfer_cache_size=0 orclstd.__db_cache_size=343932928 orclstd.__inmemory_ext_roarea=0 orclstd.__inmemory_ext_rwarea=0 orclstd.__java_pool_size=79691776 orclstd.__large_pool_size=4194304 orclstd.__oracle_base='/u01/app/oracle'#ORACLE_BASE set from environment orclstd.__pga_aggregate_target=192937984 orclstd.__sga_target=771751936 orclstd.__shared_io_pool_size=37748736 orclstd.__shared_pool_size=289406976 orclstd.__streams_pool_size=0 orclstd.__unified_pga_pool_size=0 *._optimizer_cartesian_enabled=FALSE *.audit_file_dest='/u01/app/oracle/admin/orclstd/adump' *.audit_trail='NONE' *.compatible='19.0.0' *.control_files='/oradata/orclstd/control01.ctl','/oradata/orclstd/control02.ctl' *.db_block_size=8192 *.db_create_file_dest='/oradata' *.db_file_name_convert='/oradata/ORCL/','/oradata/orclstd/' *.db_name='orcl' *.db_recovery_file_dest_size=16106127360 *.db_recovery_file_dest='/home/oracle/flashdata' *.db_unique_name='ORCLSTD' *.deferred_segment_creation=FALSE *.diagnostic_dest='/u01/app/oracle' *.dispatchers='(PROTOCOL=TCP) (SERVICE=orclXDB)' *.event='10949 trace name context forever:28401 trace name context forever,level 1:10849 trace name context forever, level 1:19823 trace name context forever, level 90' *.fal_client='orclstd' *.fal_server='orcl' *.local_listener='LISTENER_ORCL' *.log_archive_config='DG_CONFIG=(orcl,orclstd)' *.log_archive_dest_1='location=/archivelog VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=orcl' *.log_archive_dest_2='SERVICE=orclstd LGWR ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=orclstd' *.log_archive_format='%t_%s_%r.dbf' *.log_file_name_convert='/oradata/ORCL/','/oradata/orclstd/' *.nls_language='AMERICAN' *.nls_territory='AMERICA' *.open_cursors=300 *.pga_aggregate_target=184m *.processes=300 *.remote_login_passwordfile='EXCLUSIVE' *.result_cache_max_size=0 *.sga_target=735m *.standby_file_management='AUTO' *.undo_tablespace='UNDOTBS1'
去除DG相关参数
orcl_new.__data_transfer_cache_size=0 orcl_new.__db_cache_size=343932928 orcl_new.__inmemory_ext_roarea=0 orcl_new.__inmemory_ext_rwarea=0 orcl_new.__java_pool_size=79691776 orcl_new.__large_pool_size=4194304 orcl_new.__oracle_base='/u01/app/oracle'#ORACLE_BASE set from environment orcl_new.__pga_aggregate_target=192937984 orcl_new.__sga_target=771751936 orcl_new.__shared_io_pool_size=37748736 orcl_new.__shared_pool_size=289406976 orcl_new.__streams_pool_size=0 orcl_new.__unified_pga_pool_size=0 *._optimizer_cartesian_enabled=FALSE *.audit_file_dest='/u01/app/oracle/admin/orcl_new/adump' *.audit_trail='NONE' *.compatible='19.0.0' *.control_files='/oradata/orcl_new/control01.ctl','/oradata/orcl_new/control02.ctl' *.db_block_size=8192 *.db_create_file_dest='/oradata' *.db_name='orcl' *.db_recovery_file_dest_size=16106127360 *.db_recovery_file_dest='/home/oracle/flashdata' *.db_unique_name='orcl_new' *.deferred_segment_creation=FALSE *.diagnostic_dest='/u01/app/oracle' *.dispatchers='(PROTOCOL=TCP) (SERVICE=orclXDB)' *.event='10949 trace name context forever:28401 trace name context forever,level 1:10849 trace name context forever, level 1:19823 trace name context forever, level 90' *.log_archive_dest_1='location=/archivelog VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=orcl_new' *.log_archive_format='%t_%s_%r.dbf' *.nls_language='AMERICAN' *.nls_territory='AMERICA' *.open_cursors=300 *.pga_aggregate_target=184m *.processes=300 *.remote_login_passwordfile='EXCLUSIVE' *.result_cache_max_size=0 *.sga_target=735m *.standby_file_management='AUTO' *.undo_tablespace='UNDOTBS1'
3.3创建相关目录
mkdir -p /home/oracle/flashdata mkdir -p /u01/app/oracle/admin/orcl_new/adump mkdir -p /oradata/orcl_new mkdir -p /oradata/ORCL chown -R oracle.oinstall /oradata/
3.4restore控制文件
SQL> create spfile from pfile; File created. SQL> startup force nomount; ORACLE instance started. Total System Global Area 771748528 bytes Fixed Size 8901296 bytes Variable Size 373293056 bytes Database Buffers 381681664 bytes Redo Buffers 7872512 bytes --还原控制文件,加上primary关键字 RMAN> restore primary controlfile from '/data/backup/standby_1t1cnr90_61_1_1.ctl'; Starting restore at 2022-11-13 15:19:45 using target database control file instead of recovery catalog allocated channel: ORA_DISK_1 channel ORA_DISK_1: SID=18 device type=DISK channel ORA_DISK_1: restoring control file channel ORA_DISK_1: restore complete, elapsed time: 00:00:01 output file name=/oradata/orcl_new/control01.ctl output file name=/oradata/orcl_new/control02.ctl Finished restore at 2022-11-13 15:19:47
3.5注册备份信息
SQL> alter database mount; Database altered. --清除之前的备份信息 EXECUTE DBMS_BACKUP_RESTORE.RESETCFILESECTION(11); /** CLEAR V$ARCHIVED_LOG */ EXECUTE DBMS_BACKUP_RESTORE.RESETCFILESECTION(12); /** CLEAR V$BACKUP_SET */ EXECUTE DBMS_BACKUP_RESTORE.RESETCFILESECTION(13); /** CLEAR V$BACKUP_PIECE */ SQL> EXECUTE DBMS_BACKUP_RESTORE.RESETCFILESECTION(11); PL/SQL procedure successfully completed. SQL> EXECUTE DBMS_BACKUP_RESTORE.RESETCFILESECTION(12); PL/SQL procedure successfully completed. SQL> EXECUTE DBMS_BACKUP_RESTORE.RESETCFILESECTION(13); PL/SQL procedure successfully completed. --注册备份集 RMAN> catalog start with '/data/backup'; released channel: ORA_DISK_1 Starting implicit crosscheck backup at 2022-11-13 15:22:52 allocated channel: ORA_DISK_1 channel ORA_DISK_1: SID=18 device type=DISK Finished implicit crosscheck backup at 2022-11-13 15:22:52 Starting implicit crosscheck copy at 2022-11-13 15:22:52 using channel ORA_DISK_1 Finished implicit crosscheck copy at 2022-11-13 15:22:52 searching for all files in the recovery area cataloging files... no files cataloged searching for all files that match the pattern /data/backup List of Files Unknown to the Database ===================================== File Name: /data/backup/backup_oradgphy_full_.log File Name: /data/backup/FULL_ORCL_1o1cnr7q_56_1_1.full File Name: /data/backup/FULL_ORCL_1p1cnr7q_57_1_1.full File Name: /data/backup/ARC_ORCL_1q1cnr8t_58_1_1.arc File Name: /data/backup/ARC_ORCL_1r1cnr8t_59_1_1.arc File Name: /data/backup/ARC_ORCL_1s1cnr8u_60_1_1.arc File Name: /data/backup/standby_1t1cnr90_61_1_1.ctl File Name: /data/backup/spfile_ORCL_1u1cnr92_62_1_1.ora Do you really want to catalog the above files (enter YES or NO)? yes cataloging files... cataloging done List of Cataloged Files ======================= File Name: /data/backup/FULL_ORCL_1o1cnr7q_56_1_1.full File Name: /data/backup/FULL_ORCL_1p1cnr7q_57_1_1.full File Name: /data/backup/ARC_ORCL_1q1cnr8t_58_1_1.arc File Name: /data/backup/ARC_ORCL_1r1cnr8t_59_1_1.arc File Name: /data/backup/ARC_ORCL_1s1cnr8u_60_1_1.arc File Name: /data/backup/standby_1t1cnr90_61_1_1.ctl File Name: /data/backup/spfile_ORCL_1u1cnr92_62_1_1.ora List of Files Which Were Not Cataloged ======================================= File Name: /data/backup/backup_oradgphy_full_.log RMAN-07517: Reason: The file header is corrupted
3.6恢复数据文件
cat > /home/oracle/rman_restore_orcl_new.sh <<"EOF0" MYDATE=`date +'%Y%m%d%H%M%S'` export NLS_DATE_FORMAT="yyyy-mm-dd hh24:mi:ss" rman target / log /home/oracle/rman_restore_LHRDB_$MYDATE.log append <<EOF run { sql 'alter session set nls_date_format="yyyy-mm-dd hh24:mi:ss"'; sql 'alter session set NLS_LANGUAGE="AMERICAN"'; allocate channel c1 type disk; allocate channel c2 type disk; SET NEWNAME FOR DATABASE TO '/oradata/orcl_new/%b'; restore database; switch datafile all; release channel c1; release channel c2; } EOF EOF0
4.启动新主库
4.1启动open
[oracle@19c-test:~]>$sqlplus / as sysdba SQL*Plus: Release 19.0.0.0.0 - Production on Sun Nov 13 15:54:57 2022 Version 19.13.0.0.0 Copyright (c) 1982, 2021, Oracle. All rights reserved. Connected to: Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production Version 19.13.0.0.0 SQL> SQL> alter database open resetlogs; Database altered. SQL> select open_mode , database_role, flashback_on from v$database; OPEN_MODE DATABASE_ROLE FLASHBACK_ON -------------------- ---------------- ------------------ READ WRITE PRIMARY NO SQL> select status,instance_name from v$instance; STATUS INSTANCE_NAME ------------ ---------------- OPEN orcl_new
4.2配置监听
4.3配置tnsname
标签:主库,.__,备库,data,orcl,19.13,orclstd,new,backup From: https://www.cnblogs.com/houzhiheng/p/16977966.html