使用RMAN备份集搭建OracleDataguardStepbyStep(二)

5、网络配置和密码文件配置

成都创新互联公司是专业的扶绥网站建设公司,扶绥接单;提供网站设计制作、网站制作,网页设计,网站设计,建网站,PHP网站建设等专业做网站服务;采用PHP框架,可快速的进行扶绥网站开发网页制作和功能扩展;专业做搜索引擎喜爱的网站,专业的做网站团队,希望更多企业前来合作!

 

Primary和Standby端在sys用户管理密码上要求相同,所以在密码文件问题上,直接拷贝命名是支持的。

 

[oracle@SimpleLinux oracle]$ cd $ORACLE_HOME/dbs

[oracle@SimpleLinux dbs]$ ls -l

total 9552

-rw-rw----. 1 oracle oinstall   1544 May 24 21:12 hc_ora11g.dat

-rw-rw----. 1 oracle oinstall   1544 May 24 21:20 hc_ora11gsy.dat

-rw-r--r--. 1 oracle oinstall   2851 May 15 2009 init.ora

-rw-r--r--. 1 oracle oinstall    774 May 24 21:17 initora11g.ora

-rw-r--r--. 1 oracle oinstall    774 May 24 21:18 initora11gsy.ora

-rw-r-----. 1 oracle oinstall     24 Apr 1 12:39 lkORA11G

-rw-r-----. 1 oracle oinstall   1536 Apr 1 12:45 orapwora11g

-rw-r-----. 1 oracle oinstall 9748480 May 24 20:47 snapcf_ora11g.f

-rw-r-----. 1 oracle oinstall   3584 May 24 21:13 spfileora11g.ora

[oracle@SimpleLinux dbs]$ cp orapwora11g orapwora11gsy

 

Linux环境下,密码文件自动寻找规则为在$ORACLE_HOME/dbs目录中的orapw文件。

Oracle NET涉及到tnsnames.ora文件和listener.ora两个文件。tnsnames.ora负责提供链接本地名,而listener.ora提供监听器静态注册参数。

 

[oracle@SimpleLinux 2014_05_24]$ cd /u01/app/oracle/network/admin/

[oracle@SimpleLinux admin]$ ls -l

total 20

-rw-r--r--. 1 oracle oinstall 345 May 24 22:50 listener.ora

-rw-r--r--. 1 oracle oinstall 345 Apr 1 13:10 listener.ora.bk

drwxr-xr-x. 2 oracle oinstall 4096 Apr 1 12:27 samples

-rw-r--r--. 1 oracle oinstall 381 Dec 17 2012 shrept.lst

-rw-r--r--. 1 oracle oinstall 502 May 24 22:49 tnsnames.ora

 

两个文件上分别配置好ora11g和ora11gsy信息。

 

[oracle@SimpleLinux admin]$ cat tnsnames.ora

# tnsnames.ora Network Configuration File: /u01/app/oracle/network/admin/tnsnames.ora

# Generated by Oracle configuration tools.

 

ORA11GSY =

 (DESCRIPTION =

   (ADDRESS_LIST =

     (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.137.88)(PORT = 1521))

   )

   (CONNECT_DATA =

     (SERVICE_NAME = ora11gsy)

   )

 )

 

ORA11G =

 (DESCRIPTION =

   (ADDRESS_LIST =

     (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.137.88)(PORT = 1521))

   )

   (CONNECT_DATA =

     (SERVICE_NAME = ora11g)

   )

 )

 

[oracle@SimpleLinux admin]$ cat listener.ora

# listener.ora Network Configuration File: /u01/app/oracle/network/admin/listener.ora

# Generated by Oracle configuration tools.

 

LISTENER =

 (DESCRIPTION_LIST =

   (DESCRIPTION =

     (ADDRESS = (PROTOCOL = TCP)(HOST = SimpleLinux)(PORT = 1521))

     (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))

   )

 )

 

SID_LIST_LISTENER =

 (SID_LIST =

   (SID_DESC =

     (SID_NAME = ora11g)

     (ORACLE_HOME = /u01/app/oracle)

     (PROGRAM = extproc)

     (GLOBAL_DBNAME = ora11g)

   ) 

 

   (SID_DESC =

     (SID_NAME = ora11gsy)

     (ORACLE_HOME = /u01/app/oracle)

     (GLOBAL_DBNAME = ora11gsy)

   )

 )

 

 

ADR_BASE_LISTENER = /u01/app

 

监听器重新启动。

 

[oracle@SimpleLinux admin]$ lsnrctl stop

 

LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 24-MAY-2014 22:52:14

 

Copyright (c) 1991, 2013, Oracle. All rights reserved.

 

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=SimpleLinux)(PORT=1521)))

The command completed successfully

[oracle@SimpleLinux admin]$ lsnrctl start

 

LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 24-MAY-2014 22:52:23

(篇幅原因,有省略……)

 (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=SimpleLinux)(PORT=1521)))

 (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))

Services Summary...

Service "ora11g" has 1 instance(s).

 Instance "ora11g", status UNKNOWN, has 1 handler(s) for this service...

Service "ora11gsy" has 1 instance(s).

 Instance "ora11gsy", status UNKNOWN, has 1 handler(s) for this service...

The command completed successfully

 

下面就可以进行恢复动作了。

 

6、restore backup set

 

启动rman进行还原动作。

 

--连入到ora11gsy中

[oracle@SimpleLinux ~]$ export ORACLE_SID=ora11gsy

[oracle@SimpleLinux ~]$ rman target /

 

Recovery Manager: Release 11.2.0.4.0 - Production on Sat May 24 21:32:23 2014

 

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

 

connected to target database (not started)

 

启动到nomount状态,设置dbid值。这个取值和Primary数据库的相同。

 

RMAN> startup nomount

Oracle instance started

 

Total System Global Area    372449280 bytes

 

Fixed Size                    1364732 bytes

Variable Size               301993220 bytes

Database Buffers             62914560 bytes

Redo Buffers                  6176768 bytes

 

 

RMAN> set dbid=4239941846

executing command: SET DBID

 

从备份集合直接恢复控制文件。

 

RMAN> restore standby controlfile from '/standbybackup/o1_mf_ncnnf_TAG20140524T204716_9r156r7j_.bkp';

 

Starting restore at 24-MAY-14

using target database control file instead of recovery catalog

allocated channel: ORA_DISK_1

channel ORA_DISK_1: SID=1 device type=DISK

 

channel ORA_DISK_1: restoring control file

channel ORA_DISK_1: restore complete, elapsed time: 00:00:07

output file name=/u01/app/oradata/ORA11GSY/controlfile/o1_mf_9r18tmv6_.ctl

output file name=/u01/app/fast_recovery_area/ORA11GSY/controlfile/o1_mf_9r18tpkf_.ctl

Finished restore at 24-MAY-14

 

注意两个现象:首先我们是以standby controlfile的方式,直接从文件系统中读取备份。第二就是我们并没有在initora11gsy.ora中配置control_files参数,Oracle直接按照OMF法则创建了控制文件两个镜像。第三,这个数据没有写入到spfile/pfile中,日后给系统带来了些麻烦。

启动到mount状态。

 

 

RMAN> sql 'alter database mount standby database';

 

sql statement: alter database mount standby database

released channel: ORA_DISK_1

 

最后是比较麻烦的步骤,备份集合中是在Primary的文件路径,没有进行也没有途径进行remap动作。所以,Oracle这里面需要手工的对文件进行一系列的set newname动作。

 

RMAN> run {

2> ALLOCATE CHANNEL c1 DEVICE TYPE DISK ;

3> set newname for datafile 1 to '/u01/app/oradata/ORA11GSY/datafile/o1_mf_system_9mnjrzty_.dbf';

4> set newname for datafile 2 to '/u01/app/oradata/ORA11GSY/datafile/o1_mf_sysaux_9mnjs04h_.dbf';

5> set newname for datafile 3 to '/u01/app/oradata/ORA11GSY/datafile/o1_mf_undotbs1_9mnjs068_.dbf';

6> set newname for datafile 4 to '/u01/app/oradata/ORA11GSY/datafile/o1_mf_users_9mnjs074_.dbf';

7>

8> }

 

allocated channel: c1

channel c1: SID=20 device type=DISK

 

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

released channel: c1

 

如果Primary和Standby目录结构完全相同,就不需要这个步骤了。之后,如果是10g之前版本,就必须将拷贝过的备份集合放在和原来相同的目录结构中。如果是10g之后,就可以使用catalog backuppiece人工的加载备份集合。

 

RMAN> catalog backuppiece '/standbybackup/o1_mf_nnndf_TAG20140524T204320_9r14z9hn_.bkp';

 

cataloged backup piece

backup piece handle=/standbybackup/o1_mf_nnndf_TAG20140524T204320_9r14z9hn_.bkp RECID=3 STAMP=848442509

 

直接恢复数据库文件。

 

 

RMAN> run {

2> restore database;

3> switch datafile all;

4> }

 

Starting restore at 24-MAY-14

using channel ORA_DISK_1

 

(篇幅原因,有省略……)

channel ORA_DISK_1: restoring datafile 00002 to /u01/app/oradata/ORA11GSY/datafile/o1_mf_sysaux_9mnjs04h_.dbf

channel ORA_DISK_1: restoring datafile 00003 to /u01/app/oradata/ORA11GSY/datafile/o1_mf_undotbs1_9mnjs068_.dbf

channel ORA_DISK_1: reading from backup piece /standbybackup/o1_mf_nnndf_TAG20140524T204320_9r14z9hn_.bkp

 

channel ORA_DISK_1: piece handle=/standbybackup/o1_mf_nnndf_TAG20140524T204320_9r14z9hn_.bkp tag=TAG20140524T204320

channel ORA_DISK_1: restored backup piece 1

channel ORA_DISK_1: restore complete, elapsed time: 00:08:25

Finished restore at 24-MAY-14

 

recover数据库,完成恢复过程。

 

RMAN> restore database;     

 

Starting restore at 24-MAY-14

using channel ORA_DISK_1

 

skipping datafile 1; already restored to file /u01/app/oradata/ORA11GSY/datafile/o1_mf_system_9r1cgl8x_.dbf

skipping datafile 2; already restored to file /u01/app/oradata/ORA11GSY/datafile/o1_mf_sysaux_9r1cgld1_.dbf

skipping datafile 3; already restored to file /u01/app/oradata/ORA11GSY/datafile/o1_mf_undotbs1_9r1cglfr_.dbf

datafile 4 is already restored to file /u01/app/oradata/ORA11GSY/datafile/o1_mf_users_9r1c6gb9_.dbf

restore not done; all files read only, offline, or already restored

Finished restore at 24-MAY-14

 

7、standby工作配置

 

Standby恢复完成之后,还要创建专门的standby redo log作为恢复过程中使用。

 

SQL> alter database add standby logfile size 50m;

Database altered

 

SQL> alter database add standby logfile size 50m;

Database altered

 

 

SQL> select group#, sequence#, dbid from v$standby_log;

   GROUP# SEQUENCE# DBID

---------- ---------- ----------------------------------------

        4         0 UNASSIGNED

        5         0 UNASSIGNED

 

启动standby端recover动作。

 

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

 

Database altered.

 

 

SQL> select name, OPEN_MODE, database_role from v$database;

 

NAME     OPEN_MODE           DATABASE_ROLE

--------- -------------------- ----------------

ORA11G   MOUNTED             PHYSICAL STANDBY

 

Primary全过程始终处在mount状态,没有redo log生成。启动Primary到mount状态。

 

[oracle@SimpleLinux ~]$ sqlplus /nolog

 

SQL*Plus: Release 11.2.0.4.0 Production on Sat May 24 23:06:49 2014

 

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

 

SQL> conn / as sysdba

Connected.

SQL> alter database open;

Database altered.

 

Primary端传输通道是否正常查看v$archived_dest_status。

 

SQL> col dest_name for a20;

SQL> select dest_id, dest_name, status, type, database_mode, recovery_mode, DESTINATION from v$archive_dest_status where dest_id<3;

 

  DEST_ID DEST_NAME           STATUS   TYPE          DATABASE_MODE  RECOVERY_MODE          DESTINATION

---------- -------------------- --------- -------------- --------------- ----------------------- --------------------------------------------------------------------------------

        1 LOG_ARCHIVE_DEST_1  VALID    LOCAL         OPEN           IDLE                   /u01/app/oracle/dbs/arch

        2 LOG_ARCHIVE_DEST_2  VALID    PHYSICAL      MOUNTED-STANDBY MANAGED REAL TIME APPLY ora11gsy

 

日志情况,特别是日志应用情况。

 

SQL> select recid,name, sequence#, STANDBY_DEST, ARCHIVED, APPLIED from v$archived_log;

 

    RECID NAME                                                                             SEQUENCE# STANDBY_DEST ARCHIVED APPLIED

---------- -------------------------------------------------------------------------------- ---------- ------------ -------- ---------

        1 /u01/app/fast_recovery_area/ORA11G/archivelog/2014_05_24/o1_mf_1_6_9r1fdo70_.arc         6 NO          YES     NO

        2 /u01/app/fast_recovery_area/ORA11G/archivelog/2014_05_24/o1_mf_1_7_9r1fdvt1_.arc         7 NO          YES     NO

        3 ora11gsy                                                                                 6 YES         YES     YES

        4 ora11gsy                                                                                 7 YES         YES     YES

        5 /u01/app/fast_recovery_area/ORA11G/archivelog/2014_05_24/o1_mf_1_8_9r1fmzv9_.arc         8 NO          YES     NO

        6 ora11gsy                                                                                 8 YES         YES     YES

 

6 rows selected

 

sequence#=6-8的数据,已经顺利传输到ora11gsy端,并且应用apply提示标志已经设置为YES。在standby端,我们也可以查看应用情况。

 

SQL> conn sys/oracle@ora11gsy as sysdba

Connected to Oracle Database 11g Enterprise Edition Release 11.2.0.4.0

Connected as SYS

 

SQL> select recid,name, sequence#, STANDBY_DEST, ARCHIVED, APPLIED from v$archived_log;

 

    RECID NAME                                                                             SEQUENCE# STANDBY_DEST ARCHIVED APPLIED

---------- -------------------------------------------------------------------------------- ---------- ------------ -------- ---------

        1 /u01/app/fast_recovery_area/ORA11GSY/archivelog/2014_05_24/o1_mf_1_6_9r1ff3t6_.a         6 NO          YES     YES

        2 /u01/app/fast_recovery_area/ORA11GSY/archivelog/2014_05_24/o1_mf_1_7_9r1ff3dn_.a         7 NO          YES     YES

        3 /u01/app/fast_recovery_area/ORA11GSY/archivelog/2014_05_24/o1_mf_1_8_9r1fn28z_.a         8 NO          YES     YES

 

 

SQL> select group#, dbid, sequence# from v$standby_log;

 

   GROUP# DBID                                     SEQUENCE#

---------- ---------------------------------------- ----------

        4 4239941846                                       9

        5 UNASSIGNED                                       0

 

应用成功!但这并不是配置的全部,一些问题在安装过程中埋下了问题点,一些补充配置也需要后续完成,才能作为一个健全DG环境。


当前名称:使用RMAN备份集搭建OracleDataguardStepbyStep(二)
链接地址:http://hbruida.cn/article/gidddi.html