配置环境
Oracle: |
Enterprise Edition Release 10.2.0.1.0 - 64bit |
|
机器名: |
CFBDB1 |
CFBDB2 |
IP: |
192.168.0.188 |
192.168.1.188 |
Net_Name |
lscfb1 |
lscfb2 |
SID |
dgtest |
dgtest |
DB_UNIQUE_NAME |
primary |
standby |
1. 主节点上创建数据库dgtest,备节点上只安装oracle软件不创建任何数据库;
2. 主备节点上分别配置好监控和网络名
主节点listener.ora:
# listener.ora Network Configuration File: /opt/oracle/product/10.2.0/db_1/network/admin/listener.ora
# Generated by Oracle configuration tools.
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(SID_NAME = PLSExtProc)
(ORACLE_HOME = /opt/oracle/product/10.2.0/db_1)
(PROGRAM = extproc)
)
(SID_DESC =
(GLOBAL_DBNAME = dgtest)
(ORACLE_HOME = /opt/oracle/product/10.2.0/db_1)
(SID_NAME = dgtest)
)
)
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = CFBDB1)(PORT = 1521))
)
备节点listener.ora:
/opt/oracle/product/10.2.0/db_1/network/admin/listener.ora
# Generated by Oracle configuration tools.
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(SID_NAME = PLSExtProc)
(ORACLE_HOME = /opt/oracle/product/10.2.0/db_1)
(PROGRAM = extproc)
)
(SID_DESC =
(GLOBAL_DBNAME = dgtest)
(ORACLE_HOME = /opt/oracle/product/10.2.0/db_1)
(SID_NAME = dgtest)
)
)
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = CFBDB2)(PORT = 1521))
)
主备节点的tnsname.ora内容一样:
# tnsnames.ora Network Configuration File: /opt/oracle/product/10.2.0/db_1/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.
LSCFB2 =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.188)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = dgtest)
)
)
LSCFB1 =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.188)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = dgtest)
)
)
3. 将置为启用归档模式并启用强制归档
[oracle@CFBDB1 ~]$ sqlplus / as sysdba
SQL*Plus: Release 10.2.0.1.0 - Production on Tue Jan 18 14:10:10 2011
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - 64bit Production
With the Partitioning, OLAP and Data Mining options
SQL> alter database force logging;
Database altered.
SQL> archive log list
Database log mode No Archive Mode
Automatic archival Disabled
Archive destination USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence 16
Current log sequence 18
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount
ORACLE instance started.
Total System Global Area 515899392 bytes
Fixed Size 2021952 bytes
Variable Size 167773632 bytes
Database Buffers 339738624 bytes
Redo Buffers 6365184 bytes
Database mounted.
SQL> ALTER DATABASE ARCHIVELOG;
Database altered.
SQL> ALTER DATABASE OPEN;
Database altered.
SQL> archive log list
Database log mode Archive Mode
Automatic archival Enabled
Archive destination USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence 16
Next log sequence to archive 18
Current log sequence 18
4. 创建密码文件(如果用dbca创建的库,则密码文件已自动创建)
[oracle@CFBDB1 dbs]$ orapwd file='/opt/oracle/product/10.2.0/db_1/dbs/orapwdgtest.ora' password=test123 entries=10
5. 添加standby logfile(也可以不加)
为主数据库添加"备用联机日志文件",这里要保证备日志文件与主库联机日志文件相同大小。
添加备用日志文件是规则:
备用日志最少应该比redo log 多一个。
SQL> startup mount
ORACLE instance started.
SQL>alter database add standby logfile
group 4 ('/opt/oracle/oradata/dgtest/std_redo04a.log','/opt/oracle/oradata/dgtest/std_redo04b.log') size 50m,
group 5 ('/opt/oracle/oradata/dgtest/std_redo05a.log','/opt/oracle/oradata/dgtest/std_redo05b.log') size 50m,
group 6 ('/opt/oracle/oradata/dgtest/std_redo06a.log','/opt/oracle/oradata/dgtest/std_redo06b.log') size 50m,
group 7 ('/opt/oracle/oradata/dgtest/std_redo07a.log','/opt/oracle/oradata/dgtest/std_redo07b.log') size 50m;
6. 创建主库的pfile并修改
SQL> startup mount
ORACLE instance started.
Total System Global Area 515899392 bytes
Fixed Size 2021952 bytes
Variable Size 167773632 bytes
Database Buffers 339738624 bytes
Redo Buffers 6365184 bytes
Database mounted.
SQL> create pfile from spfile;
File created.
修改或添加以下内容
DB_UNIQUE_NAME='primary'
LOG_ARCHIVE_CONFIG='DG_CONFIG=(primary,standby)'
log_archive_dest_1='location=/opt/oracle/flash_recovery_area/ VALID_FOR=(ALL_LOGFILES,ALL_ROLES)' DB_UNIQUE_NAME='primary'
log_archive_dest_2='SERVICE=lscfb2 VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=standby'
LOG_ARCHIVE_DEST_STATE_1=ENABLE
LOG_ARCHIVE_DEST_STATE_2=ENABLE
fal_server=standby
fal_client=primary
remote_login_passwordfile='EXCLUSIVE'
LOG_ARCHIVE_FORMAT=%t_%s_%r.arc
db_file_name_convert='/opt/oracle/oradata/dgtest','/opt/oracle/oradata/dgtest'
log_file_name_convert='/opt/oracle/oradata/dgtest','/opt/oracle/oradata/dgtest'
STANDBY_FILE_MANAGEMENT=AUTO
7. 创建standby数据控制文件,放在数据文件目录中,后面一次性复制到备机
SQL> alter database create standby controlfile as '/opt/oracle/oradata/standby.ctl';
Database altered.
SQL> alter database open;
Database altered.
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
8. 删除spfile文件,下次启动时自动找pfile文件
[oracle@CFBDB1 dbs]$ rm spfiledgtest.ora
9. 拷贝文件,包括数据文件,standby controlfile,密码文件,参数文件,至standby服务器,此处我们将目录admin 、flash_recovery_area、 oradata一并复制到备机
[oracle@CFBDB1 dbs]$ scp initdgtest.ora oracle@cfbdb2:/opt/oracle/product/10.2.0/db_1/dbs/
[oracle@CFBDB1 dbs]$ scp orapwdgtest oracle@cfbdb2:/opt/oracle/product/10.2.0/db_1/dbs/
[oracle@CFBDB1 oracle]$ scp -r admin flash_recovery_area oradata oracle@cfbdb2:/opt/oracle
用pfile启动数据库
SQL> Shutdown immediate
SQL> startup pfile='/opt/oracle/product/10.2.0/db_1/dbs/inittest1.ora'
SQL> create spfile from pfile='/opt/oracle/product/10.2.0/db_1/dbs/inittest1.ora';
SQL> shutdown immediate
SQL> startup
备机:
10. 在备节点上,先删除从主库拷过来的控制文件,并用standby.ctl替代
[oracle@CFBDB2 dgtest]$ rm -f control0*.ctl
[oracle@CFBDB2 dgtest]$ mv ../standby.ctl dgtest/control01.ctl
[oracle@CFBDB2 dgtest]$ cp control01.ctl control02.ctl
[oracle@CFBDB2 dgtest]$ cp control01.ctl control03.ctl
11. 修改备节点的参数文件(在从刚刚拷过来的主库initdgtest.ora文件基础上修改)
DB_UNIQUE_NAME='standby'
LOG_ARCHIVE_CONFIG='DG_CONFIG=(primary,standby)'
log_archive_dest_1='location=/opt/oracle/flash_recovery_area/ VALID_FOR=(ALL_LOGFILES,ALL_ROLES)' DB_UNIQUE_NAME='standby'
log_archive_dest_2='SERVICE=lscfb1 VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=primary'
LOG_ARCHIVE_DEST_STATE_1=ENABLE
LOG_ARCHIVE_DEST_STATE_2=ENABLE
fal_server=primary
fal_client=standby
remote_login_passwordfile='EXCLUSIVE'
LOG_ARCHIVE_FORMAT=%t_%s_%r.arc
db_file_name_convert='/opt/oracle/oradata/dgtest','/opt/oracle/oradata/dgtest'
log_file_name_convert='/opt/oracle/oradata/dgtest','/opt/oracle/oradata/dgtest'
STANDBY_FILE_MANAGEMENT=AUTO
12. 启动主库和备库的listener
13. 启动主库,并从备节点上通过tnsname测试是否连通
14. 启动备库到mount状态
SQL> startup mount
ORACLE instance started.
Total System Global Area 515899392 bytes
Fixed Size 2021952 bytes
Variable Size 146802112 bytes
Database Buffers 360710144 bytes
Redo Buffers 6365184 bytes
Database mounted.
15. 备库上执行以下命令使备库自动应用已归档的日志
SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE DISCONNECT FROM SESSION;
验证:
1.在备库上看当前已归档日志
SQL> select sequence#,first_time,next_time from v$archived_log order by sequence#;
no rows selected
显示当前备份还没有归档日志被应用
2.在主库上执行归档命令并查看已归档的日志;
SQL> alter system archive log current;
System altered.
SQL> select sequence#,first_time,next_time from v$archived_log order by sequence#;
SEQUENCE# FIRST_TIME NEXT_TIME
---------- ---------- ----------
3 24-1? -11 25-1? -11
3 24-1? -11 25-1? -11
3.再次在备库上看当前已归档日志
SQL> select sequence#,first_time,next_time,applied from v$archived_log order by sequence#;
SEQUENCE# FIRST_TIME NEXT_TIME APP
---------- ---------- ---------- ---
3 24-1? -11 25-1? -11 YES
至此表示主库的归档日志已传送到备机,并被备库成功就用,表示DATAGUARD已配置成功.
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/618537/viewspace-684599/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/618537/viewspace-684599/