Data Guard——使用 RMAN 创建单实例物理(physical) standby 数据库
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 =