oracle 单实例+文件管理 +dataguard ---------------------》》 oracle rac+asm+ dataguard

环境说明:
单实例:
 操作系统:RHEL4.8 x86_64
 oracle:10.2.0.4
 db_unique_name:primary
 ip:192.168.5.237
data guard:
 操作系统:RHEL4.8 x86_64
 保护模式:最大可用模式 实时应用
 ip:192.168.12.18
 db_unique_name:standby
rac:
 操作系统:RHEL5.4 x86_64
 ip:
  192.168.5.235   zhh1
  192.168.5.233   zhh1-vip
  10.0.0.100      zhh1-priv

  192.168.5.236   zhh2
  192.168.5.234   zhh2-vip
  10.0.0.101      zhh2-priv
db_name:rac


目的:
通过rman备份单实例数据库,然后恢复到rac上,然后搭建出rac环境的standby;实现单实例数据库有两个最大可用模式的standby:一个是单实例,一个是rac环境。然后通过rac进行primary和standby切换,把单实例转为rac;最终环境转为一个rac,两个最大可用模式单实例standby。

一、查看环境:
主库
SQL> select NAME,OPEN_MODE,PROTECTION_MODE,PROTECTION_LEVEL,DATABASE_ROLE,LOG_MODE,FORCE_LOGGING from v$database;

NAME      OPEN_MODE  PROTECTION_MODE      PROTECTION_LEVEL     DATABASE_ROLE    LOG_MODE     FOR
--------- ---------- -------------------- -------------------- ---------------- ------------ ---
RAC       READ WRITE MAXIMUM AVAILABILITY MAXIMUM AVAILABILITY PRIMARY          ARCHIVELOG   YES

SQL> archive log list
Database log mode              Archive Mode
Automatic archival             Enabled
Archive destination            /usr/oracle/oradata/rac/archive
Oldest online log sequence     16
Next log sequence to archive   18
Current log sequence           18

SQL> select recovery_mode from v$archive_dest_status where dest_id=2;

RECOVERY_MODE
-----------------------
MANAGED REAL TIME APPLY

tnsnames中如下:
primary =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.5.237)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = rac)
    )
  )

standby =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.12.18)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = rac)
    )
  )

standby库
SQL>  select NAME,OPEN_MODE,PROTECTION_MODE,PROTECTION_LEVEL,DATABASE_ROLE,LOG_MODE,FORCE_LOGGING from v$database;

NAME      OPEN_MODE  PROTECTION_MODE      PROTECTION_LEVEL     DATABASE_ROLE    LOG_MODE     FOR
--------- ---------- -------------------- -------------------- ---------------- ------------ ---
RAC       MOUNTED    MAXIMUM AVAILABILITY MAXIMUM AVAILABILITY PHYSICAL STANDBY ARCHIVELOG   YES

SQL> select * from v$logfile;

    GROUP# STATUS  TYPE    MEMBER                                   IS_
---------- ------- ------- ---------------------------------------- ---
         3 STALE   ONLINE  /usr/oracle/oradata/rac/redo03.log       NO
         2         ONLINE  /usr/oracle/oradata/rac/redo02.log       NO
         1         ONLINE  /usr/oracle/oradata/rac/redo01.log       NO
         4         STANDBY /usr/oracle/oradata/rac/redo04.log       NO
         5         STANDBY /usr/oracle/oradata/rac/redo05.log       NO
         6         STANDBY /usr/oracle/oradata/rac/redo06.log       NO
         7         STANDBY /usr/oracle/oradata/rac/redo07.log       NO

SQL> select sequence#,applied from v$archived_log;

 SEQUENCE# APP
---------- ---
         5 YES
         6 YES
         7 YES
         8 YES
         9 YES
        10 YES
        11 YES
        12 YES
        13 YES
        14 YES
        15 YES

 SEQUENCE# APP
---------- ---
        16 YES
        17 YES

13 rows selected.

SQL> select PROCESS,STATUS,GROUP#,THREAD#,SEQUENCE# from v$managed_standby;

PROCESS   STATUS       GROUP#                                      THREAD#  SEQUENCE#
--------- ------------ ---------------------------------------- ---------- ----------
ARCH      CONNECTED    N/A                                               0          0
ARCH      CLOSING      5                                                 1         17
RFS       IDLE         3                                                 1         18
RFS       IDLE         N/A                                               0          0
MRP0      APPLYING_LOG N/A                                               1         18
RFS       IDLE         N/A                                               0          0

6 rows selected.

二、主库增加undotbs2和thread2 logfile

1、增加undotbs2
SQL> show parameter standby_file

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
standby_file_management              string      AUTO

SQL> select * from v$tablespace;

       TS# NAME                           INC BIG FLA ENC
---------- ------------------------------ --- --- --- ---
         0 SYSTEM                         YES NO  YES
         1 UNDOTBS1                       YES NO  YES
         2 SYSAUX                         YES NO  YES
         4 USERS                          YES NO  YES
         3 TEMP                           NO  NO  YES
         6 EXAMPLE                        YES NO  YES
         7 ZHH                            YES NO  YES

7 rows selected.

SQL> create undo tablespace undotbs2 datafile '/usr/oracle/oradata/rac/undotbs02.dbf' size 100M;

Tablespace created.

SQL> select * from v$tablespace;

       TS# NAME                           INC BIG FLA ENC
---------- ------------------------------ --- --- --- ---
         0 SYSTEM                         YES NO  YES
         1 UNDOTBS1                       YES NO  YES
         2 SYSAUX                         YES NO  YES
         4 USERS                          YES NO  YES
         3 TEMP                           NO  NO  YES
         6 EXAMPLE                        YES NO  YES
         7 ZHH                            YES NO  YES
         5 UNDOTBS2                       YES NO  YES

8 rows selected.

检查standby库是否同步创建了undotbs2表空间
SQL> select * from v$tablespace;

       TS# NAME                           INC BIG FLA ENC
---------- ------------------------------ --- --- --- ---
         0 SYSTEM                         YES NO  YES
         1 UNDOTBS1                       YES NO  YES
         2 SYSAUX                         YES NO  YES
         4 USERS                          YES NO  YES
         3 TEMP                           NO  NO  YES
         6 EXAMPLE                        YES NO  YES
         7 ZHH                            YES NO  YES
         5 UNDOTBS2                       YES NO  YES

8 rows selected.

2、增加thread2 logfile
由于standby是最大可用,并且是实时应用,配置了standby redo log,因此对primary库redo log进行增删改时,standby库需要同步进行相应操作。
primary库
SQL>  select * from v$logfile;

    GROUP# STATUS  TYPE    MEMBER                                   IS_
---------- ------- ------- ---------------------------------------- ---
         3         ONLINE  /usr/oracle/oradata/rac/redo03.log       NO
         2         ONLINE  /usr/oracle/oradata/rac/redo02.log       NO
         1         ONLINE  /usr/oracle/oradata/rac/redo01.log       NO

SQL>  select * from v$log;

    GROUP#    THREAD#  SEQUENCE#      BYTES    MEMBERS ARC STATUS           FIRST_CHANGE# FIRST_TIM
---------- ---------- ---------- ---------- ---------- --- ---------------- ------------- ---------
         1          1         16   52428800          1 YES INACTIVE                738882 15-MAR-11
         2          1         17   52428800          1 YES INACTIVE                738968 15-MAR-11
         3          1         18   52428800          1 NO  CURRENT                 738969 15-MAR-11


SQL> alter database add logfile thread 2 group 4 '/usr/oracle/oradata/rac/redo04.log' size 52428800;

Database altered.

SQL> alter database add logfile thread 2 group 5 '/usr/oracle/oradata/rac/redo05.log' size 52428800;

Database altered.

SQL> alter database add logfile thread 2 group 6 '/usr/oracle/oradata/rac/redo06.log' size 52428800;

Database altered.

SQL> select * from v$log;

    GROUP#    THREAD#  SEQUENCE#      BYTES    MEMBERS ARC STATUS           FIRST_CHANGE# FIRST_TIM
---------- ---------- ---------- ---------- ---------- --- ---------------- ------------- ---------
         1          1         16   52428800          1 YES INACTIVE                738882 15-MAR-11
         2          1         17   52428800          1 YES INACTIVE                738968 15-MAR-11
         3          1         18   52428800          1 NO  CURRENT                 738969 15-MAR-11
         4          2          0   52428800          1 YES UNUSED                       0
         5          2          0   52428800          1 YES UNUSED                       0
         6          2          0   52428800          1 YES UNUSED                       0

6 rows selected.

SQL> select * from v$logfile;

    GROUP# STATUS  TYPE    MEMBER                                   IS_
---------- ------- ------- ---------------------------------------- ---
         3         ONLINE  /usr/oracle/oradata/rac/redo03.log       NO
         2         ONLINE  /usr/oracle/oradata/rac/redo02.log       NO
         1         ONLINE  /usr/oracle/oradata/rac/redo01.log       NO
         4         ONLINE  /usr/oracle/oradata/rac/redo04.log       NO
         5         ONLINE  /usr/oracle/oradata/rac/redo05.log       NO
         6         ONLINE  /usr/oracle/oradata/rac/redo06.log       NO

6 rows selected.

SQL> alter database enable thread 2;

Database altered.

standby库
SQL> select * from v$logfile;

    GROUP# STATUS  TYPE    MEMBER                                   IS_
---------- ------- ------- ---------------------------------------- ---
         3 STALE   ONLINE  /usr/oracle/oradata/rac/redo03.log       NO
         2         ONLINE  /usr/oracle/oradata/rac/redo02.log       NO
         1         ONLINE  /usr/oracle/oradata/rac/redo01.log       NO
         4         STANDBY /usr/oracle/oradata/rac/redo04.log       NO
         5         STANDBY /usr/oracle/oradata/rac/redo05.log       NO
         6         STANDBY /usr/oracle/oradata/rac/redo06.log       NO
         7         STANDBY /usr/oracle/oradata/rac/redo07.log       NO

7 rows selected.

SQL> select * from v$log;

    GROUP#    THREAD#  SEQUENCE#      BYTES    MEMBERS ARC STATUS           FIRST_CHANGE# FIRST_TIM
---------- ---------- ---------- ---------- ---------- --- ---------------- ------------- ---------
         1          1         16   52428800          1 YES CLEARING                738882 15-MAR-11
         3          1         18   52428800          1 YES CLEARING_CURRENT        738969 15-MAR-11
         2          1         18   52428800          1 YES CLEARING                738969 15-MAR-11

SQL> recover managed standby database cancel;
Media recovery complete.
SQL> alter system set standby_file_management=manual;

System altered.

SQL> alter database add logfile thread 2 group 8 '/usr/oracle/oradata/rac/redo08.log' size 52428800;

Database altered.

SQL> alter database add logfile thread 2 group 9 '/usr/oracle/oradata/rac/redo09.log' size 52428800;

Database altered.

SQL> alter database add logfile thread 2 group 10 '/usr/oracle/oradata/rac/redo10.log' size 52428800;

Database altered.

SQL> alter database add standby logfile thread 2 group 11 '/usr/oracle/oradata/rac/redo11.log' size 52428800;

Database altered.

SQL> alter database add standby logfile thread 2 group 12 '/usr/oracle/oradata/rac/redo12.log' size 52428800;

Database altered.

SQL> alter database add standby logfile thread 2 group 13 '/usr/oracle/oradata/rac/redo13.log' size 52428800;

Database altered.

SQL> alter database add standby logfile thread 2 group 14 '/usr/oracle/oradata/rac/redo14.log' size 52428800;

Database altered.

SQL> select * from v$logfile;

    GROUP# STATUS  TYPE    MEMBER                                   IS_
---------- ------- ------- ---------------------------------------- ---
         3 STALE   ONLINE  /usr/oracle/oradata/rac/redo03.log       NO
         2         ONLINE  /usr/oracle/oradata/rac/redo02.log       NO
         1         ONLINE  /usr/oracle/oradata/rac/redo01.log       NO
         4         STANDBY /usr/oracle/oradata/rac/redo04.log       NO
         5         STANDBY /usr/oracle/oradata/rac/redo05.log       NO
         6         STANDBY /usr/oracle/oradata/rac/redo06.log       NO
         7         STANDBY /usr/oracle/oradata/rac/redo07.log       NO
         8         ONLINE  /usr/oracle/oradata/rac/redo08.log       NO
         9         ONLINE  /usr/oracle/oradata/rac/redo09.log       NO
        10         ONLINE  /usr/oracle/oradata/rac/redo10.log       NO
        11         STANDBY /usr/oracle/oradata/rac/redo11.log       NO

    GROUP# STATUS  TYPE    MEMBER                                   IS_
---------- ------- ------- ---------------------------------------- ---
        12         STANDBY /usr/oracle/oradata/rac/redo12.log       NO
        13         STANDBY /usr/oracle/oradata/rac/redo13.log       NO
        14         STANDBY /usr/oracle/oradata/rac/redo14.log       NO

14 rows selected.

SQL> select * from v$log;

    GROUP#    THREAD#  SEQUENCE#      BYTES    MEMBERS ARC STATUS           FIRST_CHANGE# FIRST_TIM
---------- ---------- ---------- ---------- ---------- --- ---------------- ------------- ---------
         1          1         16   52428800          1 YES CLEARING                738882 15-MAR-11
         2          1         18   52428800          1 YES CLEARING                738969 15-MAR-11
         3          1         18   52428800          1 YES CLEARING_CURRENT        738969 15-MAR-11
         8          2          0   52428800          1 YES UNUSED                       0
         9          2          0   52428800          1 YES UNUSED                       0
        10          2          0   52428800          1 YES UNUSED                       0

6 rows selected.

SQL> alter system set standby_file_management=auto;

System altered.

SQL> recover managed standby database using current logfile disconnect from session;
Media recovery complete.


三、修改primary库配置

修改primary数据库的tnsnames,增加如下:
standby2=
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.5.235)(PORT = 3173))
    )
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SID = rac1)
    )
  )

SQL> show parameter archive

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
archive_lag_target                   integer     0
log_archive_config                   string      dg_config=(primary,standby)
log_archive_dest                     string
log_archive_dest_1                   string      location=/usr/oracle/oradata/r
                                                 ac/archive
log_archive_dest_10                  string
log_archive_dest_2                   string      service=standby  lgwr sync aff
                                                 irm net_timeout=30 db_unique_n
                                                 ame=standby
.....

SQL> alter system set log_archive_dest_2='service=standby lgwr sync affirm net_timeout=30 valid_for=(online_logfile,primary_role) db_unique_name=standby';

System altered.

SQL> alter system set log_archive_dest_state_3=defer;

System altered.

SQL> alter system set log_archive_config='dg_config=(primary,standby,standby2)';

System altered.

SQL> alter system set log_archive_dest_3='service=standby2 lgwr sync affirm net_timeout=30 valid_for=(online_logfile,primary_role) db_unique_name=standby2';

System altered.

SQL> alter system set fal_server='standby,standby2';

System altered.

SQL> alter system set fal_client='primary';

System altered.

SQL> show parameter archive

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
archive_lag_target                   integer     0
log_archive_config                   string      dg_config=(primary,standby,sta
                                                 ndby2)
log_archive_dest                     string
log_archive_dest_1                   string      location=/usr/oracle/oradata/r
                                                 ac/archive
log_archive_dest_10                  string
log_archive_dest_2                   string      service=standby lgwr sync affi
                                                 rm net_timeout=30 valid_for=(o
                                                 nline_logfile,primary_role) db
                                                 _unique_name=standby

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
log_archive_dest_3                   string      service=standby2 lgwr sync aff
                                                 irm net_timeout=30 valid_for=(
                                                 online_logfile,primary_role) d
                                                 b_unique_name=standby2
log_archive_dest_4                   string
log_archive_dest_5                   string
log_archive_dest_6                   string
log_archive_dest_7                   string
log_archive_dest_8                   string
log_archive_dest_9                   string
log_archive_dest_state_1             string      enable

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
log_archive_dest_state_10            string      enable
log_archive_dest_state_2             string      enable
log_archive_dest_state_3             string      DEFER
......


四、rman备份primary库
RMAN>  backup database format '/usr/oracle/backup/full_%U';

Starting backup at 16-MAR-11
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
input datafile fno=00001 name=/usr/oracle/oradata/rac/system01.dbf
input datafile fno=00003 name=/usr/oracle/oradata/rac/sysaux01.dbf
input datafile fno=00005 name=/usr/oracle/oradata/rac/example01.dbf
input datafile fno=00006 name=/usr/oracle/oradata/rac/zhh01.dbf
input datafile fno=00007 name=/usr/oracle/oradata/rac/undotbs02.dbf
input datafile fno=00002 name=/usr/oracle/oradata/rac/undotbs01.dbf
input datafile fno=00004 name=/usr/oracle/oradata/rac/users01.dbf
channel ORA_DISK_1: starting piece 1 at 16-MAR-11
channel ORA_DISK_1: finished piece 1 at 16-MAR-11
piece handle=/usr/oracle/backup/full_09m7cgdr_1_1 tag=TAG20110316T153939 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:25
Finished backup at 16-MAR-11

Starting Control File and SPFILE Autobackup at 16-MAR-11
piece handle=/usr/oracle/backup/ctl_c-2333300477-20110316-05 comment=NONE
Finished Control File and SPFILE Autobackup at 16-MAR-11

RMAN> exit


Recovery Manager complete.

创建pfile,修改后供standby启动使用;同时创建standby的控制文件。
SQL> create pfile='/usr/oracle/backup/initrac1.ora' from spfile;

File created.

SQL> alter database create standby controlfile as '/usr/oracle/backup/control01.ctl';

Database altered.

把备份文件、参数文件、控制文件传输到rac
[oracle@wzlm backup]$ cd /usr/oracle/
[oracle@wzlm oracle]$ scp -r backup/ [email protected]:/usr/oracle
[email protected]'s password:
ctl_c-2333300477-20110316-05                                                                      100% 7072KB   6.9MB/s   00:00   
control01.ctl                                                                                     100% 6992KB   6.8MB/s   00:00   
initrac1.ora                                                                                      100% 1394     1.4KB/s   00:00   
full_09m7cgdr_1_1                                                                                 100%  615MB  29.3MB/s   00:21
 
五、恢复到rac
1、在rac上创建必要目录
操作系统目录:每个节点都要做
[oracle@zhh1 ~]$ cd /usr/oracle/admin/
[oracle@zhh1 admin]$ mkdir rac
[oracle@zhh1 admin]$ cd rac
[oracle@zhh1 rac]$ mkdir  adump  bdump  cdump  dpdump  pfile  udump
asm系统:只需在一个节点上执行
[oracle@zhh1 rac]$ export ORACLE_SID=+ASM1
[oracle@zhh1 rac]$ asmcmd
ASMCMD> ls
DATA/
ASMCMD> cd data
ASMCMD> mkdir rac
ASMCMD> ls
rac/
ASMCMD> cd rac
ASMCMD> mkdir archive
ASMCMD> ls
archive/
ASMCMD> pwd
+data/rac
ASMCMD> cd archive
ASMCMD> pwd
+data/rac/archive

2、编辑参数文件
在传过来的参数文件基础上修改,添加rac特有的参数:
[oracle@zhh1 ~]$ cd /usr/oracle/backup/
[oracle@zhh1 backup]$ vi initrac1.ora
*.audit_file_dest='/usr/oracle/admin/rac/adump'
*.background_dump_dest='/usr/oracle/admin/rac/bdump'
*.compatible='10.2.0.3.0'
*.control_files='+data/rac/control01.ctl'
*.core_dump_dest='/usr/oracle/admin/rac/cdump'
*.db_block_size=8192
*.db_domain=''
*.db_file_multiblock_read_count=16
*.db_name='rac'
*.db_unique_name='standby2'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=racXDB)'
*.job_queue_processes=10
*.log_archive_config='dg_config=(primary,standby,standby2)'
*.log_archive_dest_1='location=+DATA/rac/archive'
*.log_archive_dest_2='service=primary lgwr sync affirm net_timeout=30 valid_for=(online_logfile,primary_role) db_unique_name=primary'
*.log_archive_dest_3='service=standby lgwr sync affirm net_timeout=30 valid_for=(online_logfile,primary_role) db_unique_name=standby'
*.log_archive_format='%t_%s_%r.dbf'
*.log_file_name_convert=('/usr/oracle/oradata/rac/', '+data/rac/')
*.db_file_name_convert=('/usr/oracle/oradata/rac/', '+data/rac/')
*.fal_client='standby2'
*.fal_server='primary,standby'
*.open_cursors=300
*.pga_aggregate_target=199229440
*.processes=150
*.remote_login_passwordfile='EXCLUSIVE'
*.sga_target=598736896
*.cluster_database=true
*.cluster_database_instances=2
*.standby_file_management='AUTO'
*.undo_management='AUTO'
*.user_dump_dest='/usr/oracle/admin/rac/udump'
rac1.undo_tablespace='UNDOTBS1'
rac2.undo_tablespace='UNDOTBS2'
rac1.instance_number=1
rac2.instance_number=2
rac1.thread=1
rac2.thread=2
*.remote_listener=LISTENERS_RAC
rac1.local_listener='LISTENER_RAC1'
rac2.local_listener='LISTENER_RAC2'

3、编辑tnsnames,两个节点上都要添加:
RAC =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = zhh1-vip)(PORT = 3173))
    (ADDRESS = (PROTOCOL = TCP)(HOST = zhh2-vip)(PORT = 3173))
    (LOAD_BALANCE = yes)
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = rac)
    )
  )

RAC1 =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = zhh1-vip)(PORT = 3173))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = rac)
      (INSTANCE_NAME = rac1)
    )
  )

RAC2 =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = zhh2-vip)(PORT = 3173))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = rac)
      (INSTANCE_NAME = rac2)
    )
  )

LISTENER_RAC1 =
  (ADDRESS = (PROTOCOL = TCP)(HOST = zhh1-vip)(PORT = 3173))

LISTENER_RAC2 =
  (ADDRESS = (PROTOCOL = TCP)(HOST = zhh2-vip)(PORT = 3173))

LISTENERS_RAC =
  (ADDRESS_LIST =
    (ADDRESS = (PROTOCOL = TCP)(HOST = zhh1-vip)(PORT = 3173))
    (ADDRESS = (PROTOCOL = TCP)(HOST = zhh2-vip)(PORT = 3173))
  )

primary =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.5.237)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = rac)
    )
  )

standby =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.12.18)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = rac)
    )
  )

4、复制密码文件到两个节点上,修改成orapwrac1和orapwrac2

5、进行恢复
[oracle@zhh1 backup]$ /usr/oracle/product/10.2.0/db_1/bin/rman target /

Recovery Manager: Release 10.2.0.4.0 - Production on 星期三 3月 16 15:57:13 2011

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

connected to target database (not started)

RMAN> set DBID=2333300477

executing command: SET DBID

RMAN> startup nomount pfile='/usr/oracle/backup/initrac1.ora'

Oracle instance started

Total System Global Area     599785472 bytes

Fixed Size                     2085776 bytes
Variable Size                159386736 bytes
Database Buffers             432013312 bytes
Redo Buffers                   6299648 bytes

RMAN> restore controlfile from '/usr/oracle/backup/control01.ctl';

Starting restore at 16-3月 -11
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=148 instance=rac1 devtype=DISK

channel ORA_DISK_1: copied control file copy
output filename=+DATA/rac/control01.ctl
Finished restore at 16-3月 -11

RMAN> alter database mount;

database mounted
released channel: ORA_DISK_1

RMAN> restore database;

Starting restore at 16-3月 -11
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=148 instance=rac1 devtype=DISK

channel ORA_DISK_1: starting datafile backupset restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
restoring datafile 00001 to +DATA/rac/system01.dbf
restoring datafile 00002 to +DATA/rac/undotbs01.dbf
restoring datafile 00003 to +DATA/rac/sysaux01.dbf
restoring datafile 00004 to +DATA/rac/users01.dbf
restoring datafile 00005 to +DATA/rac/example01.dbf
restoring datafile 00006 to +DATA/rac/zhh01.dbf
restoring datafile 00007 to +DATA/rac/undotbs02.dbf
channel ORA_DISK_1: reading from backup piece /usr/oracle/backup/full_09m7cgdr_1_1
channel ORA_DISK_1: restored backup piece 1
piece handle=/usr/oracle/backup/full_09m7cgdr_1_1 tag=TAG20110316T153939
channel ORA_DISK_1: restore complete, elapsed time: 00:00:36
Finished restore at 16-3月 -11

六、启动rac环境standby

1、在rac上创建standby redo log
SQL> alter database add standby logfile thread 1 group 7 '+data/rac/redo07.log' size 52428800;

Database altered.

SQL> alter database add standby logfile thread 1 group 8 '+data/rac/redo08.log' size 52428800;

Database altered.

SQL> alter database add standby logfile thread 1 group 9 '+data/rac/redo09.log' size 52428800;

Database altered.

SQL> alter database add standby logfile thread 1 group 10 '+data/rac/redo10.log' size 52428800;

Database altered.

SQL> alter database add standby logfile thread 2 group 11 '+data/rac/redo11.log' size 52428800;

Database altered.

SQL> alter database add standby logfile thread 2 group 12 '+data/rac/redo12.log' size 52428800;

Database altered.

SQL> alter database add standby logfile thread 2 group 13 '+data/rac/redo13.log' size 52428800;

Database altered.

SQL> alter database add standby logfile thread 2 group 14 '+data/rac/redo14.log' size 52428800;

Database altered.

SQL>  select * from v$log;

    GROUP#    THREAD#  SEQUENCE#      BYTES    MEMBERS ARC STATUS           FIRST_CHANGE# FIRST_TIME
---------- ---------- ---------- ---------- ---------- --- ---------------- ------------- --------------
         1          1         22   52428800          1 YES INACTIVE                769973 16-3月 -11
         2          1         23   52428800          1 NO  CURRENT                 769994 16-3月 -11
         3          1         21   52428800          1 YES INACTIVE                769971 16-3月 -11
         4          2          1   52428800          1 YES ACTIVE                  768977 16-3月 -11
         5          2          0   52428800          1 YES UNUSED                       0
         6          2          0   52428800          1 YES UNUSED                       0

6 rows selected.

SQL> select * from v$logfile;

    GROUP# STATUS  TYPE    MEMBER                                   IS_
---------- ------- ------- ---------------------------------------- ---
         3         ONLINE  +DATA/rac/redo03.log                     NO
         2         ONLINE  +DATA/rac/redo02.log                     NO
         1         ONLINE  +DATA/rac/redo01.log                     NO
         4         ONLINE  +DATA/rac/redo04.log                     NO
         5         ONLINE  +DATA/rac/redo05.log                     NO
         6         ONLINE  +DATA/rac/redo06.log                     NO
         7         STANDBY +DATA/rac/redo07.log                     NO
         8         STANDBY +DATA/rac/redo08.log                     NO
         9         STANDBY +DATA/rac/redo09.log                     NO
        10         STANDBY +DATA/rac/redo10.log                     NO
        11         STANDBY +DATA/rac/redo11.log                     NO

    GROUP# STATUS  TYPE    MEMBER                                   IS_
---------- ------- ------- ---------------------------------------- ---
        12         STANDBY +DATA/rac/redo12.log                     NO
        13         STANDBY +DATA/rac/redo13.log                     NO
        14         STANDBY +DATA/rac/redo14.log                     NO

14 rows selected.

2、创建spfile
SQL> create spfile='+data/rac/spfilerac.ora' from pfile='/usr/oracle/backup/initrac1.ora';

File created.
在两个节点上创建指向spfile的pfile
[oracle@zhh1 ~]$ cd /usr/oracle/product/10.2.0/db_1/dbs/
[oracle@zhh1 dbs]$ vi initrac1.ora
spfile='+data/rac/spfilerac.ora'

SQL> shutdown immediate
ORA-01507: database not mounted


ORACLE instance shut down.
SQL> startup mount
ORACLE instance started.

Total System Global Area  599785472 bytes
Fixed Size                  2085776 bytes
Variable Size             159386736 bytes
Database Buffers          432013312 bytes
Redo Buffers                6299648 bytes
Database mounted.
SQL> show parameter spfile

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
spfile                               string      +DATA/rac/spfilerac.ora

3、启动standby
SQL> recover managed standby database  using current logfile disconnect from session;
Media recovery complete.

primary库启动log_archive_dest_state_3
SQL> alter system set log_archive_dest_state_3=enable;

System altered.

SQL> alter system switch logfile;

System altered.

4、验证standby:primary库上切换日志,看standby是否应用。
SQL> select thread#,sequence#,applied from v$archived_log;

   THREAD#  SEQUENCE# APP
---------- ---------- ---
         1         23 YES
         1         24 YES
SQL>  alter database recover managed standby database cancel;

Database altered.

SQL> alter database open read only;

Database altered.

SQL> select instance_name,host_name,status from gv$instance;

INSTANCE_NAME    HOST_NAME                                                        STATUS
---------------- ---------------------------------------------------------------- ------------
rac1             zhh1                                                             OPEN

节点2上
[oracle@zhh2 dbs]$ export ORACLE_SID=rac2
[oracle@zhh2 dbs]$ sqlplus / as sysdba

SQL*Plus: Release 10.2.0.4.0 - Production on 星期三 3月 16 16:37:45 2011

Copyright (c) 1982, 2007, Oracle.  All Rights Reserved.

Connected to an idle instance.

SQL> startup open read only
ORACLE instance started.

Total System Global Area  599785472 bytes
Fixed Size                  2085776 bytes
Variable Size             159386736 bytes
Database Buffers          432013312 bytes
Redo Buffers                6299648 bytes
Database mounted.
Database opened.
SQL> select instance_name,host_name,status from gv$instance;

INSTANCE_NAME    HOST_NAME                                                        STATUS
---------------- ---------------------------------------------------------------- ------------
rac2             zhh2                                                             OPEN
rac1             zhh1                                                             OPEN

关闭两个节点的实例,继续启动standby
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount
ORACLE instance started.

Total System Global Area  599785472 bytes
Fixed Size                  2085776 bytes
Variable Size             163581040 bytes
Database Buffers          427819008 bytes
Redo Buffers                6299648 bytes
Database mounted.
SQL> recover managed standby database  using current logfile disconnect from session;
Media recovery complete.

七、主备切换
1、第一个单实例standby(12.18)上:
tnsnames中添加
primary =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.5.237)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = rac)
    )
  )

standby =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.12.18)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = rac)
    )
  )

standby2=
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.5.235)(PORT = 3173))
    )
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SID = rac1)
    )
  )

SQL> show parameter archive

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
archive_lag_target                   integer     0
log_archive_config                   string      dg_config=(primary,standby)
......

SQL> alter system set log_archive_config='dg_config=(primary,standby,standby2)';

System altered.

SQL> alter system set fal_server='primary,standby2';

System altered.

SQL> alter system set fal_client='standby';

System altered.

2、在单实例primary(5.237)上添加standby redo log
SQL> select * from v$log;

    GROUP#    THREAD#  SEQUENCE#      BYTES    MEMBERS ARC STATUS           FIRST_CHANGE# FIRST_TIM
---------- ---------- ---------- ---------- ---------- --- ---------------- ------------- ---------
         1          1         28   52428800          1 YES INACTIVE                775306 16-MAR-11
         2          1         29   52428800          1 YES INACTIVE                775441 16-MAR-11
         3          1         30   52428800          1 NO  CURRENT                 775554 16-MAR-11
         4          2          1   52428800          1 YES ACTIVE                  768977 16-MAR-11
         5          2          0   52428800          1 YES UNUSED                       0
         6          2          0   52428800          1 YES UNUSED                       0

6 rows selected.

SQL>  select * from v$logfile;

    GROUP# STATUS  TYPE    MEMBER                                   IS_
---------- ------- ------- ---------------------------------------- ---
         3         ONLINE  /usr/oracle/oradata/rac/redo03.log       NO
         2         ONLINE  /usr/oracle/oradata/rac/redo02.log       NO
         1         ONLINE  /usr/oracle/oradata/rac/redo01.log       NO
         4         ONLINE  /usr/oracle/oradata/rac/redo04.log       NO
         5         ONLINE  /usr/oracle/oradata/rac/redo05.log       NO
         6         ONLINE  /usr/oracle/oradata/rac/redo06.log       NO

6 rows selected.

SQL> alter database add standby logfile thread 1 group 7 '/usr/oracle/oradata/rac/redo07.log' size 52428800;

Database altered.

SQL> alter database add standby logfile thread 1 group 8 '/usr/oracle/oradata/rac/redo08.log' size 52428800;

Database altered.

SQL> alter database add standby logfile thread 1 group 9 '/usr/oracle/oradata/rac/redo09.log' size 52428800;

Database altered.

SQL> alter database add standby logfile thread 1 group 10 '/usr/oracle/oradata/rac/redo10.log' size 52428800;

Database altered.

SQL> alter database add standby logfile thread 2 group 11 '/usr/oracle/oradata/rac/redo11.log' size 52428800;

Database altered.

SQL> alter database add standby logfile thread 2 group 12 '/usr/oracle/oradata/rac/redo12.log' size 52428800;

Database altered.

SQL> alter database add standby logfile thread 2 group 13 '/usr/oracle/oradata/rac/redo13.log' size 52428800;

Database altered.

SQL> alter database add standby logfile thread 2 group 14 '/usr/oracle/oradata/rac/redo14.log' size 52428800;

Database altered.

SQL> select * from v$log;

    GROUP#    THREAD#  SEQUENCE#      BYTES    MEMBERS ARC STATUS           FIRST_CHANGE# FIRST_TIM
---------- ---------- ---------- ---------- ---------- --- ---------------- ------------- ---------
         1          1         28   52428800          1 YES INACTIVE                775306 16-MAR-11
         2          1         29   52428800          1 YES INACTIVE                775441 16-MAR-11
         3          1         30   52428800          1 NO  CURRENT                 775554 16-MAR-11
         4          2          1   52428800          1 YES ACTIVE                  768977 16-MAR-11
         5          2          0   52428800          1 YES UNUSED                       0
         6          2          0   52428800          1 YES UNUSED                       0

6 rows selected.

SQL> select * from v$logfile;

    GROUP# STATUS  TYPE    MEMBER                                   IS_
---------- ------- ------- ---------------------------------------- ---
         3         ONLINE  /usr/oracle/oradata/rac/redo03.log       NO
         2         ONLINE  /usr/oracle/oradata/rac/redo02.log       NO
         1         ONLINE  /usr/oracle/oradata/rac/redo01.log       NO
         4         ONLINE  /usr/oracle/oradata/rac/redo04.log       NO
         5         ONLINE  /usr/oracle/oradata/rac/redo05.log       NO
         6         ONLINE  /usr/oracle/oradata/rac/redo06.log       NO
         7         STANDBY /usr/oracle/oradata/rac/redo07.log       NO
         8         STANDBY /usr/oracle/oradata/rac/redo08.log       NO
         9         STANDBY /usr/oracle/oradata/rac/redo09.log       NO
        10         STANDBY /usr/oracle/oradata/rac/redo10.log       NO
        11         STANDBY /usr/oracle/oradata/rac/redo11.log       NO

    GROUP# STATUS  TYPE    MEMBER                                   IS_
---------- ------- ------- ---------------------------------------- ---
        12         STANDBY /usr/oracle/oradata/rac/redo12.log       NO
        13         STANDBY /usr/oracle/oradata/rac/redo13.log       NO
        14         STANDBY /usr/oracle/oradata/rac/redo14.log       NO

14 rows selected.

3、switch切换
切换之前确保log_archive_dest_n、fal_server,fal_client参数设置正确

单实例primary上
SQL> select DATABASE_ROLE,SWITCHOVER_STATUS from v$database;

DATABASE_ROLE    SWITCHOVER_STATUS
---------------- --------------------
PRIMARY          TO STANDBY

SQL> select name, db_unique_name, database_role, switchover_status from v$database;

NAME      DB_UNIQUE_NAME                 DATABASE_ROLE    SWITCHOVER_STATUS
--------- ------------------------------ ---------------- --------------------
RAC       PRIMARY                        PRIMARY          TO STANDBY

SQL> alter database commit to switchover to physical standby with session shutdown;

Database altered.

SQL> shutdown immediate
ORA-01507: database not mounted


ORACLE instance shut down.
SQL> startup mount
ORACLE instance started.

Total System Global Area  599785472 bytes
Fixed Size                  2085776 bytes
Variable Size             163581040 bytes
Database Buffers          427819008 bytes
Redo Buffers                6299648 bytes
Database mounted.

节点1上
SQL> select name, db_unique_name, database_role, switchover_status from v$database;

NAME      DB_UNIQUE_NAME                 DATABASE_ROLE    SWITCHOVER_STATUS
--------- ------------------------------ ---------------- --------------------
RAC       standby2                       PHYSICAL STANDBY TO PRIMARY

SQL> alter database commit to switchover to primary;

Database altered.

SQL> alter database open;

Database altered.

节点2上
[oracle@zhh2 dbs]$ sqlplus / as sysdba

SQL*Plus: Release 10.2.0.4.0 - Production on 星期三 3月 16 17:32:18 2011

Copyright (c) 1982, 2007, Oracle.  All Rights Reserved.

Connected to an idle instance.

SQL> startup
ORACLE instance started.

Total System Global Area  599785472 bytes
Fixed Size                  2085776 bytes
Variable Size             163581040 bytes
Database Buffers          427819008 bytes
Redo Buffers                6299648 bytes
Database mounted.
Database opened.
SQL> select instance_name, status from gv$instance;

INSTANCE_NAME    STATUS
---------------- ------------
rac2             OPEN
rac1             OPEN

原来的单实例primary启动standby
SQL> recover managed standby database using current logfile disconnect from session;
Media recovery complete.

查看切换后的状态:
问题1:
几次切换日志后发现原primary没有接收到日志,rac环境中的alert日志:
Wed Mar 16 17:36:26 2011
ARC1: LGWR is scheduled to archive destination LOG_ARCHIVE_DEST_2 after log switch
Error 12514 received logging on to the standby
Wed Mar 16 17:36:26 2011
Errors in file /usr/oracle/admin/rac/bdump/rac1_arc1_20120.trc:
ORA-12514: TNS:listener does not currently know of service requested in connect descriptor
[oracle@zhh1 dbs]$ oerr ora 12514
12514, 00000, "TNS:listener does not currently know of service requested in connect descriptor"
// *Cause:  The listener received a request to establish a connection to a
// database or other service. The connect descriptor received by the listener
// specified a service name for a service (usually a database service)
// that either has not yet dynamically registered with the listener or has
// not been statically configured for the listener.  This may be a temporary
// condition such as after the listener has started, but before the database
// instance has registered with the listener.
// *Action:
//  - Wait a moment and try to connect a second time.
//  - Check which services are currently known by the listener by executing:
//    lsnrctl services <listener name>
//  - Check that the SERVICE_NAME parameter in the connect descriptor of the
//    net service name used specifies a service known by the listener.
//  - If an easy connect naming connect identifier was used, check that
//    the service name specified is a service known by the listener.
//  - Check for an event in the listener.log file.

检查原primary数据库的监听器状态,发现:
[oracle@wzlm archive]$ lsnrctl status

LSNRCTL for Linux: Version 10.2.0.4.0 - Production on 16-MAR-2011 17:39:55

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

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=wzlm)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 10.2.0.4.0 - Production
Start Date                10-MAR-2011 09:44:52
Uptime                    6 days 7 hr. 55 min. 2 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /usr/oracle/product/10.2.0/network/admin/listener.ora
Listener Log File         /usr/oracle/product/10.2.0/network/log/listener.log
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=wzlm)(PORT=1521)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC0)))
Services Summary...
Service "PLSExtProc" has 1 instance(s).
  Instance "PLSExtProc", status UNKNOWN, has 1 handler(s) for this service...
Service "PRIMARY" has 1 instance(s).
  Instance "rac", status READY, has 1 handler(s) for this service...
Service "PRIMARY_XPT" has 1 instance(s).
  Instance "rac", status READY, has 1 handler(s) for this service...
这个是因为没有静态注册,动态注册的service=db_unqiue_name+db+domain,解决方法可以静态注册,或者修改tnsnames中使用sid ,而不是service_name.
我们这里采取静态注册方式,修改原primary的监听器后,OK。

问题2:另外一个standby能够接收到日志,后来重启了一下,发现接收不到日志了。
rac主库上查询发现:
SQL> select dest_name,status,error from v$archive_dest;

DEST_NAME                      STATUS    ERROR
------------------------------ --------- -----------------------------------------------------------------
LOG_ARCHIVE_DEST_1             VALID
LOG_ARCHIVE_DEST_2             VALID
LOG_ARCHIVE_DEST_3             DISABLED  ORA-16057: DGID from server not in Data Guard configuration
LOG_ARCHIVE_DEST_4             INACTIVE
LOG_ARCHIVE_DEST_5             INACTIVE
LOG_ARCHIVE_DEST_6             INACTIVE
LOG_ARCHIVE_DEST_7             INACTIVE
LOG_ARCHIVE_DEST_8             INACTIVE
LOG_ARCHIVE_DEST_9             INACTIVE
LOG_ARCHIVE_DEST_10            INACTIVE

10 rows selected.

[oracle@zhh1 dbs]$ oerr ora 16057
16057, 00000, "DGID from server not in Data Guard configuration"
// *Cause:  The Data Guard name of the primary database or the FAL server
//          is not in the Data Guard configuration of the standby.
// *Action: In order for the primary database or the FAL server to archive
//          logs to the standby database, the Data Guard name of the primary
//          or FAL server must be in the Data Guard configuration of the
//          standby.
这个错误的意思是LOG_ARCHIVE_DEST_3指定的service不在log_archive_config之中,查看了一下rac主库和standby,都有。
查看这个接收不到日志的standby参数,发现确实不存在。可明明在第七步主备切换准备中,第一步就修改了log_archive_config、fal_server、fal_client这三个参数。怎么可能消失呢?突然想起来了:
这个standby使用的是pfile,没有创建spfile。查看果然没有使用spfile!
使用pfile的一个最大缺点个人认为就是无法保存修改的参数。赶紧创建spfile,然后修改那三个参数。
重启数据库后,启动standby后,发现日志仍然接收不到。
查看主库日志,发现alert中有下面的信息:
Destination LOG_ARCHIVE_DEST_3 no longer supports SYNCHRONIZATION
看来主库直接放弃LOG_ARCHIVE_DEST_3了,先把LOG_ARCHIVE_DEST_3设置成空,然后再设置成正确的参数,切换日志后,发现日志传输过来了,并且能够应用。

八、注册到CRS
SQL> alter system set service_names=rac;

System altered.

SQL> show parameter name

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
db_file_name_convert                 string      /usr/oracle/oradata/rac/, +dat
                                                 a/rac/
db_name                              string      rac
db_unique_name                       string      standby2
global_names                         boolean     FALSE
instance_name                        string      rac1
lock_name_space                      string
log_file_name_convert                string      /usr/oracle/oradata/rac/, +dat
                                                 a/rac/
service_names                        string      RAC

[oracle@zhh1 dbs]$ srvctl  add database -d rac  -o $ORACLE_HOME -p +DATA/rac/spfilerac.ora -n rac
[oracle@zhh1 dbs]$ srvctl  add instance -d rac -i rac1 -n zhh1
[oracle@zhh1 dbs]$ srvctl  add instance -d rac -i rac2 -n zhh2
[oracle@zhh1 dbs]$ srvctl modify instance -d rac -i rac1 -s +ASM1
[oracle@zhh1 dbs]$ srvctl modify instance -d rac -i rac2 -s +ASM2
[oracle@zhh1 dbs]$ srvctl status database -d rac
Instance rac1 is not running on node zhh1
Instance rac2 is not running on node zhh2
[oracle@zhh1 dbs]$ srvctl start database -d rac
[oracle@zhh1 dbs]$ srvctl status database -d rac
Instance rac1 is running on node zhh1
Instance rac2 is running on node zhh2
[oracle@zhh1 dbs]$ crs_stat -t
名称           类型           目标      状态      主机       
------------------------------------------------------------
ora.rac.db     application    ONLINE    ONLINE    zhh1       
ora....c1.inst application    ONLINE    ONLINE    zhh1       
ora....c2.inst application    ONLINE    ONLINE    zhh2       
ora....SM1.asm application    ONLINE    ONLINE    zhh1       
ora....H1.lsnr application    ONLINE    ONLINE    zhh1       
ora.zhh1.gsd   application    ONLINE    ONLINE    zhh1       
ora.zhh1.ons   application    ONLINE    ONLINE    zhh1       
ora.zhh1.vip   application    ONLINE    ONLINE    zhh1       
ora....SM2.asm application    ONLINE    ONLINE    zhh2       
ora....H2.lsnr application    ONLINE    ONLINE    zhh2       
ora.zhh2.gsd   application    ONLINE    ONLINE    zhh2       
ora.zhh2.ons   application    ONLINE    ONLINE    zhh2       
ora.zhh2.vip   application    ONLINE    ONLINE    zhh2 

重启机器,查看一下是否能够开机启动。

你可能感兴趣的:(oracle 单实例+文件管理 +dataguard ---------------------》》 oracle rac+asm+ dataguard)