oracle11201 dataguard

1、primary
[oracle@oracle11 admin]$ sqlplus '/as sysdba'
SQL*Plus: Release 11.2.0.1.0 Production on Fri Apr 27 22:04:17 2012
Copyright (c) 1982, 2009, Oracle.  All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
打开归档模式
SQL> alter system set log_archive_dest_1='location=/home/oracle/archivelog' scope =both;


System altered.

SQL> shut immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount
ORACLE instance started.


Total System Global Area  304807936 bytes
Fixed Size                  2212856 bytes
Variable Size             134220808 bytes
Database Buffers          163577856 bytes
Redo Buffers                4796416 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            /home/oracle/archivelog
Oldest online log sequence     70
Next log sequence to archive   72
Current log sequence           72
SQL> exit

rman备份数据库
[oracle@oracle11 ~]$ rman target /


Recovery Manager: Release 11.2.0.1.0 - Production on Fri Apr 27 19:47:32 2012


Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.


connected to target database: ORA11 (DBID=725596258)


RMAN> run{
2> allocate channel ch1 device type disk format '/home/oracle/rman/%d_%p_%Y_%M';
3>     CONFIGURE CONTROLFILE AUTOBACKUP ON;
4>     CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '/home/oracle/rman/%d_%F.ctl';
5>     backup database ;
6>     release channel ch1;
7>     }

将备份文件拷贝到备机
[root@oracle11 rman]# ll
总用量 976580
-rw-r-----. 1 oracle oinstall 990183424  4月 27 19:48 ORA11_1_2012_04
-rw-r-----. 1 oracle oinstall   9830400  4月 27 19:48 ORA11_c-725596258-20120427-00.ctl
[root@oracle11 rman]# scp ORA11_1_2012_04 root@192.177.100.110:/home/oracle/rman/
root@192.177.100.110's password: 
ORA11_1_2012_04                                                                                   100%  944MB  10.1MB/s   01:34    
[root@oracle11 rman]# 
[root@oracle11 rman]# 
[root@oracle11 rman]# ll
总用量 976580
-rw-r-----. 1 oracle oinstall 990183424  4月 27 19:48 ORA11_1_2012_04
-rw-r-----. 1 oracle oinstall   9830400  4月 27 19:48 ORA11_c-725596258-20120427-00.ctl
[root@oracle11 rman]# scp  ORA11_c-725596258-20120427-00.ctl  root@192.177.100.110:/home/oracle/rman/
root@192.177.100.110's password: 
ORA11_c-725596258-20120427-00.ctl                                                                 100% 9600KB   9.4MB/s   00:01    

修改主库参数
SQL> alter system set log_archive_config=(ora11,ora11standby) scope=both;
alter system set log_archive_config=(ora11,ora11standby) scope=both
                                     *
ERROR at line 1:
ORA-02065: illegal option for ALTER SYSTEM




SQL> alter system set log_archive_config='dg_config=(ora11,ora11standby)' scope=both;


System altered.


SQL> alter system set log_archive_dest_2='location=/home/oracle/dg_archive valid_for=(all_logfiles,all_roles) db_unique_name=ora11' scope =both;


System altered.


SQL> alter system set log_archive_dest_3='service=ora11standby valid_for=(online_logfiles,primary_role) db_unique_name=ora11standby' scope=both;


System altered.


SQL> alter system set fal_client=ora11 scope=both;


System altered.


SQL> alter system set fal_server=ora11standby scope=both;


System altered.

在主库的tns文件中增加到备库的连接串
ora11standby =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.177.100.110)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = ora11)
      (SERVER = DEDICATED)
    )
  )
要保证是联通的

主库上生成备库的控制文件以及pfile
[oracle@oracle11 ~]$ sqlplus '/as sysdba'


SQL*Plus: Release 11.2.0.1.0 Production on Fri Apr 27 19:54:33 2012


Copyright (c) 1982, 2009, Oracle.  All rights reserved.




Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options


SQL> alter database create standby controlfile as '/home/oracle/stanby.ctl'
  2  ;
SQL> create pfile from spfile;

将上面2个文件scp到备机,到这主库的操作就完成了


以下是备库的操作:
修改主库传过来的pfile文件

[oracle@oracle11g-std dbs]$ more initora11.ora
ora11.__db_cache_size=163577856
ora11.__java_pool_size=4194304
ora11.__large_pool_size=4194304
ora11.__oracle_base='/home/oracle/app'#ORACLE_BASE set from environment
ora11.__pga_aggregate_target=104857600
ora11.__sga_target=306184192
ora11.__shared_io_pool_size=0
ora11.__shared_pool_size=125829120
ora11.__streams_pool_size=0
*.audit_file_dest='/home/oracle/app/admin/ora11/adump'
*.audit_trail='db'
*.compatible='11.2.0.0.0'
*.control_files='/home/oracle/app/oradata/ora11/control01.ctl','/home/oracle/app/flash_recovery_area/ora11/control02.ctl'
*.db_block_size=8192
*.db_domain='us.oracle.com'
*.db_name='ora11'
*.db_recovery_file_dest='/home/oracle/app/flash_recovery_area'
*.db_recovery_file_dest_size=5218762752
*.diagnostic_dest='/home/oracle/app'
*.log_archive_dest_1='location=/home/oracle/archivelog'
*.open_cursors=300
*.pga_aggregate_target=101711872
*.processes=150
*.remote_login_passwordfile='EXCLUSIVE'
*.sga_target=306184192
*.undo_tablespace='UNDOTBS1'
*.db_unique_name=ora11standby----新增一个参数


主库上的参数如下:
[oracle@oracle11 admin]$ more /home/oracle/app/product/11.2.0.1/dbs/initora11.ora 
ora11.__db_cache_size=163577856
ora11.__java_pool_size=4194304
ora11.__large_pool_size=4194304
ora11.__oracle_base='/home/oracle/app'#ORACLE_BASE set from environment
ora11.__pga_aggregate_target=104857600
ora11.__sga_target=306184192
ora11.__shared_io_pool_size=0
ora11.__shared_pool_size=125829120
ora11.__streams_pool_size=0
*.audit_file_dest='/home/oracle/app/admin/ora11/adump'
*.audit_trail='db'
*.compatible='11.2.0.0.0'
*.control_files='/home/oracle/app/oradata/ora11/control01.ctl','/home/oracle/app/flash_recovery_area/ora11/control02.ctl'
*.db_block_size=8192
*.db_domain='us.oracle.com'
*.db_name='ora11'
*.db_recovery_file_dest='/home/oracle/app/flash_recovery_area'
*.db_recovery_file_dest_size=5218762752
*.diagnostic_dest='/home/oracle/app'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=ora11XDB)'
*.log_archive_dest_1='location=/home/oracle/archivelog'
*.open_cursors=300
*.pga_aggregate_target=101711872
*.processes=150
*.remote_login_passwordfile='EXCLUSIVE'
*.sga_target=306184192
*.undo_tablespace='UNDOTBS1'
将备库启动到nomount状态
[oracle@oracle11g-std ~]$ sqlplus '/as sysdba'


SQL*Plus: Release 11.2.0.1.0 Production on Sat Apr 28 00:25:49 2012


Copyright (c) 1982, 2009, Oracle.  All rights reserved.


Connected to an idle instance.


SQL> startup nomount pfile='/home/oracle/app/product/11.2.0.1/dbs/initora11.ora';
ORA-01261: Parameter db_recovery_file_dest destination string cannot be translated
ORA-01262: Stat failed on a file destination directory
Linux-x86_64 Error: 2: No such file or directory
删除上面的参数
SQL> startup nomount pfile='/home/oracle/app/product/11.2.0.1/dbs/initora11.ora';
ORA-09925: Unable to create audit trail file
Linux-x86_64 Error: 2: No such file or directory
Additional information: 9925
接着删除
但是在删除之后还是出现上面的错误说是无法创建audit文件,这个就郁闷了,但是此时oracle已经启动了nomount状态可以看到进程已经存在了
那是为什么那???经查发现audit会在默认位置创建文件,但是我没有那个路径文件,导致出错,创建就可以了
When connected to the database, may you check the parameter "audit_file_dest":

show parameter audit

Then, check if this directory exists or if the Unix right are corrects on it.

If you cannot logon into the database may you check for the following directories:

$ORACLE_BASE/admin/ORACLE_SID/adump
$ORACLE_HOME/rdbms/audit

These are the default value for this parameter.


修改备库参数
SQL> alter system set log_archive_dest_2='service=ora11 valid_for=(online_logfiles,primary_roles) db_unique_name=ora11';




System altered.




SQL> alter system set fal_client=ora11standby;




System altered.




SQL> alter system set fal_server=ora11;




System altered.




SQL> alter system set log_archive_config='dg_config=(ora11standby,ora11)';




System altered.


SQL> create spfile from pfile;




File created.




nomount结束需要把数据库启动到mount状态进行恢复,而此时还没有控制文件,因此需要生成standby 的控制文件
生成备库的控制文件


[oracle@oracle11g-std rdbms]$ rman target /




Recovery Manager: Release 11.2.0.1.0 - Production on Sat Apr 28 01:19:05 2012




Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.




connected to target database: ORA11 (not mounted)




RMAN> restore standby controlfile from '/home/oracle/rman/stanby.ctl';




Starting restore at 28-APR-12
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=19 device type=DISK




RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of restore command at 04/28/2012 01:19:49
ORA-19504: failed to create file "/home/oracle/app/oradata/ora11/control01.ctl"
ORA-27040: file create error, unable to create file
Linux-x86_64 Error: 2: No such file or directory
ORA-19600: input file is control file  (/home/oracle/rman/stanby.ctl)
ORA-19601: output file is control file  (/home/oracle/app/oradata/ora11/control01.ctl)




RMAN> restore standby controlfile from '/home/oracle/rman/stanby.ctl';




Starting restore at 28-APR-12
using channel ORA_DISK_1




RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of restore command at 04/28/2012 01:21:53
ORA-19504: failed to create file "/home/oracle/app/flash_recovery_area/ora11/control02.ctl"
ORA-27040: file create error, unable to create file
Linux-x86_64 Error: 2: No such file or directory
ORA-19600: input file is control file  (/home/oracle/app/oradata/ora11/control01.ctl)
ORA-19601: output file is control file  (/home/oracle/app/flash_recovery_area/ora11/control02.ctl)




RMAN> restore standby controlfile from '/home/oracle/rman/stanby.ctl';




Starting restore at 28-APR-12
using channel ORA_DISK_1




channel ORA_DISK_1: copied control file copy
output file name=/home/oracle/app/oradata/ora11/control01.ctl
output file name=/home/oracle/app/flash_recovery_area/ora11/control02.ctl
Finished restore at 28-APR-12




RMAN> exit








Recovery Manager complete.
[oracle@oracle11g-std rdbms]$ sqlplus '/as sysdba'




SQL*Plus: Release 11.2.0.1.0 Production on Sat Apr 28 01:22:36 2012




Copyright (c) 1982, 2009, Oracle.  All rights reserved.








Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options




SQL> alter database mount standby database;




Database altered.




SQL> 


恢复备库数据库
rman>restore database;
开启备库的实时应用
SQL> alter database recover managed standby database using current logfile disconnect;
alter database recover managed standby database using current logfile disconnect
*
ERROR at line 1:
ORA-38500: USING CURRENT LOGFILE option not available without standby redo logs


备库没有添加standby redo log file。但是主库采用的是:lgwr async传送的日志。当备库的RFS进程接收到日志后,发现备库没有standby redo log的时候,备库会自动用ARCH将其写入归档文件。
在主库也添加一下standby redo log,以备切换。
就是说要在备库也加上standby redo log file才能使用 using current logfile disconnect;


在standby库没有standby logfile,在maxmize pretection,maxmize availability中必须
要有standby logfile,为了避免数据的损失最少,maxmize performance 也最好创建standby logfile,考虑角色切换
primary库也要创建standby logfile,
standby logfile创建的要求, 与primary的redo logfile的大小相同,个数要至少多一个


SQL> select OPEN_MODE ,PROTECTION_MODE from v$database;




OPEN_MODE            PROTECTION_MODE
-------------------- --------------------
MOUNTED              MAXIMUM PERFORMANCE


那就创建standby log file


SQL> select member from v$logfile;




MEMBER
--------------------------------------------------------------------------------
/home/oracle/app/oradata/ora11/redo01.log
/home/oracle/app/oradata/ora11/redo02.log
/home/oracle/app/oradata/ora11/redo03.log




SQL> alter database add standby logfile group 4 '/home/oracle/app/oradata/ora11/stdredo01.log' size 10m;




Database altered.




SQL> alter database add standby logfile group 5 '/home/oracle/app/oradata/ora11/stdredo02.log' size 10m;




Database altered.


SQL> alter database  recover managed standby database using current logfile disconnect;




Database altered.



primary:
SQL> select max(sequence#) from v$log;


MAX(SEQUENCE#)
--------------
            77


备库:
SQL> select max(sequence#) from v$log;


MAX(SEQUENCE#)
--------------
            77
主库,切换一个归档:


SQL> alter system switch logfile;


System altered.
SQL> select max(sequence#) from v$log;


MAX(SEQUENCE#)
--------------
            78


SQL> 


备库:
SQL> select max(sequence#) from v$log;


MAX(SEQUENCE#)
--------------
            78


到此物理standby搭建完成。

因为是11g可以以只读的方式打开数据库:
SQL> alter database recover managed standby database cancel;


Database altered.


SQL> alter database open read only;


Database altered.


SQL> alter database recover managed standby database using current logfile disconnect;


Database altered.


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值