Data Guard——使用 RMAN 创建单实例物理(physical) standby 数据库

来源:互联网 发布:js生态圈 编辑:程序博客网 时间:2024/06/02 22:51
Primary Database:
192.168.8.251   centos10g.oracle.com  centos10g


Standby Database:
192.168.8.252   centos10g2.oracle.com  centos10g2


1、在 primary database 上启用 force logging
[oracle@centos10g ~]$ sqlplus / as sysdba
SQL> alter database force logging;
Database altered.


2、在 primary database 上启用 archivelog 模式
[oracle@centos10g ~]$ mkdir /u01/arch


SQL> alter system set log_archive_dest_1='location=/u01/arch' scope=spfile;
System altered.


SQL> shutdown immediate;


SQL> startup mount;


SQL> alter database archivelog;


SQL> archive log list
Database log mode              Archive Mode
Automatic archival             Enabled
Archive destination            /u01/arch
Oldest online log sequence     10
Next log sequence to archive   12
Current log sequence           12


3、创建 NFS 共享目录,用来存放 primary 的备份集
[root@centos10g ~]# chown -R oracle:oinstall /backup
[root@centos10g ~]# chmod -R 777 /backup
[root@centos10g ~]# vi /etc/exports
/backup centos10g.oracle.com(rw,sync) centos10g2.oracle.com(rw,sync)
[root@centos10g ~]# service nfs start
Starting NFS services:  [  OK  ]
Starting NFS quotas: [  OK  ]
Starting NFS daemon: [  OK  ]
Starting NFS mountd: [  OK  ]
--------------------------------------------------------------------
-- 在 standby 主机上挂载 primary 主机上的nfs共享
[root@centos10g2 ~]# chown -R oracle:oinstall /backup
[root@centos10g2 ~]# chmod -R 777 /backup
[root@centos10g2 ~]# mount centos10g.oracle.com:/backup /backup


[root@centos10g2 ~]# df -h /backup
Filesystem            Size  Used Avail Use% Mounted on
centos10g.oracle.com:/backup
                      2.0G   36M  1.9G   2% /backup


4、备份 primary 数据库(full backup)到 nfs 共享


RMAN> run{
2> startup mount;
3> allocate channel c1 type disk;
4> allocate channel c2 type disk;
5> backup format='/backup/%d_%s_%t.bak' database plus archivelog;
6> }


5、在 primary 库上备份 standby 的控制文件


RMAN> copy current controlfile for standby to '/backup/control01.ctl';


6、配置 primary 和 standby 的监听和 TNS


[oracle@centos10g2 ~]$ more $ORACLE_HOME/network/admin/tnsnames.ora
BEIJING =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = centos10g)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = prod)
    )
  )


TIANJIN =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = centos10g2)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = standby)
    )
  )


  [oracle@centos10g ~]$ more $ORACLE_HOME/network/admin/tnsnames.ora


  BEIJING =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = centos10g)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = prod)
    )
  )


TIANJIN =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = centos10g2)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = standby)
    )
  )




7、准备standby库的pfile
在primary库创建pfile,然后拷贝至备库的$ORACLE_HOME/dbs 路径下,并添加如下参数
*.db_unique_name=tianjin
*.log_archive_config='dg_config=(beijing,tianjin)'
*.log_archive_dest_1='location=/u01/arch valid_for=(online_logfiles,primary_role) db_unique_name=tianjin'
*.log_archive_dest_2='service=beijing valid_for=(online_logfiles,primary_role) db_unique_name=beijing'


*.fal_server=beijing
*.fal_client=tianjin
*.db_file_name_convert='/u01/app/oracle/oradata/prod'.'/u01/app/oracle/oradata/prod'
*.log_file_name_convert='/u01/app/oracle/oradata/prod'.'/u01/app/oracle/oradata/prod'
*.standby_file_management=auto


8、在standby库主机上创建初始化参数中涉及的目录
[oracle@centos10g2 dbs]$ mkdir -p /u01/app/oracle/admin/prod/adump
[oracle@centos10g2 dbs]$ mkdir -p /u01/app/oracle/admin/prod/bdump
[oracle@centos10g2 dbs]$ mkdir -p /u01/app/oracle/admin/prod/cdump
[oracle@centos10g2 dbs]$ mkdir -p /u01/app/oracle/admin/prod/udump
[oracle@centos10g2 dbs]$ mksdir -p /u01/app/oracle/oradata/prod/
[oracle@centos10g2 dbs]$ mkdir -p /u01/app/oracle/flash_recovery_area


9、利用 primary 库的备份集恢复 standby 库
9.1 在 standby 库中恢复 primary 库的 controlfile 
[oracle@centos10g2 backup]$ cp control01.ctl /u01/app/oracle/oradata/prod/control01.ctl
[oracle@centos10g2 backup]$ cp control01.ctl /u01/app/oracle/oradata/prod/control02.ctl
[oracle@centos10g2 backup]$ cp control01.ctl /u01/app/oracle/oradata/prod/control03.ctl
[oracle@centos10g2 ~]$ rman target /
RMAN> startup mount
connected to target database (not started)
Oracle instance started
Total System Global Area     285212672 bytes
Fixed Size                     1218992 bytes
Variable Size                100664912 bytes
Database Buffers             180355072 bytes
Redo Buffers                   2973696 bytes


9.2 restore database




RMAN> restore database;


Starting restore at 23-SEP-12
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=156 devtype=DISK


channel ORA_DISK_1: starting datafile backupset restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
restoring datafile 00002 to .'/u01/app/oracle/oradata/prod'/undotbs01.dbf
restoring datafile 00003 to .'/u01/app/oracle/oradata/prod'/sysaux01.dbf
restoring datafile 00005 to .'/u01/app/oracle/oradata/prod'/example01.dbf
channel ORA_DISK_1: reading from backup piece /backup/PROD_20_794779912.bak
ORA-19870: error reading backup piece /backup/PROD_20_794779912.bak
ORA-19505: failed to identify file "/backup/PROD_20_794779912.bak"
ORA-27054: NFS file system where the file is created or resides is not mounted with correct options
Additional information: 3
channel ORA_DISK_1: starting datafile backupset restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
restoring datafile 00001 to .'/u01/app/oracle/oradata/prod'/system01.dbf
restoring datafile 00004 to .'/u01/app/oracle/oradata/prod'/users01.dbf
channel ORA_DISK_1: reading from backup piece /backup/PROD_19_794779912.bak
ORA-19870: error reading backup piece /backup/PROD_19_794779912.bak
ORA-19505: failed to identify file "/backup/PROD_19_794779912.bak"
ORA-27054: NFS file system where the file is created or resides is not mounted with correct options
Additional information: 3


造成问题的原因可能是oracle去考虑nfs的问题. 总之需要执行命令。
Alter system set events '10298 trace name context forever,level 32'
或执行如下操作

[root@centos10g2 ~]# mount -t nfs -o rw,bg,hard,nointr,rsize=32768,wsize=32768,tcp,vers=3,timeo=600,actimeo=0  centos10g.oracle.com:/backup /backup



转载请注明作者、出处及原文链接,否则拒绝转载:

本文来源:http://blog.csdn.net/xiangsir/article/details/8606594

原创粉丝点击