同一台主机实现物理Data Guard配置安装

实验环境:
1.虚拟机VMware Server 1.0.6
2.操作系统:
ora10g@linux5 /home/oracle$ cat /etc/redhat-release
Red Hat Enterprise Linux Server release 5.1 (Tikanga)
3.数据库环境(OMF管理的数据库):
sys@ora10g> select * from v$version;

BANNER
----------------------------------------------------------------
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - Prod
PL/SQL Release 10.2.0.4.0 - Production
CORE    10.2.0.4.0      Production
TNS for Linux: Version 10.2.0.4.0 - Production
NLSRTL Version 10.2.0.4.0 - Production

一.Primary 数据库配置及相关操作
1.确认primary库处于归档模式
sys@ora10g> archive log list;
Database log mode              Archive Mode
Automatic archival             Enabled
Archive destination            USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence     33
Next log sequence to archive   35
Current log sequence           35

2.将primary库置为FORCE LOGGING 模式
sys@ora10g> alter database force logging;

Database altered.

3.在primary库创建standby数据库控制文件
sys@ora10g> alter database create standby controlfile as '/home/oracle/backup/ora10gdg.ctl';

Database altered.

4.创建primary库客户端初始化参数文件
1).创建主库中的pfile
sys@ora10g> create pfile from spfile;

File created.

2).备份到backup目录用于创建备库的pfile
sys@ora10g> ! cp /oracle/u01/app/oracle/product/10.2.0/db_1/dbs/initora10g.ora /home/oracle/backup/initora10gdg.ora

3).修改后主库pfile中内容如下:
ora10gdg@linux5 /oracle/u01/app/oracle/product/10.2.0/db_1/dbs$ cat initora10g.ora
ora10g.__db_cache_size=20971520
ora10g.__java_pool_size=4194304
ora10g.__large_pool_size=4194304
ora10g.__shared_pool_size=71303168
ora10g.__streams_pool_size=0
*.audit_file_dest='/oracle/u01/app/oracle/admin/ora10g/adump'
*.background_dump_dest='/oracle/u01/app/oracle/admin/ora10g/bdump'
*.compatible='10.2.0.3.0'
*.control_files='/oracle/u02/oradata/ORA10G/controlfile/o1_mf_4srph8fv_.ctl','/oracle/u01/app/oracle/flash_recovery_area/ORA10G/controlfile/o1_mf_4srph96b_.ctl'
*.core_dump_dest='/oracle/u01/app/oracle/admin/ora10g/cdump'
*.cursor_sharing='EXACT'
*.db_block_size=8192
*.db_create_file_dest='/oracle/u02/oradata'
*.db_create_online_log_dest_1='/oracle/u01'
*.db_create_online_log_dest_2='/oracle/u02'
*.db_create_online_log_dest_3='/oracle/u02'
*.db_domain=''
*.db_file_multiblock_read_count=16
*.db_name='ora10g'
*.db_recovery_file_dest='/oracle/u01/app/oracle/flash_recovery_area'
*.db_recovery_file_dest_size=4294967296
*.job_queue_processes=10
*.log_archive_format='%t_%s_%r.dbf'
*.open_cursors=300
*.pga_aggregate_target=16777216
*.processes=500
*.remote_login_passwordfile='EXCLUSIVE'
*.sga_max_size=104857600
*.sga_target=104857600
*.undo_management='AUTO'
*.undo_tablespace='UNDOTBS1'
*.user_dump_dest='/oracle/u01/app/oracle/admin/ora10g/udump'

#################################################################
#Parameters for Primary Database.
#################################################################
*.DB_NAME='ora10g'
*.DB_UNIQUE_NAME=ora10g
*.LOG_ARCHIVE_FORMAT=log%t_%s_%r.arc
*.LOG_ARCHIVE_CONFIG='DG_CONFIG=(ora10g,ora10gdg)'
*.LOG_ARCHIVE_DEST_1='LOCATION=/oracle/u02/oradata/ORA10G VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=ora10g'
*.LOG_ARCHIVE_DEST_2='SERVICE=ora10gdg LGWR ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=ora10gdg'
*.LOG_ARCHIVE_DEST_STATE_1=ENABLE
*.LOG_ARCHIVE_DEST_STATE_2=ENABLE
*.REMOTE_LOGIN_PASSWORDFILE=EXCLUSIVE

#################################################################
#Parameters which using for switch over from Primary to Standby.
#################################################################
*.FAL_SERVER=ora10gdg
*.FAL_CLIENT=ora10g
*.DB_FILE_NAME_CONVERT='/oracle/u02/oradata/ORA10GDG/datafile','/oracle/u02/oradata/ORA10G/datafile'
*.LOG_FILE_NAME_CONVERT='/oracle/u02/oradata/ORA10GDG/onlinelog','/oracle/u02/oradata/ORA10G/onlinelog'
*.STANDBY_FILE_MANAGEMENT=AUTO
*.STANDBY_ARCHIVE_DEST='/ora10g_arch'


4).通过pfile 重建spfile
sys@ora10g> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.

NotConnected@> create spfile from pfile='initora10g.ora';

File created.

5.配置listener
ora10g@linux5 /oracle/u01/app/oracle/product/10.2.0/db_1/network/admin$ cat tnsnames.ora
# tnsnames.ora Network Configuration File: /oracle/u01/app/oracle/product/10.2.0/db_1/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.

ORA10G =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = linux5)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = ora10g)
    )
  )

ORA10GDG =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = linux5)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = ora10gdg)
    )
  )

EXTPROC_CONNECTION_DATA =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC0))
    )
    (CONNECT_DATA =
      (SID = PLSExtProc)
      (PRESENTATION = RO)
    )
  )

ora10g@linux5 /oracle/u02/oradata/ORA10GDG/controlfile$ tnsping ora10g

TNS Ping Utility for Linux: Version 10.2.0.4.0 - Production on 25-MAR-2009 03:03:10

Copyright (c) 1997,  2007, Oracle.  All rights reserved.

Used parameter files:
/oracle/u01/app/oracle/product/10.2.0/db_1/network/admin/sqlnet.ora


Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = linux5)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = ora10g)))
OK (50 msec)
ora10g@linux5 /oracle/u02/oradata/ORA10GDG/controlfile$ tnsping ora10gdg

TNS Ping Utility for Linux: Version 10.2.0.4.0 - Production on 25-MAR-2009 03:03:17

Copyright (c) 1997,  2007, Oracle.  All rights reserved.

Used parameter files:
/oracle/u01/app/oracle/product/10.2.0/db_1/network/admin/sqlnet.ora


Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = linux5)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = ora10gdg)))
OK (10 msec)

二.Standby数据库配置及相关操作
1.创建密码文件,注意保持sys 密码与primary 数据库一致
ora10g@linux5 /oracle/u01/app/oracle/product/10.2.0/db_1/dbs$ orapwd file=orapwora10gdg password=sys entries=30

2.创建所需目录(注意OMF管理的文件)
ora10g@linux5 /home/oracle$ cd $ORACLE_BASE/admin
ora10g@linux5 /oracle/u01/app/oracle/admin$ mkdir ora10gdg
ora10g@linux5 /oracle/u01/app/oracle/admin$ cd ora10gdg
ora10g@linux5 /oracle/u01/app/oracle/admin/ora10gdg$ mkdir dpdump
ora10g@linux5 /oracle/u01/app/oracle/admin/ora10gdg$ mkdir cdump
ora10g@linux5 /oracle/u01/app/oracle/admin/ora10gdg$ mkdir pfile
ora10g@linux5 /oracle/u01/app/oracle/admin/ora10gdg$ mkdir bdump
ora10g@linux5 /oracle/u01/app/oracle/admin/ora10gdg$ mkdir udump
ora10g@linux5 /oracle/u01/app/oracle/admin/ora10gdg$ mkdir adump

ora10g@linux5 /oracle/u01/app/oracle/flash_recovery_area$ mkdir ORA10GDG
ora10g@linux5 /oracle/u01/app/oracle/flash_recovery_area$ cd ORA10GDG
ora10g@linux5 /oracle/u01/app/oracle/flash_recovery_area/ORA10GDG$ mkdir controlfile
ora10g@linux5 /oracle/u01/app/oracle/flash_recovery_area/ORA10GDG$ mkdir onlinelog
ora10g@linux5 /oracle/u01/app/oracle/flash_recovery_area/ORA10GDG$ mkdir backupset
ora10g@linux5 /oracle/u01/app/oracle/flash_recovery_area/ORA10GDG$ mkdir autobackup
ora10g@linux5 /oracle/u01/app/oracle/flash_recovery_area/ORA10GDG$ mkdir archivelog

3.复制数据文件到standby库对应的目录(datafile,log,controlfiles)
1).拷贝数据文件
$ cp -R /oracle/u02/oradata/ORA10G/datafile /oracle/u02/oradata/ORA10GDG
2).拷贝日志文件,注意是OMF管理的
$ cp -R /oracle/u02/oradata/ORA10G/onlinelog /oracle/u02/oradata/ORA10GDG
$ cp -R /oracle/u01/app/oracle/flash_recovery_area/ORA10G/onlinelog /oracle/u01/app/oracle/flash_recovery_area/ORA10GDG
3).拷贝主库生成的控制文件,注意是OMF管理的
$ cp /home/oracle/backup/ora10gdg.ctl /oracle/u02/oradata/ORA10GDG/controlfile/o1_mf_4srph8fv_.ctl
$ cp /home/oracle/backup/ora10gdg.ctl /oracle/u01/app/oracle/flash_recovery_area/ORA10GDG/controlfile/o1_mf_4srph96b_.ctl


4.修改standby初始化参数文件
1).standby的初始化参数如下
ora10gdg@linux5 /oracle/u01/app/oracle/product/10.2.0/db_1/dbs$ cat initora10gdg.ora
ora10g.__db_cache_size=20971520
ora10g.__java_pool_size=4194304
ora10g.__large_pool_size=4194304
ora10g.__shared_pool_size=71303168
ora10g.__streams_pool_size=0
*.audit_file_dest='/oracle/u01/app/oracle/admin/ora10gdg/adump'
*.background_dump_dest='/oracle/u01/app/oracle/admin/ora10gdg/bdump'
*.compatible='10.2.0.3.0'
*.control_files='/oracle/u02/oradata/ORA10GDG/controlfile/o1_mf_4srph8fv_.ctl','/oracle/u01/app/oracle/flash_recovery_area/ORA10GDG/controlfile/o1_mf_4srph96b_.ctl'
*.core_dump_dest='/oracle/u01/app/oracle/admin/ora10gdg/cdump'
*.cursor_sharing='EXACT'
*.db_block_size=8192
*.db_create_file_dest='/oracle/u02/oradata'
*.db_create_online_log_dest_1='/oracle/u01'
*.db_create_online_log_dest_2='/oracle/u02'
*.db_create_online_log_dest_3='/oracle/u02'
*.db_domain=''
*.db_file_multiblock_read_count=16
*.db_name='ora10g'
*.db_recovery_file_dest='/oracle/u01/app/oracle/flash_recovery_area'
*.db_recovery_file_dest_size=4294967296
*.job_queue_processes=10
*.log_archive_format='%t_%s_%r.dbf'
*.open_cursors=300
*.pga_aggregate_target=16777216
*.processes=500
*.remote_login_passwordfile='EXCLUSIVE'
*.sga_max_size=104857600
*.sga_target=104857600
*.undo_management='AUTO'
*.undo_tablespace='UNDOTBS1'
*.user_dump_dest='/oracle/u01/app/oracle/admin/ora10gdg/udump'

#################################################################
#Parameters for Standby Database.
#################################################################
*.DB_NAME='ora10g'
*.DB_UNIQUE_NAME=ora10gdg
*.LOG_ARCHIVE_FORMAT=log%t_%s_%r.arc
*.LOG_ARCHIVE_CONFIG='DG_CONFIG=(ora10g,ora10gdg)'
*.DB_FILE_NAME_CONVERT='/oracle/u02/oradata/ORA10G/datafile','/oracle/u02/oradata/ORA10GDG/datafile'
*.LOG_FILE_NAME_CONVERT='/oracle/u02/oradata/ORA10G/onlinelog','/oracle/u02/oradata/ORA10GDG/onlinelog'
*.STANDBY_ARCHIVE_DEST='/ora10gdg_arch'
*.FAL_SERVER=ora10g
*.FAL_CLIENT=ora10gdg
*.STANDBY_FILE_MANAGEMENT=AUTO

#################################################################
#Parameters which using for switch over from Standby to Primary.
#################################################################
*.LOG_ARCHIVE_DEST_1='LOCATION=/oracle/u02/oradata/ORA10GDG VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=ora10gdg'
*.LOG_ARCHIVE_DEST_2='SERVICE=ora10g LGWR ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=ora10g'
*.LOG_ARCHIVE_DEST_STATE_1=ENABLE
*.LOG_ARCHIVE_DEST_STATE_2=ENABLE
*.REMOTE_LOGIN_PASSWORDFILE=EXCLUSIVE

2).通过该pfile 创建spfile
NotConnected@> create spfile from pfile= 'initora10gdg.ora';

File created.

5.启动standby 到mount
NotConnected@> startup mount;
ORACLE instance started.

Total System Global Area  104857600 bytes
Fixed Size                  1266056 bytes
Variable Size              79695480 bytes
Database Buffers           20971520 bytes
Redo Buffers                2924544 bytes
Database mounted.

6.启动redo 应用
NotConnected@> alter database recover managed standby database disconnect from session;

Database altered.

7.查看同步情况
首先连接到primary 数据库
sys@ora10g> select instance_name,host_name,version,status from v$instance;

INSTANCE_NAME    HOST_NAME            VERSION           STATUS
---------------- -------------------- ----------------- ------------
ora10g           linux5               10.2.0.4.0        OPEN

sys@ora10g> alter system switch logfile;

System altered.

sys@ora10g> select max(sequence#) from v$archived_log;

MAX(SEQUENCE#)
--------------
            36

连接到standby 数据库
NotConnected@> select instance_name,host_name,version,status from v$instance;

INSTANCE_NAME    HOST_NAME            VERSION           STATUS
---------------- -------------------- ----------------- ------------
ora10gdg         linux5               10.2.0.4.0        MOUNTED

NotConnected@> select max(sequence#) from v$archived_log;

MAX(SEQUENCE#)
--------------
            36

8.暂停redo 应用
NotConnected@>ALTER DATABASE RECOVER MANAGED STANDBY DATABASE CANCEL;

三.验证standby数据库正确性
1.primary在sec用户创建一个表
sec@ora10g> create table test_dg (a int);

Table created.

sec@ora10g> conn / as sysdba
Connected.
sys@ora10g> alter system switch logfile;

System altered.

sys@ora10g> select max(sequence#) from v$archived_log;

MAX(SEQUENCE#)
--------------
            38

2.查看standby是否存在该表
NotConnected@> select max(sequence#) from v$archived_log;

MAX(SEQUENCE#)
--------------
            38

NotConnected@> alter database recover managed standby database cancel;

Database altered.

NotConnected@> alter database open read only;

Database altered.

sys@ora10g> conn sec/sec
Connected.

sec@ora10g> desc test_dg;
 Name       Null?    Type
 ---------- -------- ---------------
 A                   NUMBER(38)

OK,成功。
-------------------------------------------------------------------

1. 备用服务器的管理模式与只读模式

1)启动到管理模式,从数据库是处于Redo应用模式

SQL>shutdown immediate;

SQL>startup nomount;

SQL>alter database mount standby database;

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

2)启动到只读方式

 

SQL>shutdown immediate;

SQL>startup nomount;

SQL>alter database mount standby database;

SQL>alter database open read only;

3)在管理恢复模式下到只读模式

SQL>recover managed standby database cancel;

SQL>alter database open read only;

这个时候,可以给数据库增加临时数据文件(如果这个在热备份的时候是没有备份过来的)

alter tablespace temp add tempfile '/opt/oracle/oradata/ge/temp01.dbf' size 100M;

4)从只读方式到管理恢复方式

SQL>recover managed standby database disconnect from session;

posted @ 2010-01-30 01:32  无双的小宝  阅读(449)  评论(0编辑  收藏  举报