1.hosts 文件设置(主,备1,备2)
vi hosts
192.168.1.51 dghost01.m.cn dghost01
192.168.1.52 dghost02.m.cn dghost02
192.168.1.53 dghost03.m.cn dghost03
2.确认数据库开启归档,如未开启归档,请开启归档
archive log list;
SYS@orcl>startup mount;
SYS@orcl>alter database archivelog;
SYS@orcl>alter database open;
3.打开数据强制日志
alter database force logging;
查询实例的归档模式和附加日志
SYS@orcl>select log_mode,force_logging from v$database;
4.开启附加日志模式
alter database set standby nologging for data availability; --高可用模式
alter database set standby nologging for load performance; --性能模式
5.查询redo日志数量
SYS@orcl>select group#,status,type,member from v$logfile;
6.查询redo日志容量
SYS@orcl>select group# ,sequence#, bytes/104448,status from v$log;
alter system set log_archive_config='dg_config=(orcl,orcldg_1,orcldg_2)' scope=both;
7.主库设置
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 log_archive_dest_3='service=orcldg_2 lgwr async valid_for=(online_logfiles,primary_role) db_unique_name=orcldg_2' scope=both;
alter system set standby_file_management=auto scope=both;
alter system set fal_server='orcldg_1','orcldg_2' 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;
确认standby redo logfile创建成功
SYS@orcl>select group#,status,used from v$standby_log;
8.创建主库pfil文件,并将pfile文件和密码文件复制到备1和备2
scp orapworcl [email protected]:/u01/app/oracle/product/19.3.0/dbhome_1/dbs/orapworcldg_1
scp orapworcl [email protected]:/u01/app/oracle/product/19.3.0/dbhome_1/dbs/orapworcldg_2
create pfile='/home/oracle/initorcl.ora' from spfile
scp /home/oracle/initorcl.ora [email protected]:/home/oracle
scp /home/oracle/initorcl.ora [email protected]:/home/oracle
9.备1修改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;
*.log_archive_dest_3='service=orcl lgwr async valid_for=(online_logfiles,primary_role) db_unique_name=orcldg_2' scope=both;
*.fal_client='orcldg_1'
*.fal_server='orcl','orcldg_2'
10.备2修改pfile文件:
--添加
*.db_unique_name='orcldg_2'
*.log_file_name_convert='/u01/app/oracle/oradata/ORCL/','/u01/app/oracle/oradata/ORCLDG_2/'
*.db_file_name_convert='/u01/app/oracle/oradata/ORCL/','/u01/app/oracle/oradata/ORCLDG_2/'
*.standby_file_management='auto'
--修改
*.log_archive_dest_1='location=/data/orcl_arch lgwr valid_for=(all_logfiles,all_roles) db_unique_name=orcldg_2' scope=both;
*.log_archive_dest_2='service=orcl lgwr async valid_for=(online_logfiles,primary_role) db_unique_name=orcl' scope=both;
*.log_archive_dest_3='service=orcldg_1 lgwr async valid_for=(online_logfiles,primary_role) db_unique_name=orcldg_1' scope=both;
*.fal_client='orcldg_2'
*.fal_server='orcl','orcldg_1'
11.创建备库文件目录
mkdir -p /u01/app/oracle/admin/orcldg_2/adump/
mkdir -p /u01/app/oracle/admin/orcldg_2/dpdump/
mkdir -p /u01/app/oracle/db_recovery_file/ORCLDG_1/
mkdir -p /u01/app/oracle/oradata/ORCLDG_2/pdbseed
mkdir -p /u01/app/oracle/oradata/ORCLDG_2/pdb1
mkdir -p /u01/app/oracle/oradata/ORCLDG_2/pdb2
12.创建监听
主库添加静态监听及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)
)
)
orcldg_2 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.52)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcldg)
)
)
备库添加静态监听及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)
)
)
orcldg_2 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.52)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcldg)
)
)
13.备库创建spfile,用spfile或pfile都可以
SQL>create spfile from pfile='/u01/app/oracle/product/19.3.0/dbhome_1/dbs/initorcl.ora';
SQL>startup nomount
SQL>startup nomount pfile='/u01/app/oracle/product/19.3.0/dbhome_1/dbs/initorcl.ora';
14.启动备库至nomount
SQL> startup nomount
15.用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;
}
16.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;
17.测试
查看各节点实例名
select instance_name from v$instance;
自己建表测试数据同步,这里就不在赘述啦,希望对大家有帮助