【DataGuard】同一臺主機實現物理Data Guard配置安裝

secooler發表於2011-06-09
實驗環境:
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.配置tnsnames.ora檔案
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@ora10gdg> conn sec/sec
Connected.

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

OK,成功。

Good luck.

secooler
11.06.09

-- The End --

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/519536/viewspace-578181/,如需轉載,請註明出處,否則將追究法律責任。

相關文章