ALTER DATABASE FORCE LOGGING;
ALTER DATABASE SET STANDBY NOLOGGING FOR DATA AVAILABILITY;
ALTER DATABASE SET STANDBY NOLOGGING FOR LOAD PERFORMANCE;
ps:主库为asm单实例
[grid@ora2 admin]$ cat listener.ora
#Backup file is /u01/app/grid/crsdata/ora2/output/listener.ora.bak.ora2.grid line added by Agent
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = orcl)
(ORACLE_HOME = /u01/app/oracle/product/19.0.0/db_1)
(SID_NAME = orcl)
)
)
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = IPC)(KEY = LISTENER))
)
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.56.121)(PORT = 1521))
)
)
ENABLE_GLOBAL_DYNAMIC_ENDPOINT_LISTENER=ON # line added by Agent
VALID_NODE_CHECKING_REGISTRATION_LISTENER=ON # line added by Agent
[grid@ora2 admin]$
[oracle@ora2 admin]$ cat tnsnames.ora
# Generated by Oracle configuration tools. PDBDGORCL =
STD_ORCL =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.56.120)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcl)
)
)
ORCL =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.56.121)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcl)
)
)
[oracle@ora2 ~]$ cat pfile
*.audit_file_dest='/u01/app/oracle/admin/orcl/adump'
*.audit_trail='db'
*.common_user_prefix=''
*.compatible='19.0.0'
*.control_files='+B/ORCL/CONTROLFILE/current.260.1139638345'
*.db_create_file_dest='+B'
*.db_name='orcl'
*.db_recovery_file_dest_size=5368709120
*.db_recovery_file_dest='/u01/flash'
*.dg_broker_start=TRUE
*.diagnostic_dest='/u01/app/oracle'
*.enable_pluggable_database=true
*.fal_server='STD_ORCL'
*.local_listener=''
*.log_archive_config='DG_CONFIG=(orcl,std_orcl)'
*.log_archive_dest_1='location=/home/oracle/arch VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=orc
l'
*.log_archive_dest_2='service=std_orcl async VALID_FOR=(ONLINE_LOGFILE,PRIMARY_ROLE) DB_UNIQUE_NAME=st
d_orcl'
*.log_archive_dest_state_1='enable'
*.log_archive_dest_state_2='enable'
*.log_file_name_convert='/u01/app/oracle/oradata/','+B/ORCL/ONLINELOG/'
*.db_file_name_convert='/u01/app/oracle/oradata','+B'
*.standby_file_management='AUTO'
*.temp_undo_enabled=TRUE
*.timed_statistics=TRUE
2.1备库监听
[oracle@ora1 admin]$ cat listener.ora
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = orcl)
(ORACLE_HOME = /u01/app/oracle/product/19.0.0/db_1)
(SID_NAME = orcl)
)
)
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = IPC)(KEY = LISTENER))
)
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.56.120)(PORT = 1521))
)
)
2.2备库tns
从主库复制过来
[oracle@ora1 admin]$ cat tnsnames.ora
STD_ORCL =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.56.120)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcl)
)
)
ORCL =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.56.121)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcl)
)
)
*.control_files='/u01/app/oracle/oradata/control01.ctl'#Restore Controlfile
*.db_block_size=8192
*.db_create_file_dest='/u01/app/oracle/oradata'
*.db_name='orcl'
*.db_recovery_file_dest_size=5368709120
*.db_recovery_file_dest='/u01/flash'
*.db_unique_name='std_orcl'
*.dg_broker_start=TRUE
*.diagnostic_dest='/u01/app/oracle'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=orclXDB)'
*.enable_pluggable_database=true
*.fal_client='STD_ORCL'
*.fal_server='orcl'
*.local_listener=''
*.log_archive_config='DG_CONFIG=(std_orcl,orcl)'
*.log_archive_dest_1='location=/home/oracle/arch valid_for=(all_logfiles,all_roles) db_unique_name=std
_orcl'
*.log_archive_dest_2='service=orcl async VALID_FOR=(ONLINE_LOGFILE,PRIMARY_ROLE) DB_UNIQUE_NAME=orcl'
*.log_file_name_convert='+B/ORCL/ONLINELOG/','/u01/app/oracle/oradata/'
*.db_file_name_convert='+B','/u01/app/oracle/oradata'
*.standby_file_management='AUTO'
*.temp_undo_enabled=TRUE
*.timed_statistics=TRUE
1.DB_NAME
只需注意DataGuard的主备各节点instance使用相同的db_name即可。推荐与service_name一致。我们这里未作重定义
2.DB_UNIQUE_NAME
1)Primary与Standby端数据库的唯一名字,设定后不可再更改。
2)如果主备db_unique_name不一样,需要与LOG_ARCHIVE_CONFIG配合使用
3)db_unique_name并未规定需要与数据库service_name一致,可以自定义任意名称。
3.LOG_ARCHIVE_CONFIG
列出主备库上的DB_UNIQUE_NAME 参数。默认情况下,定义该参数保证数据库能够发送或接收redo log。
4.LOG_ARCHIVE_DEST_1
本地归档路径。Primary与Standby需要定义各自的online redo log的归档地址,以系统实际的存放路径为准。
本例LOG_ARCHIVE_DEST_1='LOCATION=/u01/arch/ VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=bj'
可以这样理解:对于bj(主库)而言,不管它是主库角色还是备库角色(ALL_ROLES),它都会自己完成归档动作,并将它们归档在本地的/u01/arch下。
5.LOG_ARCHIVE_DEST_2
该参数仅当数据库角色为primary时生效,指定primary传输redo log到该参数定义的standby database上。
log_archive_dest_2可以说是dataguard上最重要的参数之一,它定义了redo log的传输方式(sync or async)以及传输目标(即standby apply node),直接决定了dataguard的数据保护级别。
注意:SERVICE值,比如bj,是tnsnames.ora文件里定义的Oracle Net名称。
6.LOG_ARCHIVE_DEST_STATE_n
设置为ENABLE,激活log_archive_dest_n定义的属性。
7.FAL_SERVER and FAL_CLIENT
FAL是Fetch Archive Log的简写,它是dataguard主备之间GAP(间隙)的处理机制。
Primary上不会有GAP,所以fal_server和fal_client也是只在standby上生效的参数,当然为了switch over的需要同样会在primary端进行预设置。
FAL参数定义的数据库名同样取自本地tnsnames.ora里配置的Oracle Net Service Name.
11g以后 FAL_CLIENT可以忽略。
本例FAL_SERVER=tj的意思可以理解为:tj(备库)产生的归档日志间隙,要从主库(bj)那里获得。(fal_server=primary database db_unique_name)
8.DB_FILE_NAME_CONVERT
primary与standby上diskgroup的名称或是数据文件的存放路径不一致的时候,需要定义该参数进行转换,否则standby apply后无法创建与primary一致的数据文件并报错。
1)primary上的该参数仅在主备switch over后生效
2)注意格式应保持一致,比如"*.db_file_name_convert='+DG1/db/datafile','+DATAGRP/db/datafile/' ”,路径少了一个"/”,将导致standby apply失败。
本例 DB_FILE_NAME_CONVERT='/u01/oradata/prodstd','/u01/oradata/prod' 使用的是物理文件路径,所以可以省略”/”
3)primary上执行create tablespace等add datafile操作时,无须自定义datafile的全路径名称,由数据库自动创建datafile即可。
9.LOG_FILE_NAME_CONVERT
同DB_FILE_NAME_CONVERT类似,定义主备log文件的存放路径转换。
10)STANDBY_FILE_MANAGEMENT
设置为auto时,主库执行增删数据文件的动作,在备库也会增删数据文件,缺省是manual 需要在备库做手动增删。
1.查看redo log大小
SQL> select bytes/1024/1024 M from v$log;
M
----------
200
200
200
2.standby log要和 redolog 大小一致,否则后面mrp0进程状态一致waitapply状态
alter database add standby logfile group 4 '/u01/app/oracle/oradata/std1.log' size 200m;
alter database add standby logfile group 5 '/u01/app/oracle/oradata/std2.log' size 200m;
alter database add standby logfile group 6 '/u01/app/oracle/oradata/std3.log' size 200m;
alter database add standby logfile group 7 '/u01/app/oracle/oradata/std4.log' size 200m;
3.若添加失败,删除重新添加
ALTER DATABASE DROP STANDBY LOGFILE GROUP 4;
ALTER DATABASE DROP STANDBY LOGFILE GROUP 5;
ALTER DATABASE DROP STANDBY LOGFILE GROUP 6;
ALTER DATABASE DROP STANDBY LOGFILE GROUP 7;
4.若添加standby log成功,查询 standby log大小及状态
SELECT v$logfile.member,
v$logfile.group#,
v$standby_log.status,
v$standby_log.ARCHIVED,
v$standby_log.bytes / 1024 / 1024 M,
v$standby_log.thread#
FROM v$standby_log, v$logfile
WHERE v$standby_log.group# = v$logfile.group#
ORDER BY v$standby_log.thread#, v$logfile.group#;
[oracle@ora1 ~]$ rman target sys/oracle@orcl auxiliary sys/oracle@std_orcl
Recovery Manager: Release 19.0.0.0.0 - Production on Sat Jul 22 15:40:30 2023
Version 19.3.0.0.0
Copyright (c) 1982, 2019, Oracle and/or its affiliates. All rights reserved.
connected to target database: ORCL (DBID=1667419081)
connected to auxiliary database: ORCL (started)
RMAN> duplicate target database for standby from active database;
1.复制完成备库处于mount状态 ,可启动至open
2,启动mrp0进程
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE DISCONNECT FROM SESSION;
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE cancel;
SQL> select process,status from v$managed_standby;
PROCESS STATUS
--------- ------------
DGRD ALLOCATED
ARCH CLOSING
DGRD ALLOCATED
ARCH CLOSING
ARCH CLOSING
ARCH CLOSING
MRP0 APPLYING_LOG
RFS IDLE
RFS IDLE
RFS IDLE
RFS IDLE
SQL> SELECT ROLE, THREAD#, SEQUENCE#, ACTION FROM V$DATAGUARD_PROCESS;
ROLE THREAD# SEQUENCE# ACTION
------------------------ ---------- ---------- ------------
log writer 0 0 IDLE
redo transport monitor 0 0 IDLE
gap manager 0 0 IDLE
redo transport timer 0 0 IDLE
archive local 0 0 IDLE
archive redo 0 0 IDLE
archive redo 0 0 IDLE
archive redo 0 0 IDLE
broker instance slave 0 0 IDLE
broker monitor 0 0 IDLE
managed recovery 0 0 IDLE
recovery logmerger 1 192 APPLYING_LOG
recovery apply slave 0 0 IDLE
recovery apply slave 0 0 IDLE
RFS archive 0 0 IDLE
RFS async 1 192 IDLE
RFS ping 1 192 IDLE
RFS archive 0 0 IDLE
RFS archive 0 0 IDLE
19 rows selected.
create pluggable database pdbprod3 admin user pdbadmin identified by oracle;
如状态异常,可直接用以下 命令在sqlplus中修改配置
alter system set LOG_ARCHIVE_CONFIG='DG_CONFIG=(std_orcl,orcl)';
alter system set log_archive_dest_2='service=orcl async VALID_FOR=(ONLINE_LOGFILE,PRIMARY_ROLE) DB_UNIQUE_NAME=orcl';
select * from v$archive_gap;
select * from gv$archive_gap;
--查看备库归档应用情况:
set linesize 600 pagesize 100
select thread#,max(sequence#) from v$log_history group by thread#;
---备库上查看同步过来的归档日志的应用情况:
col name for a80
select name,SEQUENCE#,APPLIED from v$archived_log order by sequence#;