使用RMAN方式建立ORACLE DATAGUARD

1.      备用库数据软件安装相关目录的准备

(adump、bdump、cdump、udump;、/oradata;/arch、/arch/standby等)

2.      备份数据库standby controlfile

rman target / (主机上)

backup full database format=‘/oradata/standby/fulldatabase_%U.dbf‘ include current controlfile for standby;

把备份的数据全部拷贝到备机的相同目录


3.      打开主数据的归档模式

startup mount;

alter database archivelog;

alter database force logging;

alter database open;

create pfile from spfile;

修改pfile:

*.db_unique_name=’testa’

*.fal_client=’testb’

*.fal_server=’testa’

*.log_archive_dest_1=’location=/arch’

*.log_archive_dest_2=’service=testb mandatory reopen=60’

*.standby_archive_dest=’/arch/standby’

*.standby_file_management=’AUTO’

把修改完成后的pfile传到备机相应目录

并修改为:

*.db_unique_name=’testb’

*.fal_client=’testb’

*.fal_server=’testa’

*.log_archive_dest_1=’location=/arch’

*.log_archive_dest_2=’service=testa mandatory reopen=60’

*.standby_archive_dest=’/arch/standby’

*.standby_file_management=’AUTO’

*.log_archive_dest_state_2=’DEFER’

修改listener.ora及tnsnames.ora

主机listener.ora如下:

SID_LIST_LISTENER =

(SID_LIST =

(SID_DESC =

(SERVICE_NAME=testa)

(ORACLE_HOME = /oracle/product/10.2)

(SID_NAME=test)

(PROGRAM = extproc)

)

)

LISTENER =

(DESCRIPTION_LIST =

(DESCRIPTION =

(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.249.131)(PORT = 1521))

(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC0))

)

)

备机listener.ora如下:

SID_LIST_LISTENER =

(SID_LIST =

(SID_DESC =

(SERVICE_NAME=testb)

(ORACLE_HOME = /oracle/product/10.2)

(SID_NAME=test)

(PROGRAM = extproc)

)

)

LISTENER =

(DESCRIPTION_LIST =

(DESCRIPTION =

(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.249.132)(PORT = 1521))

(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC0))

)

)

主机tnsnames.ora如下:

testb =

(DESCRIPTION =

(ADDRESS_LIST =

(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.249.132)(PORT = 1521))

)

(CONNECT_DATA =

(SERVER=DEDICATED)

(SERVICE_NAME = testb)

(UR=A)

)

)

TESTA =

(DESCRIPTION =

(ADDRESS_LIST =

(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.249.131)(PORT = 1521))

)

(CONNECT_DATA =

(SERVICE_NAME = testa)

)

)

TEST =

(DESCRIPTION =

(ADDRESS_LIST =

(ADDRESS = (PROTOCOL = TCP)(HOST = 127.0.0.1)(PORT = 1521))

)

(CONNECT_DATA =

(SERVICE_NAME = testa)

)

)

EXTPROC_CONNECTION_DATA =

(DESCRIPTION =

(ADDRESS_LIST =

(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC0))

)

(CONNECT_DATA =

(SID = PLSExtProc)

(PRESENTATION = RO)

)

)

备机tnsnames.ora如下:

TESTB =

(DESCRIPTION =

(ADDRESS_LIST =

(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.249.132)(PORT = 1521))

)

(CONNECT_DATA =

(SERVICE_NAME = testb)

)

)

TESTA =

(DESCRIPTION =

(ADDRESS_LIST =

(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.249.131)(PORT = 1521))

)

(CONNECT_DATA =

(SERVICE_NAME = testa)

)

)

EXTPROC_CONNECTION_DATA =

(DESCRIPTION =

(ADDRESS_LIST =

(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC0))

)

(CONNECT_DATA =

(SID = PLSExtProc)

(PRESENTATION = RO)

)

)

4.     建立备份数据库:

拷贝password文件到备机相应目录

备机执行:

startup nomount;

主机登陆rman

>rman target /

rman>connect auxiliary sys/test@testb(登陆standby目标数据库)

rman> duplicate target database for standby database nofilenamecheck;

登陆备机数据库执行:

Sql> alter database  reover managed standby database disconnect from session;

主机切换日志查看数据库同步情况:

Sql>alter system switch logfile;(主机)

Sql>select message from v$dataguard_status;(备机)

如果需要改变数据文件的位置rman脚本如下:

RMAN> run

2> {

3> set newname for datafile ‘/data/system.dbf’ to ‘/data/standby/system.dbf’;

4>……

8>duplicate target database for standby;

9>}

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>