一、环境说明
源库 | 目标库 | |
IP | 192.168.37.201 | 192.168.37.202 |
系统版本 | RedHat 7.9 | RedHat 7.9 |
数据库版本 | 19.3.0.0.0 | 19.3.0.0.0 |
SID | pri | std |
hostname | primary | standby |
数据量 | 整个库 |
说明:源库已经创建数据库实例,目标库只有数据库软件。
二、备份
2.1.日志清理(源端)
cd $ORACLE_BASE/diag/rdbms/pri/pri/trace
find ./ -name "*.trc" -ctime +15|xargs rm -f
find ./ -name "*.trm" -ctime +15|xargs rm -f
2.2.监听日志清理(源端)
cd /u01/app/oracle/diag/tnslsnr/primary/listener/alert
find ./ -name "*.xml" -ctime +15 |xargs rm -f
2.3.审计日志文件清理(源端)
cd /u01/app/oracle/admin/pri/adump
find ./ -name "*.aud" -ctime +15 |xargs rm -f
2.4.数据库目录备份(源端)
su – oracle
cd $ORACLE_HOME
cd ..
tar -cvzf db_home.tar.gz db/ #压缩至db同一目录
三、源端配置
3.1.开启归档模式
su – oracle
sas
startup
archive log list
--启动至mount状态
startup mount;
--将归档的位置修改
alter system set log_archive_dest_1='location=/u01/app/archive';
--启用归档
alter database archivelog;
alter database force logging;
alter database open;
3.2.创建standby日志组
--查询redo日志
col MEMBER for a30;
select group#,type,member from v$logfile;
--查询日志容量大小
select group#,bytes/1024/1024 as MB,status from v$log;
--创建日志组
alter database add standby logfile
group 6 ('/u01/app/oracle/oradata/PRI/standby_redo04.log') size 200m reuse,
group 7 ('/u01/app/oracle/oradata/PRI/standby_redo05.log') size 200m reuse,
group 8 ('/u01/app/oracle/oradata/PRI/standby_redo06.log') size 200m reuse,
group 9 ('/u01/app/oracle/oradata/PRI/standby_redo07.log') size 200m reuse;
--查看结果
select group#,status,used from v$standby_log;
3.3.配置文件传输
--创建pfile配置文件
sas
create pfile from spfile
quit
--修改源端配置文件
cd $ORACLE_HOME/dbs/
vi initpri.ora
#原内容清空,插入以下
pri.__data_transfer_cache_size=0
pri.__db_cache_size=2785017856
pri.__inmemory_ext_roarea=0
pri.__inmemory_ext_rwarea=0
pri.__java_pool_size=0
pri.__large_pool_size=33554432
pri.__oracle_base='/u01/app/oracle'#ORACLE_BASE set from environment
pri.__pga_aggregate_target=1577058304
pri.__sga_target=3674210304
pri.__shared_io_pool_size=134217728
pri.__shared_pool_size=704643072
pri.__streams_pool_size=0
pri.__unified_pga_pool_size=0
*.audit_file_dest='/u01/app/oracle/admin/pri/adump'
*.audit_trail='db'
*.compatible='19.0.0'
*.control_files='/u01/app/oracle/oradata/PRI/control01.ctl','/u01/app/oracle/oradata/PRI/control02.ctl'
*.db_block_size=8192
*.db_name='pri'
*.db_unique_name='pri'
*.fal_client='pri'
*.fal_server='std'
*.log_archive_config='dg_config=(pri,std)'
*.log_archive_dest_1='LOCATION=/u01/app/archive valid_for=(all_logfiles,all_roles) db_unique_name=pri'
*.log_archive_dest_2='service=std lgwr async valid_for=(online_logfiles,primary_role) db_unique_name=std'
*.log_archive_format='%t_%s_%r.arc'
*.db_file_name_convert='/u01/app/oracle/oradata/STD/','/u01/app/oracle/oradata/PRI/'
*.log_file_name_convert='/u01/app/oracle/oradata/STD/','/u01/app/oracle/oradata/PRI/'
STANDBY_FILE_MANAGEMENT=AUTO
*.diagnostic_dest='/u01/app/oracle'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=priXDB)'
*.log_archive_dest_1='location=/u01/app/archive'
*.nls_language='SIMPLIFIED CHINESE'
*.nls_territory='CHINA'
*.open_cursors=300
*.pga_aggregate_target=1500m
*.processes=1500
*.remote_login_passwordfile='EXCLUSIVE'
*.sga_target=3500m
*.undo_tablespace='UNDOTBS1'
--启用新的配置文件
shutdown immediate;
create spfile from pfile;
startup;
--将配置文件传输至目标端
cd $ORACLE_HOME/dbs/
cp orapwpri /soft/orapwstd
cp initpri.ora /soft/initstd.ora
cd /soft
scp orapwstd oracle@standby:/soft
scp initstd.ora oracle@standby:/soft
--去目标端查看
3.4.配置监听(源端&目标端)
--源端配置
cd /u01/app/oracle/product/19.3.0/db/network/admin
vi tnsnames.ora
#将以下添加进去
PRI =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = primary)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = pri)
)
)
LISTENER_ORACLE =
(ADDRESS = (PROTOCOL = TCP)(HOST = primary)(PORT = 1521))
STD =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = standby)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = std)
)
)
--配置listener.ora
vi listener.ora
#将以下添加进去
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = primary)(PORT = 1521))
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
)
)
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = pri)
(ORACLE_HOME = /u01/app/oracle/product/19.3.0/db)
(SID_NAME = pri)
)
)
--监听重载
lsnrctl start
lsnrctl reload
--目标端配置
cd /u01/app/oracle/product/19.3.0/db/network/admin
vi tnsnames.ora
#将以下添加进去
PRI =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = primary)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = pri)
)
)
LISTENER_ORACLE =
(ADDRESS = (PROTOCOL = TCP)(HOST = primary)(PORT = 1521))
STD =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = standby)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = std)
)
)
--配置listener.ora
vi listener.ora
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = standby)(PORT = 1521))
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
)
)
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = std)
(ORACLE_HOME = /u01/app/oracle/product/19.3.0/db)
(SID_NAME = std)
)
)
--监听重载
lsnrctl start
lsnrctl reload
--分别在源、目标端测试
tnsping primary
tnsping standby
四、配置目标端
4.1.修改配置文件
cd /soft
vi initstd.ora
#清空内容,将以下内容插入
pri.__data_transfer_cache_size=0
pri.__db_cache_size=2785017856
pri.__inmemory_ext_roarea=0
pri.__inmemory_ext_rwarea=0
pri.__java_pool_size=0
pri.__large_pool_size=33554432
pri.__oracle_base='/u01/app/oracle'#ORACLE_BASE set from environment
pri.__pga_aggregate_target=1577058304
pri.__sga_target=3674210304
pri.__shared_io_pool_size=134217728
pri.__shared_pool_size=704643072
pri.__streams_pool_size=0
pri.__unified_pga_pool_size=0
*.audit_file_dest='/u01/app/oracle/admin/std/adump'
*.audit_trail='db'
*.compatible='19.0.0'
*.control_files='/u01/app/oracle/oradata/STD/control01.ctl','/u01/app/oracle/oradata/STD/control02.ctl'
*.db_block_size=8192
*.db_name='pri'
*.db_unique_name='std'
*.fal_client='std'
*.fal_server='pri'
*.log_archive_config='dg_config=(std,pri)'
*.log_archive_dest_1='LOCATION=/u01/app/archive valid_for=(all_logfiles,all_roles) db_unique_name=std'
*.log_archive_dest_2='service=std lgwr async valid_for=(online_logfiles,primary_role) db_unique_name=pri'
*.log_archive_format='%t_%s_%r.arc'
*.db_file_name_convert='/u01/app/oracle/oradata/PRI/','/u01/app/oracle/oradata/STD/'
*.log_file_name_convert='/u01/app/oracle/oradata/PRI/','/u01/app/oracle/oradata/STD/'
STANDBY_FILE_MANAGEMENT=AUTO
*.diagnostic_dest='/u01/app/oracle'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=priXDB)'
*.log_archive_dest_1='location=/u01/app/archive'
*.nls_language='SIMPLIFIED CHINESE'
*.nls_territory='CHINA'
*.open_cursors=300
*.pga_aggregate_target=1500m
*.processes=1500
*.remote_login_passwordfile='EXCLUSIVE'
*.sga_target=3500m
*.undo_tablespace='UNDOTBS1'
--创建相关文件目录
因为备库只有软件,没有实例,所以我们需要手动创建相关目录
mkdir -p /u01/app/oracle/admin/std/adump
mkdir -p /u01/app/oracle/oradata/STD
4.2.启动目标端
sas
create spfile from pfile;
startup nomount;
alter system set standby_file_management=MANUAL;
五、构建
5.1.源端登录rman
--登录rman
rman target sys/oracle@pri auxiliary sys/oracle@std
--执行
run {
allocate channel ch001 type disk;
allocate channel ch002 type disk;
allocate channel ch003 type disk;
allocate channel ch004 type disk;
allocate auxiliary channel ch005 type disk;
allocate auxiliary channel ch006 type disk;
duplicate target database for standby from active database nofilenamecheck using compressed backupset;
release channel ch001;
release channel ch002;
release channel ch003;
release channel ch004;
release channel ch005;
release channel ch006;
}
--查看目标端状态
select open_mode from v$database;
--open
alter database open;
--查看相关文件
col MEMBER for a40;
select group#,type,member from v$logfile order by 2,1;
--开启日志应用
alter database recover managed standby database using current logfile disconnect;
--验证
select process,status from v$managed_standby;
六、主备交换
6.1.查看源端状态
select database_role, switchover_status from v$database;
--如果是to standby:
alter database commit to switchover to physical standby;
--其他:
alter database commit to switchover to physical standby with session shutdown;
6.2.重启源端
startup nomount;
alter database mount standby database;
alter database open read only;
alter database recover managed standby database using current logfile disconnect;
6.3.查看目标端状态
select database_role, switchover_status from v$database;
--如果是to primary:
ALTER DATABASE COMMIT TO SWITCHOVER TO PRIMARY;
--其他
ALTER DATABASE COMMIT TO SWITCHOVER TO PRIMARY;
Alter database open;
select name,DATABASE_ROLE from v$database;