oracle DataGuard

手工搭建物理dataguard



首先数据库需要设置为归档模式



强制数据库为force logging 模式


SQL>alter database force logging;


为主库添加standby redo log,standby日志文件需要大于或等于联机日志文件


SQL> alter database add standby logfile group 4 '/export/home/oracle/oradata/orcl/std_redo04.log' size 51m;


SQL> alter database add standby logfile group 5 '/export/home/oracle/oradata/orcl/std_redo05.log' size 51m;


SQL> alter database add standby logfile group 6 '/export/home/oracle/oradata/orcl/std_redo06.log' size 51m;


SQL> alter database add standby logfile group 7 '/export/home/oracle/oradata/orcl/std_redo07.log' size 51m;



创建pfile文件


SQL>create pfile='/export/home/oracle/oracle/product/10.2.0.1/dbs/initorcl.ora'





修改pfile文件



[oracle@solaris ~/oracle/product/10.2.0.1/dbs]-->cat initorcl.ora

orcl.__db_cache_size=41943040

orcl.__java_pool_size=4194304

orcl.__large_pool_size=4194304

orcl.__shared_pool_size=54525952

orcl.__streams_pool_size=0

*.audit_file_dest='/export/home/oracle/admin/orcl/adump'

*.background_dump_dest='/export/home/oracle/admin/orcl/bdump'

*.compatible='10.2.0.2.0'

*.control_files='/export/home/oracle/oradata/orcl/control01.ctl','/export/home/oracle/oradata/orcl/control02.ctl','/export/home/ora


cle/oradata/orcl/control03.ctl'

*.core_dump_dest='/export/home/oracle/admin/orcl/cdump'

*.db_block_size=8192

*.db_domain=''

*.db_file_multiblock_read_count=16

*.db_name='orcl'

*.db_recovery_file_dest='/export/home/oracle/flash_recovery_area'

*.db_recovery_file_dest_size=2147483648

*.dispatchers='(PROTOCOL=TCP) (SERVICE=orclXDB)'

*.job_queue_processes=10

*.log_file_name_convert='/export/home/oracle/oradata/std','/export/home/oracle/oradata/orcl'

*.nls_language='SIMPLIFIED CHINESE'

*.open_cursors=300

*.pga_aggregate_target=10777216

*.processes=150

*.remote_login_passwordfile='EXCLUSIVE'

*.sga_target=107772160

*.standby_file_management='auto'

*.undo_tablespace='UNDOTBS1'

*.user_dump_dest='/export/home/oracle/admin/orcl/udump'

----以下内容是新添加的

*.db_unique_name='orcl'

*.db_file_name_convert='/export/home/oracle/oradata/std','/export/home/oracle/oradata/orcl'

*.log_archive_config='dg_config=(orcl,std)'

*.log_archive_dest_1='location=/export/home/oracle/arch/orcl valid_for=(all_logfiles,all_roles) db_unique_name=orcl'

*.LOG_ARCHIVE_DEST_2='SERVICE=std LGWR ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=std'

*.log_archive_dest_state_1='enable'

*.log_archive_dest_state_2='enable'

*.fal_client='orcl'

*.fal_server='std'

*.undo_management='AUTO'

*.standby_archive_dest='/export/home/oracle/arch/orcl'



创建相关的目录

$mkdir -p /export/home/oracle/arch/orcl



修改listener.ora 和tnsname.ora


首先是listener.ora 主备的配置一样

[oracle@solaris ~/oracle/product/10.2.0.1/network/admin]-->cat listener.ora

# listener.ora Network Configuration File: /export/home/oracle/oracle/product/10.2.0.1/network/admin/listener.ora

# Generated by Oracle configuration tools.


SID_LIST_LISTENER =

 (SID_LIST =

   (SID_DESC =

     (SID_NAME = orcl)

     (ORACLE_HOME = /export/home/oracle/oracle/product/10.2.0.1)

    (GLOBAL_DBNAME = orcl)

   )

   (SID_DESC =

     (SID_NAME = std)

     (ORACLE_HOME = /export/home/oracle/oracle/product/10.2.0.1)

    (GLOBAL_DBNAME = std)

   )


 )



LISTENER =

 (DESCRIPTION_LIST =

   (DESCRIPTION =

     (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1))

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

   )

 )


再是tnsname.ora


[oracle@solaris ~/oracle/product/10.2.0.1/network/admin]-->cat tnsnames.ora

# tnsnames.ora Network Configuration File: /export/home/oracle/oracle/product/10.2.0.1/network/admin/tnsnames.ora

# Generated by Oracle configuration tools.


ORCL =

 (DESCRIPTION =

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

   (CONNECT_DATA =

     (SERVER = DEDICATED)

     (SERVICE_NAME = orcl)

   )

 )


std =

 (DESCRIPTION =

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

   (CONNECT_DATA =

     (SERVER = DEDICATED)

     (SERVICE_NAME = std)

   )

 )


因为我主备的实例都运行在本机,所以tnsname.ora 有两个实例的监听


创建密码文件


[oracle@solaris ~/oracle/product/10.2.0.1/dbs]-->orapwd file=orapworcl password=oracle entries=10 force=y

[oracle@solaris ~/oracle/product/10.2.0.1/dbs]-->orapwd file=orapwstd password=oracle entries=10 force=y




将主库的参数文件复制为备库的参数文件,修改相应的值

$cp initorcl.ora initstd.ora


[oracle@solaris ~/oracle/product/10.2.0.1/dbs]-->cat initstd.ora                                        

orcl.__db_cache_size=41943040

orcl.__java_pool_size=4194304

orcl.__large_pool_size=4194304

orcl.__shared_pool_size=54525952

orcl.__streams_pool_size=0

*.audit_file_dest='/export/home/oracle/admin/std/adump'

*.background_dump_dest='/export/home/oracle/admin/std/bdump'

*.compatible='10.2.0.2.0'

*.control_files='/export/home/oracle/oradata/std/control01.ctl'

*.core_dump_dest='/export/home/oracle/admin/std/cdump'

*.db_block_size=8192

*.db_domain=''

*.db_file_multiblock_read_count=16

*.db_file_name_convert='/export/home/oracle/oradata/orcl','/export/home/oracle/oradata/std'

*.db_name='orcl'

*.db_recovery_file_dest='/export/home/oracle/flash_recovery_area'

*.db_recovery_file_dest_size=2147483648

*.db_unique_name='std'

*.dispatchers='(PROTOCOL=TCP) (SERVICE=orclXDB)'

*.fal_client='std'

*.fal_server='orcl'

*.job_queue_processes=10

*.log_archive_config='dg_config=(orcl,std)'

*.log_archive_dest_1='location=/export/home/oracle/arch/std valid_for=(all_logfiles,all_roles) db_unique_name=std'

*.LOG_ARCHIVE_DEST_2='SERVICE=orcl LGWR ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=orcl'

*.log_archive_dest_state_1='enable'

*.log_archive_dest_state_2='enable'

*.log_file_name_convert='/export/home/oracle/oradata/orcl','/export/home/oracle/oradata/std'

*.nls_language='SIMPLIFIED CHINESE'

*.open_cursors=300

*.pga_aggregate_target=10777216

*.processes=150

*.remote_login_passwordfile='EXCLUSIVE'

*.sga_target=107772160

*.standby_archive_dest='/export/home/oracle/arch/std'

*.standby_file_management='auto'

*.undo_management='AUTO'

*.undo_tablespace='UNDOTBS1'

*.user_dump_dest='/export/home/oracle/admin/std/udump'



$mkdir -p /export/home/oracle/arch/std

$mkdir -p /export/home/oracle/admin/std/{a,b,c,u}dump

$mkdir -p /export/home/oracle/oradata/std





创建备库的控制文件


SQL> alter database create standby controlfile as '/export/home/oracle/oradata/std/control01.ctl';

SQL> alter database create standby controlfile as '/export/home/oracle/oradata/std/control02.ctl';

SQL> alter database create standby controlfile as '/export/home/oracle/oradata/std/control03.ctl';


关闭主数据库


SQL> shutdown immedate



将数据文件,日志文件,standby日志文件拷贝到备库中

$cp /export/home/oracle/oradata/orcl/*  /export/home/oracle/oradata/orcl



启动主备数据库


SQL> startup pfile='/export/home/oracle/oracle/product/10.2.0.1/dbs/initorcl.ora';

SQL> create spfile from pfile;



SQL> startup nomout;

SQL> alter database mount standby database;

SQL> alter database recover managed standby database disconnect from session;



查看sequence#


SQL> select sequence# from v$log;


SEQUENCE#

----------

       33

       32

        0

SQL> select sequence# from v$log;


SEQUENCE#

----------

       33

        0

        0





主备之间的切换


主切换到备

SQL>  ALTER DATABASE COMMIT TO SWITCHOVER TO PHYSICAL STANDBY WITH SESSION SHUTDOWN ;

SQL> shutdown immedate

SQL> startup mount

SQL> select database_role,switchover_status from v$database;


DATABASE_ROLE    SWITCHOVER_STATUS

---------------- --------------------

PHYSICAL STANDBY TO PRIMARY


SQL> alter database recover managed standby database disconnect from session;



备切换到主

SQL> ALTER DATABASE COMMIT TO SWITCHOVER TO primary WITH SESSION SHUTDOWN ;

SQL> alter database open;

SQL> select database_role,switchover_status from v$database;


DATABASE_ROLE    SWITCHOVER_STATUS

---------------- --------------------

PRIMARY          SESSIONS ACTIVE




















你可能感兴趣的:(oracle,数据库,dataguard)