1.确认数据库开启归档,如未开启归档,请开启归档
archive log list;
SYS@orcl>startup mount;
SYS@orcl>alter database archivelog;
SYS@orcl>alter database open;
打开数据强制日志
alter database force logging;
查询实例的归档模式和附加日志
SYS@orcl>select log_mode,force_logging from v$database;
开启附加日志模式
alter database set standby nologging for data availability; --高可用模式
alter database set standby nologging for load performance; --性能模式
查询redo日志数量
SYS@orcl>select group#,status,type,member from v$logfile;
查询redo日志容量
SYS@orcl>select group# ,sequence#, bytes/104448,status from v$log;
alter system set log_archive_config='dg_config=(orcl,orcldg_1)' scope=both;
2.设置归档日志的本地目录及远程目录,async表示采用异步
alter system set log_archive_dest_1='location=USE_DB_RECOVERY_FILE_DEST lgwr valid_for=(all_logfiles,all_roles) db_unique_name=orcl' scope=both;
alter system set log_archive_dest_2='service=orcldg_1 lgwr async valid_for=(online_logfiles,primary_role) db_unique_name=orcldg_1' scope=both;
alter system set standby_file_management=auto scope=both;
alter system set fal_server='orcldg_1' scope=spfile;
alter system set fal_client='orcl' scope=spfile;
alter database add standby logfile group 5 ('/u01/app/oracle/oradata/ORCL/standbyredo05.log') size 200M;
alter database add standby logfile group 6 ('/u01/app/oracle/oradata/ORCL/standbyredo06.log') size 200M;
alter database add standby logfile group 7 ('/u01/app/oracle/oradata/ORCL/standbyredo07.log') size 200M;
alter database add standby logfile group 8 ('/u01/app/oracle/oradata/ORCL/standbyredo08.log') size 200M;
alter database add standby logfile group 9 ('/u01/app/oracle/oradata/ORCL/standbyredo09.log') size 200M;
3.创建备库文件目录
mkdir -p /u01/app/oracle/admin/orcldg_1/adump/
mkdir -p /u01/app/oracle/admin/orcldg_1/dpdump/
mkdir -p /u01/app/oracle/db_recovery_file/ORCLDG_1/
mkdir -p /u01/app/oracle/oradata/ORCLDG_1/pdbseed
mkdir -p /u01/app/oracle/oradata/ORCLDG_1/pdb1
mkdir -p /u01/app/oracle/oradata/ORCLDG_1/pdb2
注:创不创建都可以,保险起见还是自行创建目录,adummp跟踪目录一定要创建
4.主库添加静态监听及tnsnames.ora添加
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC=
(GLOBAL_DBNAME=mislake)
(ORACLE_HOME=/u01/app/oracle/product/19.3.0/db_1)
(SID_NAME=orcl)
)
)
orcl =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.51)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcl)
)
)
orcldg_1 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.52)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcldg)
)
)
5.备库添加静态监听及tnsnames.ora添加
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC=
(GLOBAL_DBNAME=orcldg)
(ORACLE_HOME=/u01/app/oracle/product/19.3.0/db_1)
(SID_NAME=orcldg)
)
)
orcl =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.51)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcl)
)
)
orcldg_1 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.52)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcldg)
)
)
6.主库创建pfile文件,并将pfile文件及密码文件拷贝至备库
scp orapworcl [email protected]:/u01/app/oracle/product/19.3.0/dbhome_1/dbs/orapworcldg_1
create pfile='/home/oracle/initorcl1.ora' from spfile
scp /home/oracle/initorcl1.ora [email protected]:/home/oracle
7.修改备库pfile文件
--添加
*.db_unique_name='orcldg_1'
*.log_file_name_convert='/u01/app/oracle/oradata/ORCL/','/u01/app/oracle/oradata/ORCLDG_1/'
*.db_file_name_convert='/u01/app/oracle/oradata/ORCL/','/u01/app/oracle/oradata/ORCLDG_1/'
*.standby_file_management='auto'
--修改
*.log_archive_dest_1='location=/data/orcl_arch lgwr valid_for=(all_logfiles,all_roles) db_unique_name=orcldg_1' scope=both;
*.log_archive_dest_2='service=orcl lgwr async valid_for=(online_logfiles,primary_role) db_unique_name=orcl' scope=both;
*.fal_client='orcldg_1'
*.fal_server='orcl'
8.备库创建spfile
create spfile from pfile='/u01/app/oracle/product/19.3.0/dbhome_1/dbs/initorcl.ora';
startup nomount
如果启动失败则用下面方法
startup nomount pfile='/u01/app/oracle/product/19.3.0/dbhome_1/dbs/initorcl.ora';
9.启动备库至nomount
SQL> startup nomount
10.用rman duplicate主库
rman target sys/oracle@orcl auxiliary sys/oracle@orcldg_2
run {
allocate channel c1 type disk rate 200M;
allocate channel c2 type disk rate 200M;
allocate channel c3 type disk rate 200M;
allocate auxiliary channel st1 type disk rate 200M;
allocate auxiliary channel st2 type disk rate 200M;
allocate auxiliary channel st3 type disk rate 200M;
duplicate target database for standby from active database nofilenamecheck dorecover;
release channel c1;
release channel c2;
release channel c3;
release channel st1;
release channel st2;
release channel st3;
}
11.open数据库,并开启同步
SQL> select open_mode from v$database;
OPEN_MODE
------------------------------------------------------------
MOUNTED
SQL> alter database open;
Database altered.
SQL> select log_mode,open_mode ,database_role from v$database;
LOG_MODE OPEN_MODE DATABASE_ROLE
--------------- --------------- --------------------
ARCHIVELOG READ ONLY PHYSICAL STANDBY
SQL>alter database recover managed standby database using current logfile disconnect from session;
11.测试
查看各节点实例名
select instance_name from v$instance;
建表自己测试数据同步