本文主要是介绍利用Rman搭建物理standby,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
步骤:
(1)建立对应standby数据库的目录,如$ORACLE_BASE/admin,$ORACL_EBASE/oradata下的对应目录以及相关子目录,归档日志存放目录,闪回区存放路径等;创建密码文件。
mkdir /opt/oracle/admin/standby
cd /opt/oracle/admin/standby
mkdir adump bdump cdump udump dpdump
mkdir /opt/oracle/oradata/standby
mkdir /opt/oracle/oradata/standby/archivelog
orapwd file=$ORACLE_HOME/dbs/orapwstandby password=oracle force=y
(2) 开始主库的备份,备份包括数据文件和控制文件
rman target sys/oracle@ocp
RMAN> backup format '/oracle/bak/backup_%U' database plus archivelog;
RMAN> backup format '/oracle/bak/bk_%U' current controlfile for standby;
(3) 修改主库的参数文件
create pfile from spfile
vim $ORACLE_HOME/dbs/initocp.ora
*.log_archive_config='dg_config=(demo,standby)'
*.fal_server=standby
*.fal_client=demo
*.standby_file_management=AUTO
*.db_unique_name=demo
*.log_archive_dest_1='LOCATION=/opt/oracle/oradata/ocp/archive/'
*.log_archive_dest_2='SERVICE=standby valid_for=(online_logfiles,primary_role) db_unique_name=standby'
*.log_archive_dest_state_1='ENABLE'
*.log_archive_dest_state_2='ENABLE'
(4)关闭主库,创建spfile
shutdown immediate;
create spfile from pfile;
(5)创建备库的参数文件
create pfile='?/dbs/initstandby.ora' from spfile;
改变其中的相关路径,设置如下对应参数:
*.log_archive_dest_1='LOCATION=/opt/oracle/oradata/standby/archive/'
*.log_archive_dest_2='SERVICE=ocp valid_for=(online_logfiles,primary_role) db_unique_name=ocp'
*.log_archive_config='dg_config=(ocp,standby)'
*.fal_server=ocp
*.fal_client=standby
*.standby_file_management=AUTO
*.db_unique_name=standby
*.db_file_name_convert='/opt/oracle/oradata/ocp','/opt/oracle/oradata/standby'
*.log_file_name_convert='/opt/oracle/oradata/ocp','/opt/oracle/oradata/standby'
*.log_archive_dest_state_1='ENABLE'
*.log_archive_dest_state_2='ENABLE'
修改pfile完成后,创建备库对应的spfile:
create spfile='?/dbs/spfilestandby.ora' from pfile='?/dbs/initstandby.ora';
(6) 配置监听,将对应的db_unique_name配置进去
vim $ORACLE_HOME/network/admin/tnsnames.ora
DEMO =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.102)(PORT = 1521))
)
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = demo)
)
)
STANDBY =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.102)(PORT = 1521))
)
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = standby)
)
)
重新启动监听。
(7)如果在不同的机器上实验,则需要scp 主库数据文件和控制文件的备份到备库相同的目录(因为执行步骤9时,会读取主库的控制文件,然后知道备份片的位置,再restore备库的控制文件,如果备库的备份片位置和主库不同,则步骤9会报错)
如果主备库在同一台机器上搭建,则无需做这一步了。
(8) 启动备库
export ORACLE_SID=standby
startup nomount;
(9) 利用rman恢复备库
uniread rman target sys/oracle@demo auxiliary sys/oracle@standby
connected to target database: OCP (DBID=2606671501)
connected to auxiliary database: OCP (not mounted)
RMAN> duplicate target database for standby dorecover; --如果在同一台机器上。
RMAN> duplicate target database for standby nofilenamecheck dorecover; --如果在不同机器上
(10) 执行步骤9以后,备库进入到mount状态,但是此时日志还不能传输过来,需要重启备库。
startup force mount;
这篇关于利用Rman搭建物理standby的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!