DataGuard实战1
-------------------------------------------2013/10/27
一.Primary数据库的配置及操作
1. 确定主库处于归档日志模式。
SQL> archive log list;
2. 将主库设置成force logging模式。
SQL> alter database force logging;
3. 创建standby数据库控制文件。
SQL> alter database create standby controlfile as ‘/u01/august01.ctl’;
--一定要生成standby的控制文件,不能直接用主库的控制文件。不然会抱错,提示该控制文件不是一个standby控制文件。
4. 修改primary数据库的参数文件。
例如:[Oracle@localhost dbs]$ cat initaugust.ora
august.__db_cache_size=92274688
august.__java_pool_size=4194304
august.__large_pool_size=4194304
august.__oracle_base='/u01/app/oracle'#ORACLE_BASE set from environment
august.__pga_aggregate_target=146800640
august.__sga_target=276824064
august.__shared_io_pool_size=0
august.__shared_pool_size=163577856
august.__streams_pool_size=4194304
*.audit_file_dest='/u01/app/oracle/admin/august/adump'
*.audit_trail='db'
*.compatible='11.2.0.0.0'
*.control_files='/u01/app/oracle/oradata/august/august/control01.ctl','/u01/app/oracle/flash_recovery_area/august/august/control02.ctl'#Restore Controlfile
*.db_block_size=8192
*.db_domain=''
*.db_name='august'
*.db_unique_name=augustpri
*.log_archive_config='dg_config=(augustpri,augustdg)'
*.log_archive_dest_1='location=/u01/app/oracle/flash_recovery_area/august/arch valid_for=(all_logfiles,all_roles) db_unique_name=augustpri'
--这里是本地存放日志的地方
*.log_archive_dest_2='service=augustdg lgwr async valid_for=(online_logfiles,primary_role) db_unique_name=augustdg'
--这是设置将日志传给standby数据库,service和db_unique_name设置为备库的。
*.log_archive_dest_state_1=enable
*.log_archive_dest_state_2=enable
*.remote_login_passwordfile=exclusive
*.fal_server=augustdg
*.fal_client=augustpri
*.standby_file_management=auto
*.db_recovery_file_dest='/u01/app/oracle/flash_recovery_area/august'
*.db_recovery_file_dest_size=4039114752
*.diagnostic_dest='/u01/app/oracle'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=augustXDB)'
*.log_archive_format='%t_%s_%r.dbf'
*.memory_target=420478976
*.open_cursors=300
*.processes=150
*.remote_login_passwordfile='EXCLUSIVE'
*.undo_tablespace='UNDOTBS1'
5. 关闭数据库,重新由pfile生成新的spfile
SQL> shutdown immediate;
SQL> create spfile from pfile; / SQL> create spfile from pfile=’/**/**/init_name.ora’;
6. 使用rman备份数据库,并传输到目标数据库。
RMAN> backup database include current controlfile for standby plus archivelog;
*7. 创建standby log文件。
SQL> shutdown immediate;
SQL> startup mount;
SQL> alter database add standby logfile
group 4 ('/opt/oracle/oradata/fost/std_redo04.log') size 50m,
group 5 ('/opt/oracle/oradata/fost/std_redo05.log') size 50m,
group 6 ('/opt/oracle/oradata/fost/std_redo06.log') size 50m,
group 7 ('/opt/oracle/oradata/fost/std_redo07.log') size 50m;
SQL> alter database open;
8. 将数据库密码文件传输到standby数据库,如果之前有,而且密码一致就可以不传输。
二. Standby数据库的配置及操作。
1. 将primary数据库的参数文件拷贝到standby数据库,或者直接手动修改。
例如:[Oracle@localhost dbs]$ cat initaugust.ora
august.__db_cache_size=79691776
august.__java_pool_size=4194304
august.__large_pool_size=4194304
august.__oracle_base='/u01/app/oracle'#ORACLE_BASE set from environment
august.__pga_aggregate_target=159383552
august.__sga_target=264241152
august.__shared_io_pool_size=0
august.__shared_pool_size=163577856
august.__streams_pool_size=4194304
*.audit_file_dest='/u01/app/oracle/admin/august/adump'
*.audit_trail='db'
*.compatible='11.2.0.0.0'
*.control_files='/u01/app/oracle/oradata/august/august/control01.ctl','/u01/app/oracle/flash_recovery_area/august/august/control02.ctl'#Restore Controlfile
*.db_block_size=8192
*.db_domain=''
*.db_name='august'
*.db_unique_name=augustdg
*.log_archive_config='dg_config=(augustpri,augustdg)'
*.log_archive_dest_1='location=/u01/app/oracle/flash_recovery_area/august/arch valid_for=(all_logfiles,all_roles) db_unique_name=augustdg'
--这里应该是接受到主库传输的日志归档后的地方。
*.log_archive_dest_2='service=augustpri lgwr async valid_for=(online_logfiles,primary_role) db_unique_name=augustpri'
--这里设置为将日志传给Primary库的配置,其中service和db_unique_name都应该设置Primary数据对应的值。
*.log_archive_dest_state_1=enable
*.log_archive_dest_state_2=enable
*.remote_login_passwordfile=exclusive
*.fal_server=augustpri
*.fal_client=augustdg
*.standby_file_management=auto
*.db_recovery_file_dest='/u01/app/oracle/flash_recovery_area/august'
*.db_recovery_file_dest_size=4039114752
*.db_unique_name='AUGUSTDG'
*.diagnostic_dest='/u01/app/oracle'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=augustXDB)'
*.log_archive_format='%t_%s_%r.dbf'
*.memory_target=420478976
*.open_cursors=300
*.processes=150
*.remote_login_passwordfile='EXCLUSIVE'
*.undo_tablespace='UNDOTBS1'
2. 利用此参数文件启动实例到nomount下,并生成spfile文件。
RMAN> startup nomount;
RMAN> sql 'create spfile from pfile';
3. 将Primary生成的standby控制文件,复制到standby数据库中对应的目录中。
4. 根据参数文件,创建相应的目录,然后利用rman备份数据restore并恢复数据库。
5. 在数据库mount状态下,打开recover模式。
SQL> alter database recover managend standby database disconnect from session;
*5。在standby数据库中创建standby log文件。
SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE CANCEL;
SQL> alter database add standby logfile
group 4 ('/opt/oracle/oradata/fost/std_redo04.log') size 50m,
group 5 ('/opt/oracle/oradata/fost/std_redo05.log') size 50m,
group 6 ('/opt/oracle/oradata/fost/std_redo06.log') size 50m,
group 7 ('/opt/oracle/oradata/fost/std_redo07.log') size 50m;
SQL> shutdown immediate;
SQL> startup mount;
SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE DISCONNECT FROM SESSION;
至此DataGuard搭建成功!
三. 相关设置
1. 查看Primary数据库角色及保护模式。
SQL> select database_role,protection_mode,protection_level from v$database;
DATABASE_ROLE PROTECTION_MODE PROTECTION_LEVEL
‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
PRIMARY MAXIMUM PERFORMANCE MAXIMUM PERFORMANCE
2. 修改为最大可用性模式并验证。
SQL> alter database set standby database to maximize availability;
Database altered.
SQL> select database_role,protection_mode,protection_level from v$database;
DATABASE_ROLE PROTECTION_MODE PROTECTION_LEVEL
‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
PRIMARY MAXIMUM AVAILABILITY RESYNCHRONIZATION
注意:如果发现dataguard 搭建后,日志并没有传输到备机,没有同步。那么通过视图v$arch_dest查看错误信息
select dest_id,error from v$arch_dest;
也可以通过trace file查看详细错误信息。
相关链接:
http://www.5ienet.com/note/html/dg/physical-standby-created-step.shtml
http://www.5ienet.com/note/html/dg/physical-standby-created-script.shtml
http://www.5ienet.com/note/html/dg/physical-standby-role-switch.shtml