單機搭建Data Guard
搭建環境:
Red Hat Linux Enterprise 5.4
Oracle 10g R2
主機作業系統主要資訊為192.168.199.128.
搭建準備:
已存在主庫(生產庫)DB_NAME=mustang SID=april
開始搭建Data Guard
首先需要準備好引數檔案,設定一些必要的引數。在主庫,先透過spfile生成pfile檔案:
SQL>create pfile=’/home/oracle/product/10.2initapril.ora’ from spfile;
然後修改主庫新生成的initapril.ora引數檔案。在原有的基礎上新增如下內容:
db_unique_name=mustang
log_archive_config='DG_CONFIG=(mustang,standby)'
log_archive_dest_2='service=standby arch async valid_for=(online_logfiles,primary_role)
db_unique_name=standby'
log_archive_dest_1='location=/home/oracle/archive valid_for=(all_logfiles,all_roles)
db_unique_name=mustang'
log_archive_dest_state_1=enable
log_archive_dest_state_2=enable
log_archive_format=%t_%s_%r.arc
log_archive_max_processes=30
fal_server=standby
fal_client=mustang
db_file_name_convert='standby','mustang'
log_file_name_convert='/home/oracle/','/home/oracle/standby/'
standby_file_management=auto
修改完引數檔案之後,要重新開啟主庫,然後透過iniapril.ora來建立spfile。如下:
SQL>create spfile=’/home/oracle/product/10.2.0/db_1/dbs/spfileapril.ora’ from pfile=’
/home/oracle/product/10.2.0/db_1/dbs/initapril.ora’;
接下來的工作就是要透過主庫的引數檔案,建立備庫需要的引數檔案,在主庫上執行:
SQL>create pfile=’ /home/oracle/product/10.2.0/db_1/dbs/initstandby.ora’ from spfile;
編輯initstandby.ora。如下所示:
standby.__db_cache_size=213909504
standby.__large_pool_size=4194304
*.control_files='/home/oracle/standby/standby.ctl'
*.db_file_multiblock_read_count=8
*.db_file_name_convert='standby','mustang'
*.db_files=80
*.db_name='mustang'
*.db_unique_name='standby'
*.fal_client='standby'
*.fal_server='mustang'
*.global_names=TRUE
*.instance_name='standby'
*.log_archive_config='DG_CONFIG=(mustang,standby)'
*.log_archive_dest_1='location=/home/oracle/standby/archive'
*.log_archive_dest_2='service=mustang arch async valid_for=(online_logfiles,primary_role)
db_unique_name=mustang'
*.log_archive_dest_state_1='enable'
*.log_archive_dest_state_2='enable'
*.log_archive_format='%t_%s_%r.arc'
*.log_archive_max_processes=30
*.log_buffer=32768
*.log_checkpoint_interval=10000
*.log_file_name_convert='/home/oracle/','/home/oracle/standby/'
*.max_dump_file_size='10240'
*.parallel_max_servers=5
*.processes=50
*.service_names='standby'
*.sga_max_size=300M
*.sga_target=300M
*.standby_file_management='auto'
*.undo_management='auto'
*.undo_tablespace='undotbs'
儲存initstandby.ora引數檔案。透過initstandby.ora生成動態檔案spfilestandby.ora:
SQL>create spfile=’/home/oracle/product/10.2.0/db_1/dbs/spfilestandby.ora’ from pfile=’
/home/oracle/product/10.2.0/db_1/dbs/initstandby.ora’;
在主庫上建立我們的密碼檔案:
[oracle@localhost dbs]$orapwd file=’ /home/oracle/product/10.2.0/db_1/dbs/orapwstandby’ password=oracle entries=10
透過主庫的控制檔案生成我們備庫的控制檔案:
SQL>alter database create standby controlfile as ‘/home/oracle/standby.ctl’;
開始建立備庫:
首先建立備庫的目錄結構,這裡我們以主庫位於同一目錄:
主庫:/home/oracle/mustang 主庫歸檔檔案:/home/oracle/archive
於是我們在/home/oracle下建立我們的備庫目錄:
mkdir standby
cd standby
mkdir archive
mkdir bdump
mkdir udump
目錄結構完成。
下一步就是要配置監聽(如果沒有監聽standby是啟動不了的)。在配置監聽之前,首先要進行一步就是要生成備庫的密碼檔案:
[oracle@localhost dbs]$orapwd file=’ /home/oracle/product/10.2.0/db_1/dbs/orapwstandby’ password=oracle entries=10
將路徑切換到/home/oracle/product/10.2.0/db_1/network/admin下。透過ls命令可以看到:
[oracle@localhost admin]$ ls
listener.ora shrept.lst sqlnet.log tnsnames.ora
再配置監聽之前,要先將我們的監聽服務停止:lsnrctl stop。
開始配置監聽
首先配置tnsnames.ora檔案。設定服務名(因為我們這裡是單機,所以配置在本機上配置就行了,如果是兩臺機的話,就要在主備庫的tnsnames.ora同時修改):
april=
(DESCRIPTION=
(ADDRESS=(PROTOCOL=TCP)(HOST=localhost.localdomain)(PORT=1521))
(CONNECT_DATA=
(SERVER=DEDICATED)
(SERVICE_NAME=mustang)
)
)
standby=
(DESCRIPTION=
(ADDRESS=(PROTOCOL=TCP)(HOST=localhost.localdomain)(PORT=1522))
(CONNECT_DATA=
(SERVER=DEDICATED)
(SERVICE_NAME=standby)
)
)
接下來配置listener.ora檔案(建議用途netmgr配置,比較方便,因為手工配置容易出錯)。配置如下:
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = mustang)
(ORACLE_HOME = /home/oracle/product/10.2.0/db_1)
(SID_NAME = april)
)
(SID_DESC =
(GLOBAL_DBNAME = standby)
(ORACLE_HOME = /home/oracle/product/10.2.0/db_1)
(SID_NAME = standby)
)
)
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = localhost.localdomain)(PORT = 1521))
)
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = localhost.localdomain)(PORT = 1522))
)
)
TRACE_LEVEL_LISTENER = USER
至此我們的監聽配置就完成,啟動監聽器:
[oracle@localhost admin]$ lsnrctl start
出現如下內容說明,已經配置成功:
LSNRCTL for Linux: Version 10.2.0.1.0 - Production on 26-JUL-2012 20:59:37
Copyright (c) 1991, 2005, Oracle. All rights reserved.
Starting /home/oracle/product/10.2.0/db_1/bin/tnslsnr: please wait...
TNSLSNR for Linux: Version 10.2.0.1.0 - Production
System parameter file is /home/oracle/product/10.2.0/db_1/network/admin/listener.ora
Log messages written to /home/oracle/product/10.2.0/db_1/network/log/listener.log
Trace information written to /home/oracle/product/10.2.0/db_1/network/trace/listener.trc
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=localhost.localdomain)(PORT=1521)))
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=localhost.localdomain)(PORT=1522)))
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost.localdomain)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Linux: Version 10.2.0.1.0 - Production
Start Date 26-JUL-2012 20:59:37
Uptime 0 days 0 hr. 0 min. 0 sec
Trace Level user
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /home/oracle/product/10.2.0/db_1/network/admin/listener.ora
Listener Log File /home/oracle/product/10.2.0/db_1/network/log/listener.log
Listener Trace File /home/oracle/product/10.2.0/db_1/network/trace/listener.trc
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=localhost.localdomain)(PORT=1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=localhost.localdomain)(PORT=1522)))
Services Summary...
Service "mustang" has 1 instance(s).
Instance "april", status UNKNOWN, has 1 handler(s) for this service...
Service "standby" has 1 instance(s).
Instance "standby", status UNKNOWN, has 1 handler(s) for this service...
The command completed successfully
我們也可以透過tnsping來檢查,是否配置成功:
[oracle@localhost admin]$ tnsping standby
TNS Ping Utility for Linux: Version 10.2.0.1.0 - Production on 26-JUL-2012 21:00:45
Copyright (c) 1997, 2005, Oracle. All rights reserved.
Used parameter files:
Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION= (ADDRESS=(PROTOCOL=TCP)(HOST=localhost.localdomain)(PORT=1522)) (CONNECT_DATA= (SERVER=DEDICATED) (SERVICE_NAME=standby)))
OK (20 msec)
[oracle@localhost admin]$ tnsping april
TNS Ping Utility for Linux: Version 10.2.0.1.0 - Production on 26-JUL-2012 21:00:51
Copyright (c) 1997, 2005, Oracle. All rights reserved.
Used parameter files:
Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION= (ADDRESS=(PROTOCOL=TCP)(HOST=localhost.localdomain)(PORT=1521)) (CONNECT_DATA= (SERVER=DEDICATED) (SERVICE_NAME=mustang)))
OK (30 msec)
看到以上提示,說明我們的監聽配置完全正確。
複製相關檔案到備庫的目錄下:
[oracle@localhost mustang]$cp /home/oracle/mustang/*.dbf /home/oracle/standby
[oracle@localhost mustang]$cp /home/oracle/standby.ctl /home/oracle/standby/
接下來,開始啟動我們的主庫和備庫,最好開啟兩個視窗進行實驗:
在主庫視窗:
1)指定以april例項開始我們的主庫:
export ORACLE_SID=april
2)
[oracle@localhost admin]$ sqlplus sys/oracle@april as sysdba
3)開啟主庫的歸檔模式和force logging:
SQL>alter database archivelog;
SQL>alter database force logging;
在備庫視窗:
1) 指定以standby例項開啟我們的備庫:
export ORACLE_SID=standby
2)
[oracle@localhost admin]$ sqlplus sys/oracle@standby as sysdba
3) 使standby資料庫處於恢復狀態,主備庫歸檔日誌同步
SQL>alter database recover managed standby database disconnect from session:
接下來就要檢視我們的Data Guard是否正常。
我們在主庫環境下,檢視當前的歸檔日誌情況:
SQL>select sequence#,first_time,next_time from v$archived_log order by sequence#;
然後切換到備庫環境下,檢視當前的歸檔日誌情況:
SQL>select sequence#,first_time,next_time from v$archived_log order by sequence#;
接著我們再次切換到主庫環境下,進行一次日誌切換:
SQL>alter system switch logfile;
再次檢視主庫的歸檔情況:
SQL>select sequence#,first_time,next_time from v$archived_log order by sequence#;
這時,你會發現多了2個歸檔檔案。
我們再切到備庫,檢視:
SQL>select sequence#,first_time,next_time from v$archived_log order by sequence#;
發現備庫的歸檔檔案也同樣多了。
至此,可以說明我們的歸檔同步了。
在主庫下:我們新建一個表,然後往表中插入資料,先不要commit。我們發現備庫中也同樣有了這個表,但是還沒有資料,如果我們commit掉主庫的事務,備庫中該表就有了資料了。
我們可以檢視主庫和備庫的switchover引數。
SQL>select switchover_status,database_role from v$database;
DG搭建工作至此完成。剛剛學習Data Guard,上文有不正確的地方,還請多多批評賜教!
©著作權歸作者所有:來自51CTO部落格作者鄭宏輝的原創作品,如需轉載,請註明出處,否則將追究法律責任
oracle單機DGOracle
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/3034/viewspace-2821231/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 單機上快速搭建一個Data Guard環境
- Data guard搭建
- 【DG】Data Guard搭建(physical standby)
- RedHat搭建物理Data GuardRedhat
- 搭建Active Data Guard環境
- 容災技術Data Guard搭建
- Data Guard搭建困境突圍(一)
- Oracle RAC + Data Guard 環境搭建Oracle
- Oracle 12c Data Guard搭建(一)Oracle
- 搭建邏輯Data Guard 12c
- 不停機 data guard 以及 switchover
- Data guard 配置之搭建物理備庫
- DATA GUARD部署模式——DATA GUARD概念和管理模式
- win2003不同主機上搭建物理data guard
- 搭建Oracle Data Guard 11g(物理備用)Oracle
- 介紹ORACLE DATA GUARD——DATA GUARD概念和管理Oracle
- oracle data guard!!Oracle
- 搭建11g data guard(duplicate from active database方式)Database
- Data Guard 之RMAN備份線上搭建物理standby
- 12c 容災之Active Data Guard本機搭建和基礎測試
- Data Guard Broker系列之二:Data Guard Broker配置實戰
- DATA GUARD 簡介
- Data Guard 建立(ASM)ASM
- Oracle Data Guard配置Oracle
- Oracle Data Guard Linux 平臺 Physical Standby 搭建例項OracleLinux
- Oracle 11g Data Guard Enabling Active Data GuardOracle
- [Data Guard]Oracle10g Data Guard學習筆記(一)Oracle筆記
- [Data Guard]Oracle10g Data Guard學習筆記(二)Oracle筆記
- [Data Guard]Oracle10g Data Guard學習筆記(三)Oracle筆記
- 半自動化搭建Data Guard的想法和實踐(一)
- 半自動化搭建Data Guard的想法和實踐(二)
- 半自動化搭建Data Guard的想法和實踐(四)
- 半自動化搭建Data Guard的想法和實踐(三)
- Oracle RAC & Data Guard搭建高可用資料庫系統方案Oracle資料庫
- Oracle Data Guard Linux 平臺 Physical Standby 搭建例項-3OracleLinux
- Oracle Data Guard Linux 平臺 Physical Standby 搭建例項 -2OracleLinux
- Oracle Data Guard Linux 平臺 Physical Standby 搭建例項 -1OracleLinux
- Oracle Data Guard Broker元件Oracle元件