IP | sid | DB_UNIQUE_NAME | |
主库 | 192.168.31.1 | orcl | orcl |
备库 | 192.168.31.2 | orcl | orcldg |
1.主库参数设置
--打开数据强制日志
alter database force logging;
--确认数据库开启归档,如未开启归档,请开启归档
archive log list;
alter system set log_archive_config='dg_config=(orcl,orcldg)' scope=both;
--设置归档日志的本地目录及远程目录,async表示采用异步
alter system set log_archive_dest_1='location=/data/orcl_arch lgwr valid_for=(all_logfiles,all_roles) db_unique_name=orcl' scope=both;
alter system set log_archive_dest_2='service=orcldg lgwr async valid_for=(online_logfiles,primary_role) db_unique_name=orcldg' scope=both;
alter system set standby_file_management=auto scope=both;
alter system set fal_server='orcldg' scope=spfile;
alter system set fal_client='orcl' scope=spfile;
2.主库日志文件添加
standby日志组比redo日志多一组即可
alter database add standby logfile group 5 ('/data/ORCL/standbyredo05.log') size 200M;
alter database add standby logfile group 6 ('/data/ORCL/standbyredo06.log') size 200M;
alter database add standby logfile group 7 ('/data/ORCL/standbyredo07.log') size 200M;
alter database add standby logfile group 8 ('/data/ORCL/standbyredo08.log') size 200M;
alter database add standby logfile group 9 ('/data/ORCL/standbyredo09.log') size 200M;
3.主库添加静态监听及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.31.1)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcl)
)
)
orcldg =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.31.2)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcldg)
)
)
4.备库添加静态监听及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.31.1)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcl)
)
)
orcldg =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.31.2)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcldg)
)
)
5主库创建pfile文件,并将pfile文件及密码文件拷贝至备库
scp orapworcl oracle@192.168.31.2:/u01/app/oracle/product/19.3.0/dbhome_1/dbs/orapworcldg
create pfile='/home/oracle/1.ora' from spfile
scp /home/oracle/1.oracle@192.168.31.2:/home/oracle
6.修改备库pfile文件
--添加
*.db_unique_name='orcldg'
*.log_file_name_convert='/data/ORCL','/data/ORCLDG'
*.db_file_name_convert='/data/ORCL','/data/ORCLEDG'
*.standby_file_management='auto'
--修改
*.log_archive_dest_1='location=/data/orcl_arch lgwr valid_for=(all_logfiles,all_roles) db_unique_name=orcldg' 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'
*.fal_server='orcl'
7.备库创建spfile
create spfile from pfile='/home/orcl/1.ora'
8.启动备库至nomount
SQL> startup nomount
9.用rman duplicate主库
rman target sys/oracle@orcl auxiliary sys/oracle@orcldg
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;
}
10.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.验证是否正常同步,可以在主库新建一个表看看备库是否有