更改db_unique_name后,修复磁盘组依赖关系和其他crs中的相关配置

做ADG时,修改了数据库的db_unique_name后,alert中报错如下:

ERROR: failed to establish dependency between database mynewdb and diskgroup resource ora.DATA.dg
ERROR: failed to establish dependency between database mynewdb and diskgroup resource ora.REDODG.dg

这个错误不影响使用,但是终归是别扭的……

检查crs中数据库的配置:

[oracle@lunardb2 ~]$ srvctl config database -d lunardb
Database unique name: lunardb
Database name: lunardb
Oracle home: /u01/app/oracle/product/11.2.0/db_1
Oracle user: oracle
Spfile: +DATA/lunardb/spfilelunardb.ora
Domain: 
Start options: open
Stop options: immediate
Database role: PRIMARY
Management policy: AUTOMATIC
Server pools: lunardb
Database instances: lunardb1,lunardb2
Disk Groups: DATA
Mount point paths: 
Services: 
Type: RAC
Database is administrator managed
[oracle@lunardb2 ~]$ 

这里可以看到,以前的spfile(主库的)位置是:+DATA/lunardb/spfilelunardb.ora

此时,即便是手动修改了参数文件位置为 SPFILE=’+DATA/mynewdb/spfilemynewdb.ora’,重启crs后,启动数据库也会有报错信息:

[oracle@lunardb1 ~]$ ss

SQL*Plus: Release 11.2.0.3.0 Production on Wed Sep 24 23:51:54 2014

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

Connected to an idle instance.

23:51:54 SYS@ lunardb1> startup
ORA-01078: failure in processing system parameters
ORA-01565: error in identifying file '+DATA/lunardb/spfilelunardb.ora'
ORA-17503: ksfdopn:2 Failed to open file +DATA/lunardb/spfilelunardb.ora
ORA-15056: additional error message
ORA-17503: ksfdopn:2 Failed to open file +DATA/lunardb/spfilelunardb.ora
ORA-15173: entry 'lunardb' does not exist in directory '/'
ORA-06512: at line 4
23:51:57 SYS@ lunardb1> 

因为它还是自动修改为crs的db资源中的信息,并把以前我手工修改的信息做了备份:

[oracle@lunardb1 dbs]$ cat initlunardb1.ora
SPFILE='+DATA/lunardb/spfilelunardb.ora'              # line added by Agent
[oracle@lunardb1 dbs]$ cat initlunardb1.ora.bak.lunardb1
SPFILE='+DATA/mynewdb/spfilemynewdb.ora'
[oracle@lunardb1 dbs]$ 

可以修改crs中db的spfile位置:
srvctl modify database -d lunardb -p ‘+DATA/mynewdb/spfilemynewdb.ora’

再次检查,可以发现spfile位置已经正确了:

[oracle@lunardb1 ~]$ srvctl config database -d lunardb
Database unique name: lunardb
Database name: lunardb
Oracle home: /u01/app/oracle/product/11.2.0/db_1
Oracle user: oracle
Spfile: +DATA/mynewdb/spfilemynewdb.ora
Domain: 
Start options: open
Stop options: immediate
Database role: PRIMARY
Management policy: AUTOMATIC
Server pools: lunardb
Database instances: lunardb1,lunardb2
Disk Groups: ARCHDG,DATA,REDODG
Mount point paths: 
Services: 
Type: RAC
Database is administrator managed
[oracle@lunardb1 ~]$ 

这里很显然,除了spfile位置,Database unique name也是不对的,因为crs中保存的db信息是根据db_unique_name来判断的,只能通过remove database,然后再add database,add instance等等:

[oracle@lunardb1 ~]$ srvctl remove database -d lunardb
Remove the database lunardb? (y/[n]) y
[oracle@lunardb1 ~]$ srvctl add database -d mynewdb -o /u01/app/oracle/product/11.2.0/db_1
[oracle@lunardb1 ~]$ srvctl config database -d mynewdb
Database unique name: mynewdb
Database name: 
Oracle home: /u01/app/oracle/product/11.2.0/db_1
Oracle user: oracle
Spfile: 
Domain: 
Start options: open
Stop options: immediate
Database role: PRIMARY
Management policy: AUTOMATIC
Server pools: mynewdb
Database instances: lunardb1,lunardb2
Disk Groups: 
Mount point paths: 
Services: 
Type: RAC
Database is administrator managed
[oracle@lunardb1 ~]$ srvctl modify database -d mynewdb -a ARCHDG,DATA,REDODG
[oracle@lunardb1 ~]$ srvctl modify database -d mynewdb -p '+DATA/mynewdb/spfilemynewdb.ora'
[oracle@lunardb1 ~]$ srvctl config database -d mynewdb
Database unique name: mynewdb
Database name: 
Oracle home: /u01/app/oracle/product/11.2.0/db_1
Oracle user: oracle
Spfile: +DATA/mynewdb/spfilemynewdb.ora
Domain: 
Start options: open
Stop options: immediate
Database role: PRIMARY
Management policy: AUTOMATIC
Server pools: mynewdb
Database instances: lunardb1,lunardb2
Disk Groups: ARCHDG,DATA,REDODG
Mount point paths: 
Services: 
Type: RAC
Database is administrator managed
[oracle@lunardb1 ~]$ srvctl modify database -d mynewdb -n lunardb
[oracle@lunardb1 ~]$ srvctl config database -d mynewdb
Database unique name: mynewdb
Database name: lunardb
Oracle home: /u01/app/oracle/product/11.2.0/db_1
Oracle user: oracle
Spfile: +DATA/mynewdb/spfilemynewdb.ora
Domain: 
Start options: open
Stop options: immediate
Database role: PRIMARY
Management policy: AUTOMATIC
Server pools: mynewdb
Database instances: lunardb1,lunardb2
Disk Groups: ARCHDG,DATA,REDODG
Mount point paths: 
Services: 
Type: RAC
Database is administrator managed
[oracle@lunardb1 ~]$ 

好了,alert中信息正常了:

ALTER DATABASE   MOUNT
This instance was first to mount
NOTE: Loaded library: System 
SUCCESS: diskgroup DATA was mounted
SUCCESS: diskgroup REDODG was mounted
NOTE: dependency between database mynewdb and diskgroup resource ora.DATA.dg is established
NOTE: dependency between database mynewdb and diskgroup resource ora.REDODG.dg is established
发表在 RAC | 标签为 | 留下评论

使用statspack监控Active Dataguard的性能—2-创建ADG的性能报告

后台执行一个脚本,模拟登录风暴

#!/bin/bash
for i in {1..1000}
do
echo $i
sqlplus -S lunar/lunar@DB16<<EOF
select instance_name from v\$instance;
EOF
sleep 1
done
exit 0

[oracle@lunar ~]$ nohup ./login.sh &
[1] 27907
[oracle@lunar ~]$ nohup: appending output to `nohup.out’

[oracle@lunar ~]$ jobs
[1]+ Running nohup ./login.sh &
[oracle@lunar ~]$ jobs
[1]+ Running nohup ./login.sh &
[oracle@lunar ~]$ jobs
[1]+ Running nohup ./login.sh &
[oracle@lunar ~]$ jobs
[1]+ Running nohup ./login.sh &
[oracle@lunar ~]$ jobs
[1]+ Running nohup ./login.sh &
[oracle@lunar ~]$
[oracle@lunar ~]$

收集一个快照:
08:06:05 STDBYPERF@lunarp>exec STATSPACK_lunarc_lunarc.snap;

PL/SQL procedure successfully completed.

Elapsed: 00:00:02.49
08:06:13 STDBYPERF@lunarp>

过几分钟,再次打一个快照:
08:08:36 STDBYPERF@lunarp>exec STATSPACK_lunarc_lunarc.snap;

PL/SQL procedure successfully completed.

Elapsed: 00:00:00.71
08:10:36 STDBYPERF@lunarp>

做个报表:
08:10:36 STDBYPERF@lunarp>@?/rdbms/admin/sbreport

Instances in this Statspack schema
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

DB Unique Name Instance Name
—————————— —————-
lunarc lunarc

Enter the DATABASE UNIQUE NAME of the standby database to report
Enter value for db_unique_name: lunarc
You entered: lunarc

Enter the INSTANCE NAME of the standby database instance to report
Enter value for inst_name: lunarc
You entered: lunarc

Specify the number of days of snapshots to choose from
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Entering the number of days (n) will result in the most recent
(n) days of snapshots being listed. Pressing without
specifying a number lists all completed snapshots.

Listing all Completed Snapshots

Snap
Instance Snap Id Snap Started Level Comment
———— ——— —————– —– ——————–
lunarc 1 03 Aug 2014 08:08 5
2 03 Aug 2014 08:10 5

Specify the Begin and End Snapshot Ids
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Enter value for begin_snap: 1
Begin Snapshot Id specified: 1

Enter value for end_snap: 2
End Snapshot Id specified: 2

Specify the Report Name
~~~~~~~~~~~~~~~~~~~~~~~
The default report file name is sb_lunarc_lunarc_1_2. To use this name,
press to continue, otherwise enter an alternative.

Enter value for report_name:
。。。。。。。。。。。。这里省略部分报告内容

init.ora Parameters DB/Inst: lunarc/lunarc Snaps: 1-2

End value
Parameter Name Begin value (if different)
—————————– ——————————— ————–
audit_file_dest /u01/app/oracle/admin/lunarc/adum
audit_trail NONE
compatible 11.2.0.3.0
control_files /tempdisk/lunarc/control01.ctl, /
db_block_size 8192
db_domain
db_file_name_convert /stage/lunar/, /tempdisk/lunarc/
db_name lunar
db_recovery_file_dest /stage/fast_recovery_area
db_recovery_file_dest_size 1218762752
db_unique_name lunarc
deferred_segment_creation FALSE
diagnostic_dest /u01/app/oracle
fal_client lunarc
fal_server lunarp, lunars
filesystemio_options setall
log_archive_config DG_CONFIG=(lunarp,lunars,lunarc)
log_archive_dest_1 LOCATION=USE_DB_RECOVERY_FILE_DES
log_archive_dest_2 SERVICE=lunarp LGWR ASYNC AFFIRM
log_archive_dest_3 SERVICE=lunars LGWR ASYNC AFFIRM
log_archive_dest_state_1 ENABLE
log_archive_dest_state_2 ENABLE
log_archive_dest_state_3 ENABLE
log_file_name_convert /stage/lunar/, /tempdisk/lunarc/
open_cursors 300
pga_aggregate_target 153092096
processes 150
remote_login_passwordfile EXCLUSIVE
sec_return_server_release_ban FALSE
service_names lunar
sga_target 629145600
standby_file_management AUTO
undo_tablespace UNDOTBS1
————————————————————-

End of Report ( sb_lunarc_lunarc_1_2.lst )

08:11:58 STDBYPERF@lunarp>!
[oracle@lunar ~]$ ls
awrinfo.txt lunar_baby.txt lunar.env nohup.out sbctab.lis sbdtab.lis sb_lunarc_lunarc_1_2.lst spctab.lis spdtab.lis test
login.sh lunar_banner.txt lunarstb.env sbcpkg.lis sbcusr.lis sbdusr.lis spcpkg.lis spcusr.lis spdusr.lis tmp
[oracle@lunar ~]$

可以看到下面的报告每秒钟登录110次,O(∩_∩)O哈哈~:


无标题


这里使用的完整的示例报告如下:
sb_lunarc_lunarc_1_2

发表在 Dataguard | 一条评论

使用statspack监控Active Dataguard的性能—1-安装篇和简介

Statspack的功能早在Oracle 8.1.6就可以使用(Oracle 8.1.7正式随产品发布),这里不再赘述,baidu google上大把大把的……

从Oracle 10.1开始,Oracle引入了AWR(Automatic Workload Repository),其功能较之statspack不是强大了一星半点(AWR,ASH,ADDM,SPA,SPM……),statspack一度在10g后被搁置了……

随着Oracle 11.1 ADG的出现,Statspack有了新的用途……我们都知道ADG是只读打开的,其awr跟主库的是一致的,监控ADG上的查询业务的功能,又变成了使用脚本和crontab等的手工作坊式管理……Oracle为此给statspack增加了新的功能:
@?/rdbms/admin/sb*
在statspack目录下($ORACLE_HOME/rdbms/admin/),有两类statsapck相关的文件:

[oracle@lunar ~]$ cd $ORACLE_HOME/rdbms/admin/
[oracle@lunar admin]$ ls sp*
spadvrpt.sql  spawrrac.sql  spctab.sql  spdrop.sql  sppurge.sql   spreport.sql  sptrunc.sql  spup10.sql     spup816.sql  spup92.sql
spauto.sql    spcpkg.sql    spcusr.sql  spdtab.sql  sprepcon.sql  sprepsql.sql  spuexp.par   spup1101.sql   spup817.sql
spawrio.sql   spcreate.sql  spdoc.txt   spdusr.sql  sprepins.sql  sprsqins.sql  spup102.sql  spup11201.sql  spup90.sql
[oracle@lunar admin]$ 
[oracle@lunar admin]$ 
[oracle@lunar admin]$ ls sb*
sbaddins.sql  sbcreate.sql  sbcusr.sql    sbdoc.txt   sbdtab.sql  sblisins.sql  sbrepcon.sql  sbreport.sql  sbup11201.sql
sbcpkg.sql    sbctab.sql    sbdelins.sql  sbdrop.sql  sbdusr.sql  sbpurge.sql   sbrepins.sql  sbup1101.sql
[oracle@lunar admin]$ 
[oracle@lunar admin]$ 

前面的sp开头的应该都不陌生,跟9i和8i的都一样的:

spcreate用于创建statspack用户和对象
spdrop用于删除statspack用户和对象
sptrunc用于truncate掉statsapck的对象的内容,但保留对象和用户
spreport是打statspack报告的脚本
…………

后面sb开头的是ADG中在备库上使用的一套脚本(sb,也就是standby):

sbcreate用于创建stdbyperf用户和对象
sbdrop用于删除stdbyperf用户和对象
sbtrunc用于truncate掉stdbyperf的对象的内容,但保留对象和用户
sbreport是打statspack报告的脚本
…………

具体的安装过程,参加下面的附件sbcreate
如果ADG是RAC,那么需要使用sbaddins.sql将其余的节点加入到statspack中。

发表在 Dataguard, Performence Tuning | 标签为 , , , | 一条评论

Cascade Standby切换测试(级联ADG的切换)

当前环境:
A: 当前是Primary ,Oracle 11.2.0.3,本次切换后为Physical Standby
B: 当前是Physical Standby,本次切换后为Cascade Standby(因为这个库是11.2.0.4,版本不一致,因此只能做standby,不能open)
C:当前是Cascade Standby,Oracle 11.2.0.3,本次切换后为Primary

============================================================================================================
1,级联环境下,如果到Cascade的路径是enable,则在做switchover时,主库上查询会报:“RESOLVABLE GAP”
解决方法是将主库到cascade的归档路径设置为defer ;
============================================================================================================

21:17:04 SYS@lunarp>SELECT SWITCHOVER_STATUS FROM V$DATABASE;

SWITCHOVER_STATUS
--------------------
RESOLVABLE GAP

Elapsed: 00:00:00.02
21:17:30 SYS@lunarp>show parameter log

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
audit_syslog_level                   string
commit_logging                       string
db_create_online_log_dest_1          string
db_create_online_log_dest_2          string
db_create_online_log_dest_3          string
db_create_online_log_dest_4          string
db_create_online_log_dest_5          string
enable_ddl_logging                   boolean     FALSE
log_archive_config                   string      DG_CONFIG=(lunarp,lunars,lunar
                                                 c)
log_archive_dest                     string
log_archive_dest_1                   string      LOCATION=USE_DB_RECOVERY_FILE_
                                                 DEST VALID_FOR=(ALL_LOGFILES,A
                                                 LL_ROLES) DB_UNIQUE_NAME=lunar
                                                 p
log_archive_dest_10                  string
log_archive_dest_11                  string
log_archive_dest_12                  string
log_archive_dest_13                  string
log_archive_dest_14                  string
log_archive_dest_15                  string
log_archive_dest_16                  string
log_archive_dest_17                  string
log_archive_dest_18                  string
log_archive_dest_19                  string
log_archive_dest_2                   string      SERVICE=lunars LGWR SYNC AFFIR
                                                 M VALID_FOR=(ONLINE_LOGFILES,P
                                                 RIMARY_ROLE) DB_UNIQUE_NAME=lu
                                                 nars
log_archive_dest_20                  string
log_archive_dest_21                  string
log_archive_dest_22                  string
log_archive_dest_23                  string
log_archive_dest_24                  string
log_archive_dest_25                  string
log_archive_dest_26                  string
log_archive_dest_27                  string
log_archive_dest_28                  string
log_archive_dest_29                  string
log_archive_dest_3                   string      SERVICE=lunarc LGWR SYNC AFFIR
                                                 M VALID_FOR=(STANDBY_LOGFILES,
                                                 STANDBY_ROLE) DB_UNIQUE_NAME=l
                                                 unarc
log_archive_dest_30                  string
log_archive_dest_31                  string
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
log_archive_dest_state_10            string      enable
log_archive_dest_state_11            string      enable
log_archive_dest_state_12            string      enable
log_archive_dest_state_13            string      enable
log_archive_dest_state_14            string      enable
log_archive_dest_state_15            string      enable
log_archive_dest_state_16            string      enable
log_archive_dest_state_17            string      enable
log_archive_dest_state_18            string      enable
log_archive_dest_state_19            string      enable
log_archive_dest_state_2             string      ENABLE
log_archive_dest_state_20            string      enable
log_archive_dest_state_21            string      enable
log_archive_dest_state_22            string      enable
log_archive_dest_state_23            string      enable
log_archive_dest_state_24            string      enable
log_archive_dest_state_25            string      enable
log_archive_dest_state_26            string      enable
log_archive_dest_state_27            string      enable
log_archive_dest_state_28            string      enable
log_archive_dest_state_29            string      enable
log_archive_dest_state_3             string      ENABLE
log_archive_dest_state_30            string      enable
log_archive_dest_state_31            string      enable
log_archive_dest_state_4             string      enable
log_archive_dest_state_5             string      enable
log_archive_dest_state_6             string      enable
log_archive_dest_state_7             string      enable
log_archive_dest_state_8             string      enable
log_archive_dest_state_9             string      enable
log_archive_duplex_dest              string
log_archive_format                   string      %t_%s_%r.dbf
log_archive_local_first              boolean     TRUE
log_archive_max_processes            integer     4
log_archive_min_succeed_dest         integer     1
log_archive_start                    boolean     FALSE
log_archive_trace                    integer     0
log_buffer                           integer     7200768
log_checkpoint_interval              integer     0
log_checkpoint_timeout               integer     1800
log_checkpoints_to_alert             boolean     FALSE
log_file_name_convert                string      +DATA/lunars/, /stage/lunar/
remote_login_passwordfile            string      EXCLUSIVE
sec_case_sensitive_logon             boolean     TRUE
sec_max_failed_login_attempts        integer     10
21:20:24 SYS@lunarp>alter system set log_archive_dest_state_3=defer; 

System altered.

Elapsed: 00:00:00.07
21:20:53 SYS@lunarp>SELECT NAME,DB_UNIQUE_NAME,DATABASE_ROLE,PROTECTION_MODE, SWITCHOVER_STATUS, OPEN_MODE FROM V$DATABASE;

NAME      DB_UNIQUE_NAME                 DATABASE_ROLE    PROTECTION_MODE      SWITCHOVER_STATUS    OPEN_MODE
--------- ------------------------------ ---------------- -------------------- -------------------- --------------------
LUNAR     lunarp                         PRIMARY          MAXIMUM PERFORMANCE  TO STANDBY           READ WRITE

Elapsed: 00:00:00.03
21:21:16 SYS@lunarp>

============================================================================================================
2,如果主库到备库的归档路径(A到B的)是defer,那么switchover时,检查主库状态会是“NOT ALLOWED”:
解决方法是: 将A到B的路径设置为enable
============================================================================================================

21:41:50 SYS@lunarp>SELECT NAME,DB_UNIQUE_NAME,DATABASE_ROLE,PROTECTION_MODE, SWITCHOVER_STATUS, OPEN_MODE FROM V$DATABASE;

NAME      DB_UNIQUE_NAME                 DATABASE_ROLE    PROTECTION_MODE      SWITCHOVER_STATUS    OPEN_MODE
--------- ------------------------------ ---------------- -------------------- -------------------- --------------------
LUNAR     lunarp                         PRIMARY          MAXIMUM PERFORMANCE  NOT ALLOWED          READ WRITE

Elapsed: 00:00:00.02
21:41:52 SYS@lunarp>archive log list
Database log mode              Archive Mode
Automatic archival             Enabled
Archive destination            USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence     34
Next log sequence to archive   36
Current log sequence           36
21:42:29 SYS@lunarp>show parameter log

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
audit_syslog_level                   string
commit_logging                       string
db_create_online_log_dest_1          string
db_create_online_log_dest_2          string
db_create_online_log_dest_3          string
db_create_online_log_dest_4          string
db_create_online_log_dest_5          string
enable_ddl_logging                   boolean     FALSE
log_archive_config                   string      DG_CONFIG=(lunarp,lunars,lunar
                                                 c)
log_archive_dest                     string
log_archive_dest_1                   string      LOCATION=USE_DB_RECOVERY_FILE_
                                                 DEST VALID_FOR=(ALL_LOGFILES,A
                                                 LL_ROLES) DB_UNIQUE_NAME=lunar
                                                 p
log_archive_dest_10                  string
log_archive_dest_11                  string
log_archive_dest_12                  string
log_archive_dest_13                  string
log_archive_dest_14                  string
log_archive_dest_15                  string
log_archive_dest_16                  string
log_archive_dest_17                  string
log_archive_dest_18                  string
log_archive_dest_19                  string
log_archive_dest_2                   string      SERVICE=lunars LGWR ASYNC AFFI
                                                 RM VALID_FOR=(ONLINE_LOGFILES,
                                                 PRIMARY_ROLE) DB_UNIQUE_NAME=l
                                                 unars
log_archive_dest_20                  string
log_archive_dest_21                  string
log_archive_dest_22                  string
log_archive_dest_23                  string
log_archive_dest_24                  string
log_archive_dest_25                  string
log_archive_dest_26                  string
log_archive_dest_27                  string
log_archive_dest_28                  string
log_archive_dest_29                  string
log_archive_dest_3                   string      SERVICE=lunarc LGWR ASYNC AFFI
                                                 RM VALID_FOR=(STANDBY_LOGFILES
                                                 ,STANDBY_ROLE) DB_UNIQUE_NAME=
                                                 lunarc
log_archive_dest_30                  string
log_archive_dest_31                  string
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
log_archive_dest_state_10            string      enable
log_archive_dest_state_11            string      enable
log_archive_dest_state_12            string      enable
log_archive_dest_state_13            string      enable
log_archive_dest_state_14            string      enable
log_archive_dest_state_15            string      enable
log_archive_dest_state_16            string      enable
log_archive_dest_state_17            string      enable
log_archive_dest_state_18            string      enable
log_archive_dest_state_19            string      enable
log_archive_dest_state_2             string      DEFER
log_archive_dest_state_20            string      enable
log_archive_dest_state_21            string      enable
log_archive_dest_state_22            string      enable
log_archive_dest_state_23            string      enable
log_archive_dest_state_24            string      enable
log_archive_dest_state_25            string      enable
log_archive_dest_state_26            string      enable
log_archive_dest_state_27            string      enable
log_archive_dest_state_28            string      enable
log_archive_dest_state_29            string      enable
log_archive_dest_state_3             string      DEFER
log_archive_dest_state_30            string      enable
log_archive_dest_state_31            string      enable
log_archive_dest_state_4             string      enable
log_archive_dest_state_5             string      enable
log_archive_dest_state_6             string      enable
log_archive_dest_state_7             string      enable
log_archive_dest_state_8             string      enable
log_archive_dest_state_9             string      enable
log_archive_duplex_dest              string
log_archive_format                   string      %t_%s_%r.dbf
log_archive_local_first              boolean     TRUE
log_archive_max_processes            integer     4
log_archive_min_succeed_dest         integer     1
log_archive_start                    boolean     FALSE
log_archive_trace                    integer     0
log_buffer                           integer     7200768
log_checkpoint_interval              integer     0
log_checkpoint_timeout               integer     1800
log_checkpoints_to_alert             boolean     FALSE
log_file_name_convert                string      +DATA/lunars/, /stage/lunar/
remote_login_passwordfile            string      EXCLUSIVE
sec_case_sensitive_logon             boolean     TRUE
sec_max_failed_login_attempts        integer     10
21:42:34 SYS@lunarp>
21:42:57 SYS@lunarp>alter system set log_archive_dest_state_2=enable;

System altered.

Elapsed: 00:00:00.10
21:43:08 SYS@lunarp>SELECT NAME,DB_UNIQUE_NAME,DATABASE_ROLE,PROTECTION_MODE, SWITCHOVER_STATUS, OPEN_MODE FROM V$DATABASE;

NAME      DB_UNIQUE_NAME                 DATABASE_ROLE    PROTECTION_MODE      SWITCHOVER_STATUS    OPEN_MODE
--------- ------------------------------ ---------------- -------------------- -------------------- --------------------
LUNAR     lunarp                         PRIMARY          MAXIMUM PERFORMANCE  TO STANDBY           READ WRITE

Elapsed: 00:00:00.02
21:43:14 SYS@lunarp>

============================================================================================================
将A库切换为Standby:
============================================================================================================

21:43:14 SYS@lunarp>ALTER SYSTEM SWITCH LOGFILE;

System altered.

Elapsed: 00:00:00.10
21:47:55 SYS@lunarp>select max(sequence#),thread# from v$archived_log group by thread#;

MAX(SEQUENCE#)    THREAD#
-------------- ----------
            37          1

Elapsed: 00:00:00.07
21:48:07 SYS@lunarp>alter database commit to switchover to physical standby WITH SESSION SHUTDOWN;

Database altered.

Elapsed: 00:00:05.62
21:50:59 SYS@lunarp>shutdown immediate;
ORA-01092: ORACLE instance terminated. Disconnection forced
21:51:43 SYS@lunarp>
21:51:55 SYS@lunarp>exit
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning and Real Application Testing options
[oracle@lunar ~]$ ss

SQL*Plus: Release 11.2.0.3.0 Production on Sat Aug 2 21:52:09 2014

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

Welcome Lunar's oracle world!

Connected to an idle instance.

alter session set nls_date_format='yyyy-mm-dd hh24:mi:ss'
*
ERROR at line 1:
ORA-01034: ORACLE not available
Process ID: 0
Session ID: 0 Serial number: 0


Elapsed: 00:00:00.01
21:52:10 SYS@lunarp>startup mount
Welcome Lunar's oracle world!

Love you , baby !

ORACLE instance started.

Total System Global Area  626327552 bytes
Fixed Size                  2230952 bytes
Variable Size             184550744 bytes
Database Buffers          432013312 bytes
Redo Buffers                7532544 bytes
Database mounted.
Welcome Lunar's oracle world!

Love you , baby !

21:52:27 SYS@lunarp>SELECT SWITCHOVER_STATUS FROM V$DATABASE;

SWITCHOVER_STATUS
--------------------
RECOVERY NEEDED

Elapsed: 00:00:00.11
21:52:31 SYS@lunarp>ALTER DATABASE RECOVER MANAGED STANDBY DATABASE DISCONNECT FROM SESSION;

Database altered.

Elapsed: 00:00:06.08
21:52:55 SYS@lunarp>select DATABASE_ROLE,PROTECTION_MODE,PROTECTION_LEVEL from v$database;

DATABASE_ROLE    PROTECTION_MODE      PROTECTION_LEVEL
---------------- -------------------- --------------------
PHYSICAL STANDBY MAXIMUM PERFORMANCE  MAXIMUM PERFORMANCE

Elapsed: 00:00:00.03
21:53:07 SYS@lunarp>

============================================================================================================
3,同理,Cascade不能切换为Primary,也需要enable C库到A库的归档路径:
============================================================================================================

21:50:41 SYS@lunarc>SELECT SWITCHOVER_STATUS FROM V$DATABASE;

SWITCHOVER_STATUS
--------------------
NOT ALLOWED

Elapsed: 00:00:00.07
21:54:21 SYS@lunarc>show parameter log

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
audit_syslog_level                   string
commit_logging                       string
db_create_online_log_dest_1          string
db_create_online_log_dest_2          string
db_create_online_log_dest_3          string
db_create_online_log_dest_4          string
db_create_online_log_dest_5          string
enable_ddl_logging                   boolean     FALSE
log_archive_config                   string      DG_CONFIG=(lunarp,lunars,lunar
                                                 c)
log_archive_dest                     string
log_archive_dest_1                   string      LOCATION=USE_DB_RECOVERY_FILE_
                                                 DEST VALID_FOR=(ALL_LOGFILES,A
                                                 LL_ROLES) DB_UNIQUE_NAME=lunar
                                                 c
log_archive_dest_10                  string
log_archive_dest_11                  string
log_archive_dest_12                  string
log_archive_dest_13                  string
log_archive_dest_14                  string
log_archive_dest_15                  string
log_archive_dest_16                  string
log_archive_dest_17                  string
log_archive_dest_18                  string
log_archive_dest_19                  string
log_archive_dest_2                   string      SERVICE=lunarp LGWR ASYNC AFFI
                                                 RM VALID_FOR=(ONLINE_LOGFILES,
                                                 PRIMARY_ROLE) DB_UNIQUE_NAME=l
                                                 unarp
log_archive_dest_20                  string
log_archive_dest_21                  string
log_archive_dest_22                  string
log_archive_dest_23                  string
log_archive_dest_24                  string
log_archive_dest_25                  string
log_archive_dest_26                  string
log_archive_dest_27                  string
log_archive_dest_28                  string
log_archive_dest_29                  string
log_archive_dest_3                   string      SERVICE=lunars LGWR ASYNC AFFI
                                                 RM VALID_FOR=(STANDBY_LOGFILES
                                                 ,STANDBY_ROLE) DB_UNIQUE_NAME=
                                                 lunars
log_archive_dest_30                  string
log_archive_dest_31                  string
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
log_archive_dest_state_10            string      enable
log_archive_dest_state_11            string      enable
log_archive_dest_state_12            string      enable
log_archive_dest_state_13            string      enable
log_archive_dest_state_14            string      enable
log_archive_dest_state_15            string      enable
log_archive_dest_state_16            string      enable
log_archive_dest_state_17            string      enable
log_archive_dest_state_18            string      enable
log_archive_dest_state_19            string      enable
log_archive_dest_state_2             string      DEFER
log_archive_dest_state_20            string      enable
log_archive_dest_state_21            string      enable
log_archive_dest_state_22            string      enable
log_archive_dest_state_23            string      enable
log_archive_dest_state_24            string      enable
log_archive_dest_state_25            string      enable
log_archive_dest_state_26            string      enable
log_archive_dest_state_27            string      enable
log_archive_dest_state_28            string      enable
log_archive_dest_state_29            string      enable
log_archive_dest_state_3             string      DEFER
log_archive_dest_state_30            string      enable
log_archive_dest_state_31            string      enable
log_archive_dest_state_4             string      enable
log_archive_dest_state_5             string      enable
log_archive_dest_state_6             string      enable
log_archive_dest_state_7             string      enable
log_archive_dest_state_8             string      enable
log_archive_dest_state_9             string      enable
log_archive_duplex_dest              string
log_archive_format                   string      %t_%s_%r.dbf
log_archive_local_first              boolean     TRUE
log_archive_max_processes            integer     4
log_archive_min_succeed_dest         integer     1
log_archive_start                    boolean     FALSE
log_archive_trace                    integer     0
log_buffer                           integer     7200768
log_checkpoint_interval              integer     0
log_checkpoint_timeout               integer     1800
log_checkpoints_to_alert             boolean     FALSE
log_file_name_convert                string      /stage/lunar/, /tempdisk/lunar
                                                 c/
remote_login_passwordfile            string      EXCLUSIVE
sec_case_sensitive_logon             boolean     TRUE
sec_max_failed_login_attempts        integer     10
21:58:35 SYS@lunarc>alter system set log_archive_dest_state_2=enable;         

System altered.

Elapsed: 00:00:00.01
22:00:00 SYS@lunarc>

============================================================================================================
4,还需要B库到C库的归档路径:
============================================================================================================

22:16:17 SYS@lunarc>archive log list
Database log mode              Archive Mode
Automatic archival             Enabled
Archive destination            USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence     34
Next log sequence to archive   0
Current log sequence           35
22:16:34 SYS@lunarc>show parameter log

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
audit_syslog_level                   string
commit_logging                       string
db_create_online_log_dest_1          string
db_create_online_log_dest_2          string
db_create_online_log_dest_3          string
db_create_online_log_dest_4          string
db_create_online_log_dest_5          string
enable_ddl_logging                   boolean     FALSE
log_archive_config                   string      DG_CONFIG=(lunarp,lunars,lunar
                                                 c)
log_archive_dest                     string
log_archive_dest_1                   string      LOCATION=USE_DB_RECOVERY_FILE_
                                                 DEST VALID_FOR=(ALL_LOGFILES,A
                                                 LL_ROLES) DB_UNIQUE_NAME=lunar
                                                 c
log_archive_dest_10                  string
log_archive_dest_11                  string
log_archive_dest_12                  string
log_archive_dest_13                  string
log_archive_dest_14                  string
log_archive_dest_15                  string
log_archive_dest_16                  string
log_archive_dest_17                  string
log_archive_dest_18                  string
log_archive_dest_19                  string
log_archive_dest_2                   string      SERVICE=lunarp LGWR ASYNC AFFI
                                                 RM VALID_FOR=(ONLINE_LOGFILES,
                                                 PRIMARY_ROLE) DB_UNIQUE_NAME=l
                                                 unarp
log_archive_dest_20                  string
log_archive_dest_21                  string
log_archive_dest_22                  string
log_archive_dest_23                  string
log_archive_dest_24                  string
log_archive_dest_25                  string
log_archive_dest_26                  string
log_archive_dest_27                  string
log_archive_dest_28                  string
log_archive_dest_29                  string
log_archive_dest_3                   string      SERVICE=lunars LGWR ASYNC AFFI
                                                 RM VALID_FOR=(STANDBY_LOGFILES
                                                 ,STANDBY_ROLE) DB_UNIQUE_NAME=
                                                 lunars
log_archive_dest_30                  string
log_archive_dest_31                  string
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
log_archive_dest_state_10            string      enable
log_archive_dest_state_11            string      enable
log_archive_dest_state_12            string      enable
log_archive_dest_state_13            string      enable
log_archive_dest_state_14            string      enable
log_archive_dest_state_15            string      enable
log_archive_dest_state_16            string      enable
log_archive_dest_state_17            string      enable
log_archive_dest_state_18            string      enable
log_archive_dest_state_19            string      enable
log_archive_dest_state_2             string      ENABLE
log_archive_dest_state_20            string      enable
log_archive_dest_state_21            string      enable
log_archive_dest_state_22            string      enable
log_archive_dest_state_23            string      enable
log_archive_dest_state_24            string      enable
log_archive_dest_state_25            string      enable
log_archive_dest_state_26            string      enable
log_archive_dest_state_27            string      enable
log_archive_dest_state_28            string      enable
log_archive_dest_state_29            string      enable
log_archive_dest_state_3             string      DEFER
log_archive_dest_state_30            string      enable
log_archive_dest_state_31            string      enable
log_archive_dest_state_4             string      enable
log_archive_dest_state_5             string      enable
log_archive_dest_state_6             string      enable
log_archive_dest_state_7             string      enable
log_archive_dest_state_8             string      enable
log_archive_dest_state_9             string      enable
log_archive_duplex_dest              string
log_archive_format                   string      %t_%s_%r.dbf
log_archive_local_first              boolean     TRUE
log_archive_max_processes            integer     4
log_archive_min_succeed_dest         integer     1
log_archive_start                    boolean     FALSE
log_archive_trace                    integer     0
log_buffer                           integer     7200768
log_checkpoint_interval              integer     0
log_checkpoint_timeout               integer     1800
log_checkpoints_to_alert             boolean     FALSE
log_file_name_convert                string      /stage/lunar/, /tempdisk/lunar
                                                 c/
remote_login_passwordfile            string      EXCLUSIVE
sec_case_sensitive_logon             boolean     TRUE
sec_max_failed_login_attempts        integer     10
22:16:39 SYS@lunarc>show parameter fal

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
fal_client                           string      lunarc
fal_server                           string      lunars, lunarp
22:17:06 SYS@lunarc>SELECT NAME,DB_UNIQUE_NAME,DATABASE_ROLE,PROTECTION_MODE, SWITCHOVER_STATUS, OPEN_MODE FROM V$DATABASE;

NAME      DB_UNIQUE_NAME                 DATABASE_ROLE    PROTECTION_MODE      SWITCHOVER_STATUS    OPEN_MODE
--------- ------------------------------ ---------------- -------------------- -------------------- --------------------
LUNAR     lunarc                         PHYSICAL STANDBY MAXIMUM PERFORMANCE  TO PRIMARY           MOUNTED

Elapsed: 00:00:00.01
22:20:57 SYS@lunarc>archive log list
Database log mode              Archive Mode
Automatic archival             Enabled
Archive destination            USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence     35
Next log sequence to archive   0
Current log sequence           39
22:21:10 SYS@lunarc>

============================================================================================================
将C切换为primary:
============================================================================================================
检查C库:

22:24:47 SYS@lunarc> SELECT NAME,DB_UNIQUE_NAME,DATABASE_ROLE,PROTECTION_MODE, SWITCHOVER_STATUS, OPEN_MODE FROM V$DATABASE;


NAME      DB_UNIQUE_NAME                 DATABASE_ROLE    PROTECTION_MODE      SWITCHOVER_STATUS    OPEN_MODE
--------- ------------------------------ ---------------- -------------------- -------------------- --------------------
LUNAR     lunarc                         PHYSICAL STANDBY MAXIMUM PERFORMANCE  TO PRIMARY           MOUNTED

Elapsed: 00:00:00.04
22:26:26 SYS@lunarc>22:26:26 SYS@lunarc>select max(sequence#),thread# from v$archived_log group by thread#;

MAX(SEQUENCE#)    THREAD#
-------------- ----------
            39          1

Elapsed: 00:00:00.02
22:26:30 SYS@lunarc>

============================================================================================================
检查A库(已经切换为Standby了):
============================================================================================================
21:52:55 SYS@lunarp>select DATABASE_ROLE,PROTECTION_MODE,PROTECTION_LEVEL from v$database;

DATABASE_ROLE    PROTECTION_MODE      PROTECTION_LEVEL
---------------- -------------------- --------------------
PHYSICAL STANDBY MAXIMUM PERFORMANCE  MAXIMUM PERFORMANCE

Elapsed: 00:00:00.03
21:53:07 SYS@lunarp>select max(sequence#),thread# from v$archived_log group by thread#;

MAX(SEQUENCE#)    THREAD#
-------------- ----------
            39          1

Elapsed: 00:00:00.04
22:15:18 SYS@lunarp>

============================================================================================================
检查B库(即将被切换为Cascade):
============================================================================================================

SQL> select max(sequence#),thread# from v$archived_log group by thread#;

MAX(SEQUENCE#)    THREAD#
-------------- ----------
            39          1

SQL>  SELECT NAME,DB_UNIQUE_NAME,DATABASE_ROLE,PROTECTION_MODE, SWITCHOVER_STATUS, OPEN_MODE FROM V$DATABASE;


NAME      DB_UNIQUE_NAME                 DATABASE_ROLE    PROTECTION_MODE
--------- ------------------------------ ---------------- --------------------
SWITCHOVER_STATUS    OPEN_MODE
-------------------- --------------------
LUNAR     lunars                         PHYSICAL STANDBY MAXIMUM PERFORMANCE
NOT ALLOWED          MOUNTED


SQL> SQL> 

============================================================================================================
切换C为primary:
============================================================================================================
22:26:30 SYS@lunarc>alter database recover managed standby database finish;

Database altered.

Elapsed: 00:00:03.19
22:27:58 SYS@lunarc>select max(sequence#),thread# from v$archived_log group by thread#;

MAX(SEQUENCE#)    THREAD#
-------------- ----------
            39          1

Elapsed: 00:00:00.01
22:28:16 SYS@lunarc>SELECT NAME,DB_UNIQUE_NAME,DATABASE_ROLE,PROTECTION_MODE, SWITCHOVER_STATUS, OPEN_MODE FROM V$DATABASE;

NAME      DB_UNIQUE_NAME                 DATABASE_ROLE    PROTECTION_MODE      SWITCHOVER_STATUS    OPEN_MODE
--------- ------------------------------ ---------------- -------------------- -------------------- --------------------
LUNAR     lunarc                         PHYSICAL STANDBY MAXIMUM PERFORMANCE  TO PRIMARY           MOUNTED


Elapsed: 00:00:00.01
22:28:34 SYS@lunarc>22:28:34 SYS@lunarc>ALTER DATABASE COMMIT TO SWITCHOVER TO PRIMARY WITH SESSION SHUTDOWN;


Database altered.

Elapsed: 00:00:02.75
22:28:52 SYS@lunarc>22:28:52 SYS@lunarc>

测试C库的alert:
Sat Aug 02 22:27:55 2014
alter database recover managed standby database finish
Terminal Recovery: Stopping real time apply
Sat Aug 02 22:27:55 2014
MRP0: Background Media Recovery cancelled with status 16037
Errors in file /u01/app/oracle/diag/rdbms/lunarc/lunarc/trace/lunarc_pr00_19297.trc:
ORA-16037: user requested cancel of managed recovery operation
Managed Standby Recovery not using Real Time Apply
Recovery interrupted!
Sat Aug 02 22:27:55 2014
MRP0: Background Media Recovery process shutdown (lunarc)
Terminal Recovery: Stopped real time apply
Attempt to do a Terminal Recovery (lunarc)
Media Recovery Start: Managed Standby Recovery (lunarc)
 started logmerger process
Sat Aug 02 22:27:56 2014
Managed Standby Recovery not using Real Time Apply
Parallel Media Recovery started with 2 slaves
Media Recovery Waiting for thread 1 sequence 40
RECOVER FINISH applied through switchover EOR logs and stopped.
Media Recovery Complete: End-Of-REDO (lunarc)
Attempt to set limbo arscn 0:1362521 irscn 0:1362521 
Completed: alter database recover managed standby database finish
Sat Aug 02 22:28:49 2014
ALTER DATABASE COMMIT TO SWITCHOVER TO PRIMARY WITH SESSION SHUTDOWN
ALTER DATABASE SWITCHOVER TO PRIMARY (lunarc)
Maximum wait for role transition is 15 minutes.
krsv_proc_kill: Killing 4 processes (all RFS)
Backup controlfile written to trace file /u01/app/oracle/diag/rdbms/lunarc/lunarc/trace/lunarc_ora_18445.trc
SwitchOver after complete recovery through change 1362521
Online log /tempdisk/lunarc/redo01.log: Thread 1 Group 1 was previously cleared
Online log /tempdisk/lunarc/redo02.log: Thread 1 Group 2 was previously cleared
Online log /tempdisk/lunarc/redo03.log: Thread 1 Group 3 was previously cleared
Standby became primary SCN: 1362519
Switchover: Complete - Database mounted as primary
Completed: ALTER DATABASE COMMIT TO SWITCHOVER TO PRIMARY WITH SESSION SHUTDOWN
Sat Aug 02 22:29:12 2014
RFS[10]: Assigned to RFS process 19349
RFS[10]: Database mount ID mismatch [0x92fd5f55:0x92fca1ab] (2466078549:2466029995)
RFS[10]: Client instance is standby database instead of primary
RFS[10]: Not using real application clusters
Sat Aug 02 22:29:41 2014
ARC0: Becoming the 'no SRL' ARCH

然后,重启C库:

22:28:52 SYS@lunarc>22:28:52 SYS@lunarc>shutdown immediate;
ORA-01109: database not open


Database dismounted.
ORACLE instance shut down.
22:30:35 SYS@lunarc>startup
Welcome Lunar's oracle world!

Love you , baby !

ORACLE instance started.

Total System Global Area  626327552 bytes
Fixed Size                  2230952 bytes
Variable Size             184550744 bytes
Database Buffers          432013312 bytes
Redo Buffers                7532544 bytes
Database mounted.
Welcome Lunar's oracle world!

Love you , baby !

Database opened.

此时,C库的日志:

Sat Aug 02 22:30:37 2014
Starting ORACLE instance (normal)
****************** Large Pages Information *****************
 
Total Shared Global Region in Large Pages = 0 KB (0%)
 
Large Pages used by this instance: 0 (0 KB)
Large Pages unused system wide = 0 (0 KB) (alloc incr 4096 KB)
Large Pages configured system wide = 0 (0 KB)
Large Page size = 2048 KB
 
RECOMMENDATION:
  Total Shared Global Region size is 602 MB. For optimal performance,
  prior to the next instance restart increase the number
  of unused Large Pages by atleast 301 2048 KB Large Pages (602 MB)
  system wide to get 100% of the Shared
  Global Region allocated with Large pages
***********************************************************
LICENSE_MAX_SESSION = 0
LICENSE_SESSIONS_WARNING = 0
Picked latch-free SCN scheme 3
Autotune of undo retention is turned on. 
IMODE=BR
ILAT =27
LICENSE_MAX_USERS = 0
SYS auditing is disabled
Starting up:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning and Real Application Testing options.
ORACLE_HOME = /u01/app/oracle/product/11.2.0.3/dbhome_1
System name:    Linux
Node name:      lunar
Release:        2.6.32-300.10.1.el5uek
Version:        #1 SMP Wed Feb 22 17:37:40 EST 2012
Machine:        x86_64
Using parameter settings in server-side spfile /u01/app/oracle/product/11.2.0.3/dbhome_1/dbs/spfilelunarc.ora
System parameters with non-default values:
  processes                = 150
  filesystemio_options     = "setall"
  sga_target               = 600M
  control_files            = "/tempdisk/lunarc/control01.ctl"
  control_files            = "/tempdisk/lunarc/control02.ctl"
  db_file_name_convert     = "/stage/lunar/"
  db_file_name_convert     = "/tempdisk/lunarc/"
  log_file_name_convert    = "/stage/lunar/"
  log_file_name_convert    = "/tempdisk/lunarc/"
  db_block_size            = 8192
  compatible               = "11.2.0.3.0"
  log_archive_dest_1       = "LOCATION=USE_DB_RECOVERY_FILE_DEST VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=lunarc"
  log_archive_dest_2       = "SERVICE=lunarp LGWR SYNC AFFIRM VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=lunarp"
  log_archive_dest_state_1 = "ENABLE"
  log_archive_dest_state_2 = "ENABLE"
  log_archive_dest_state_3 = "ENABLE"
  fal_client               = "lunarc"
  fal_server               = "lunars"
  fal_server               = "lunarp"
  log_archive_config       = "DG_CONFIG=(lunarp,lunars,lunarc)"
  db_recovery_file_dest    = "/stage/fast_recovery_area"
  db_recovery_file_dest_size= 1190198K
  standby_file_management  = "auto"
  undo_tablespace          = "UNDOTBS1"
  remote_login_passwordfile= "EXCLUSIVE"
  db_domain                = ""
  service_names            = "lunar"
  audit_file_dest          = "/u01/app/oracle/admin/lunarc/adump"
  audit_trail              = "NONE"
  db_name                  = "lunar"
  db_unique_name           = "lunarc"
  open_cursors             = 300
  pga_aggregate_target     = 146M
  deferred_segment_creation= FALSE
  sec_return_server_release_banner= FALSE
  diagnostic_dest          = "/u01/app/oracle"
Sat Aug 02 22:30:38 2014
PMON started with pid=2, OS id=19357 
Sat Aug 02 22:30:38 2014
PSP0 started with pid=3, OS id=19359 
Sat Aug 02 22:30:39 2014
VKTM started with pid=4, OS id=19361 at elevated priority
VKTM running at (1)millisec precision with DBRM quantum (100)ms
Sat Aug 02 22:30:40 2014
GEN0 started with pid=5, OS id=19365 
Sat Aug 02 22:30:40 2014
DIAG started with pid=6, OS id=19367 
Sat Aug 02 22:30:40 2014
DBRM started with pid=7, OS id=19369 
Sat Aug 02 22:30:40 2014
DIA0 started with pid=8, OS id=19371 
Sat Aug 02 22:30:40 2014
MMAN started with pid=9, OS id=19373 
Sat Aug 02 22:30:40 2014
DBW0 started with pid=10, OS id=19375 
Sat Aug 02 22:30:40 2014
LGWR started with pid=11, OS id=19377 
Sat Aug 02 22:30:40 2014
CKPT started with pid=12, OS id=19379 
Sat Aug 02 22:30:40 2014
SMON started with pid=13, OS id=19381 
Sat Aug 02 22:30:40 2014
RECO started with pid=14, OS id=19383 
Sat Aug 02 22:30:40 2014
MMON started with pid=15, OS id=19385 
Sat Aug 02 22:30:40 2014
MMNL started with pid=16, OS id=19387 
ORACLE_BASE from environment = /u01/app/oracle
Sat Aug 02 22:30:40 2014
ALTER DATABASE   MOUNT
Sat Aug 02 22:30:45 2014
NSS2 started with pid=18, OS id=19394 
Successful mount of redo thread 1, with mount id 2466039952
Database mounted in Exclusive Mode
Lost write protection disabled
Completed: ALTER DATABASE   MOUNT
Sat Aug 02 22:30:45 2014
ALTER DATABASE OPEN
Assigning activation ID 2466039952 (0x92fcc890)
LGWR: STARTING ARCH PROCESSES
Sat Aug 02 22:30:46 2014
ARC0 started with pid=21, OS id=19401 
ARC0: Archival started
LGWR: STARTING ARCH PROCESSES COMPLETE
ARC0: STARTING ARCH PROCESSES
Destination LOG_ARCHIVE_DEST_2 is UNSYNCHRONIZED
Sat Aug 02 22:30:47 2014
ARC1 started with pid=19, OS id=19403 
Sat Aug 02 22:30:47 2014
ARC2 started with pid=20, OS id=19405 
Thread 1 advanced to log sequence 41 (thread open)
Sat Aug 02 22:30:47 2014
ARC3 started with pid=22, OS id=19407 
ARC1: Archival started
ARC2: Archival started
ARC2: Becoming the 'no FAL' ARCH
ARC2: Becoming the 'no SRL' ARCH
ARC1: Becoming the heartbeat ARCH
Thread 1 opened at log sequence 41
  Current log# 2 seq# 41 mem# 0: /tempdisk/lunarc/redo02.log
Successful open of redo thread 1
MTTR advisory is disabled because FAST_START_MTTR_TARGET is not set
SMON: enabling cache recovery
Archived Log entry 33 added for thread 1 sequence 40 ID 0x92fcc890 dest 1:
ARC3: Archival started
ARC0: STARTING ARCH PROCESSES COMPLETE
Sat Aug 02 22:30:50 2014
Destination LOG_ARCHIVE_DEST_2 is SYNCHRONIZED
******************************************************************
LGWR: Setting 'active' archival for destination LOG_ARCHIVE_DEST_2
******************************************************************
Destination LOG_ARCHIVE_DEST_2 no longer supports SYNCHRONIZATION
Thread 1 advanced to log sequence 42 (LGWR switch)
  Current log# 3 seq# 42 mem# 0: /tempdisk/lunarc/redo03.log
Archived Log entry 35 added for thread 1 sequence 41 ID 0x92fcc890 dest 1:
[19395] Successfully onlined Undo Tablespace 2.
Undo initialization finished serial:0 start:99886074 end:99887784 diff:1710 (17 seconds)
Dictionary check beginning
Sat Aug 02 22:30:52 2014
Errors in file /u01/app/oracle/diag/rdbms/lunarc/lunarc/trace/lunarc_dbw0_19375.trc:
ORA-01157: cannot identify/lock data file 201 - see DBWR trace file
ORA-01110: data file 201: '/tempdisk/lunarc/temp01.dbf'
ORA-27037: unable to obtain file status
Linux-x86_64 Error: 2: No such file or directory
Additional information: 3
Errors in file /u01/app/oracle/diag/rdbms/lunarc/lunarc/trace/lunarc_dbw0_19375.trc:
ORA-01186: file 201 failed verification tests
ORA-01157: cannot identify/lock data file 201 - see DBWR trace file
ORA-01110: data file 201: '/tempdisk/lunarc/temp01.dbf'
File 201 not verified due to error ORA-01157
Dictionary check complete
Verifying file header compatibility for 11g tablespace encryption..
Verifying 11g file header compatibility for tablespace encryption completed
Sat Aug 02 22:30:52 2014
SMON: enabling tx recovery
Re-creating tempfile /tempdisk/lunarc/temp01.dbf    ---重建了temp表空间的数据文件
Database Characterset is AL32UTF8
No Resource Manager plan active
Sat Aug 02 22:30:56 2014
replication_dependency_tracking turned off (no async multimaster replication found)
Starting background process QMNC
Sat Aug 02 22:30:58 2014
QMNC started with pid=23, OS id=19421 
LOGSTDBY: Validating controlfile with logical metadata
LOGSTDBY: Validation complete
Completed: ALTER DATABASE OPEN
Sat Aug 02 22:31:05 2014
Starting background process CJQ0
Sat Aug 02 22:31:06 2014
CJQ0 started with pid=25, OS id=19435 
Sat Aug 02 22:31:07 2014
db_recovery_file_dest_size of 1162 MB is 33.81% used. This is a
user-specified limit on the amount of space that will be used by this
database for recovery-related files, and does not reflect the amount of
space available in the underlying filesystem or ASM diskgroup.
Sat Aug 02 22:31:47 2014
ARC1: STARTING ARCH PROCESSES
Sat Aug 02 22:31:47 2014
ARC4 started with pid=27, OS id=19445 
ARC4: Archival started
ARC1: STARTING ARCH PROCESSES COMPLETE
Shutting down archive processes
ARCH shutting down
ARC4: Archival stopped

切换后的C库(已经切换为primary了):

22:33:15 SYS@lunarc>SELECT SWITCHOVER_STATUS FROM V$DATABASE;

SWITCHOVER_STATUS
--------------------
TO STANDBY

Elapsed: 00:00:00.18
22:33:23 SYS@lunarc> ALTER SYSTEM SWITCH LOGFILE;

System altered.

Elapsed: 00:00:00.26
22:33:31 SYS@lunarc>select DATABASE_ROLE,PROTECTION_MODE,PROTECTION_LEVEL from v$database;

DATABASE_ROLE    PROTECTION_MODE      PROTECTION_LEVEL
---------------- -------------------- --------------------
PRIMARY          MAXIMUM PERFORMANCE  MAXIMUM PERFORMANCE

Elapsed: 00:00:00.02
22:33:55 SYS@lunarc>select thread#,max(sequence#) from v$archived_log group by thread#;

   THREAD# MAX(SEQUENCE#)
---------- --------------
         1             42

Elapsed: 00:00:00.11
22:34:02 SYS@lunarc>

此时A库的日志(已经切换为Standby)了:

Sat Aug 02 22:07:24 2014
db_recovery_file_dest_size of 1162 MB is 13.66% used. This is a
user-specified limit on the amount of space that will be used by this
database for recovery-related files, and does not reflect the amount of
space available in the underlying filesystem or ASM diskgroup.
Sat Aug 02 22:30:48 2014
Using STANDBY_ARCHIVE_DEST parameter default value as USE_DB_RECOVERY_FILE_DEST
Sat Aug 02 22:30:49 2014
RFS[1]: Assigned to RFS process 19415
RFS[1]: Opened log for thread 1 sequence 40 dbid -1830388907 branch 853060791
Archived Log entry 72 added for thread 1 sequence 40 rlc 853060791 ID 0x92fcc890 dest 2:
Sat Aug 02 22:30:50 2014
Primary database is in MAXIMUM PERFORMANCE mode
RFS[2]: Assigned to RFS process 19417
RFS[2]: No standby redo logfiles created
RFS[2]: Opened log for thread 1 sequence 42 dbid -1830388907 branch 853060791
Sat Aug 02 22:30:51 2014
Media Recovery Log /stage/fast_recovery_area/LUNARP/archivelog/2014_08_02/o1_mf_1_40_9xvorstf_.arc
Media Recovery Waiting for thread 1 sequence 41 (in transit)
Sat Aug 02 22:30:51 2014
RFS[3]: Assigned to RFS process 19419
RFS[3]: Opened log for thread 1 sequence 41 dbid -1830388907 branch 853060791
Archived Log entry 73 added for thread 1 sequence 41 rlc 853060791 ID 0x92fcc890 dest 2:
Media Recovery Log /stage/fast_recovery_area/LUNARP/archivelog/2014_08_02/o1_mf_1_41_9xvorvo0_.arc
Media Recovery Waiting for thread 1 sequence 42 (in transit)
Sat Aug 02 22:33:30 2014
Archived Log entry 74 added for thread 1 sequence 42 rlc 853060791 ID 0x92fcc890 dest 2:
RFS[2]: No standby redo logfiles created
RFS[2]: Opened log for thread 1 sequence 43 dbid -1830388907 branch 853060791
Sat Aug 02 22:33:32 2014
Media Recovery Log /stage/fast_recovery_area/LUNARP/archivelog/2014_08_02/o1_mf_1_42_9xvorv1t_.arc
Media Recovery Waiting for thread 1 sequence 43 (in transit)

调整一下A库的fal参数:

22:15:18 SYS@lunarp>show parameter fal

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
fal_client                           string      lunarp
fal_server                           string      lunars
22:38:18 SYS@lunarp>alter system set fal_server='lunarc';

System altered.

Elapsed: 00:00:00.08
22:38:44 SYS@lunarp>show parameter fal

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
fal_client                           string      lunarp
fal_server                           string      lunarc
22:38:58 SYS@lunarp>

============================================================================================================
5,B库,将被切换为Cascade,此时需要先修改归档参数,取消B到A和B到C的归档
============================================================================================================

SQL> SELECT NAME,DB_UNIQUE_NAME,DATABASE_ROLE,PROTECTION_MODE, SWITCHOVER_STATUS, OPEN_MODE FROM V$DATABASE;

NAME      DB_UNIQUE_NAME                 DATABASE_ROLE    PROTECTION_MODE
--------- ------------------------------ ---------------- --------------------
SWITCHOVER_STATUS    OPEN_MODE
-------------------- --------------------
LUNAR     lunars                         PHYSICAL STANDBY MAXIMUM PERFORMANCE
NOT ALLOWED          MOUNTED


SQL> show parameter log

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
audit_syslog_level                   string
commit_logging                       string
db_create_online_log_dest_1          string      +DATA
db_create_online_log_dest_2          string
db_create_online_log_dest_3          string
db_create_online_log_dest_4          string
db_create_online_log_dest_5          string
enable_ddl_logging                   boolean     FALSE
log_archive_config                   string      DG_CONFIG=(lunarp,lunars,lunar
                                                 c)
log_archive_dest                     string

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
log_archive_dest_1                   string      LOCATION=USE_DB_RECOVERY_FILE_
                                                 DEST VALID_FOR=(ALL_LOGFILES,A
                                                 LL_ROLES) DB_UNIQUE_NAME=lunar
                                                 s
log_archive_dest_10                  string
log_archive_dest_11                  string
log_archive_dest_12                  string
log_archive_dest_13                  string
log_archive_dest_14                  string
log_archive_dest_15                  string
log_archive_dest_16                  string

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
log_archive_dest_17                  string
log_archive_dest_18                  string
log_archive_dest_19                  string
log_archive_dest_2                   string      SERVICE=lunarp LGWR SYNC AFFIR
                                                 M VALID_FOR=(ONLINE_LOGFILES,P
                                                 RIMARY_ROLE) DB_UNIQUE_NAME=lu
                                                 narp
log_archive_dest_20                  string
log_archive_dest_21                  string
log_archive_dest_22                  string
log_archive_dest_23                  string

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
log_archive_dest_24                  string
log_archive_dest_25                  string
log_archive_dest_26                  string
log_archive_dest_27                  string
log_archive_dest_28                  string
log_archive_dest_29                  string
log_archive_dest_3                   string      SERVICE=lunarc LGWR SYNC AFFIR
                                                 M VALID_FOR=(STANDBY_LOGFILES,
                                                 STANDBY_ROLE) DB_UNIQUE_NAME=l
                                                 unarc
log_archive_dest_30                  string

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
log_archive_dest_31                  string
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
log_archive_dest_state_10            string      enable
log_archive_dest_state_11            string      enable
log_archive_dest_state_12            string      enable

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
log_archive_dest_state_13            string      enable
log_archive_dest_state_14            string      enable
log_archive_dest_state_15            string      enable
log_archive_dest_state_16            string      enable
log_archive_dest_state_17            string      enable
log_archive_dest_state_18            string      enable
log_archive_dest_state_19            string      enable
log_archive_dest_state_2             string      ENABLE
log_archive_dest_state_20            string      enable
log_archive_dest_state_21            string      enable
log_archive_dest_state_22            string      enable

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
log_archive_dest_state_23            string      enable
log_archive_dest_state_24            string      enable
log_archive_dest_state_25            string      enable
log_archive_dest_state_26            string      enable
log_archive_dest_state_27            string      enable
log_archive_dest_state_28            string      enable
log_archive_dest_state_29            string      enable
log_archive_dest_state_3             string      ENABLE
log_archive_dest_state_30            string      enable
log_archive_dest_state_31            string      enable
log_archive_dest_state_4             string      enable

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
log_archive_dest_state_5             string      enable
log_archive_dest_state_6             string      enable
log_archive_dest_state_7             string      enable
log_archive_dest_state_8             string      enable
log_archive_dest_state_9             string      enable
log_archive_duplex_dest              string
log_archive_format                   string      %t_%s_%r.dbf
log_archive_local_first              boolean     TRUE
log_archive_max_processes            integer     4
log_archive_min_succeed_dest         integer     1
log_archive_start                    boolean     FALSE

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
log_archive_trace                    integer     0
log_buffer                           integer     7176192
log_checkpoint_interval              integer     0
log_checkpoint_timeout               integer     1800
log_checkpoints_to_alert             boolean     FALSE
log_file_name_convert                string      /stage/lunar/, +DATA/lunars/
remote_login_passwordfile            string      EXCLUSIVE
sec_case_sensitive_logon             boolean     TRUE
sec_max_failed_login_attempts        integer     10
SQL> alter system set log_archive_dest_3='';

System altered.

SQL> alter system set log_archive_dest_state_3=defer;

System altered.

SQL> 

日志没有同步完成,需要检查日志的同步情况:

SQL> SELECT SWITCHOVER_STATUS FROM V$DATABASE;

SWITCHOVER_STATUS
--------------------
NOT ALLOWED

SQL> select max(sequence#),thread# from v$archived_log group by thread#;

MAX(SEQUENCE#)    THREAD#
-------------- ----------
            39          1

SQL> show parameter fal

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
fal_client                           string      lunars
fal_server                           string      lunarp
SQL> alter system set fal_server='lunarp','lunarc';

System altered.

SQL>  show parameter fal

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
fal_client                           string      lunars
fal_server                           string      lunarp, lunarc
SQL> 

============================================================================================================
修改A库(已经切换为Standby了)参数:
============================================================================================================

alter system set log_archive_dest_2='';
alter system set log_archive_dest_3='';

alter system set log_archive_dest_2='SERVICE=lunarc LGWR ASYNC AFFIRM VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=lunarc';
alter system set log_archive_dest_state_2=enable;

alter system set log_archive_dest_3='SERVICE=lunars LGWR ASYNC AFFIRM VALID_FOR=(STANDBY_LOGFILES,STANDBY_ROLE) DB_UNIQUE_NAME=lunars';
alter system set log_archive_dest_state_3=enable;

如果还有问题,可以执行下面的(本次没等执行,已经好了):

alter system set log_archive_dest_state_2=defer;
alter system set log_archive_dest_state_3=defer;

alter system set log_archive_dest_state_2=enable;
alter system set log_archive_dest_state_3=enable;

此时原来C库的日志(已经从Cascade Standby切换为primart了):

22:59:48 SYS@lunarc>alter system switch logfile;

System altered.

Elapsed: 00:00:00.19
23:06:22 SYS@lunarc>select thread#,max(sequence#) from v$archived_log group by thread#;

   THREAD# MAX(SEQUENCE#)
---------- --------------
         1             48

Elapsed: 00:00:00.04
23:06:57 SYS@lunarc>select thread#,applied,max(sequence#) from v$archived_log where applied='YES' group by thread#,applied;

   THREAD# APPLIED   MAX(SEQUENCE#)
---------- --------- --------------
         1 YES                   48

Elapsed: 00:00:00.05
23:13:00 SYS@lunarc>

日志如下:

Sat Aug 02 22:59:50 2014
Destination LOG_ARCHIVE_DEST_2 is SYNCHRONIZED
Destination LOG_ARCHIVE_DEST_2 no longer supports SYNCHRONIZATION
Thread 1 advanced to log sequence 48 (LGWR switch)
  Current log# 3 seq# 48 mem# 0: /tempdisk/lunarc/redo03.log
Sat Aug 02 22:59:51 2014
Archived Log entry 48 added for thread 1 sequence 47 ID 0x92fcc890 dest 1:
Sat Aug 02 23:06:22 2014
Destination LOG_ARCHIVE_DEST_2 is SYNCHRONIZED
Destination LOG_ARCHIVE_DEST_2 no longer supports SYNCHRONIZATION
Thread 1 advanced to log sequence 49 (LGWR switch)
  Current log# 1 seq# 49 mem# 0: /tempdisk/lunarc/redo01.log
Sat Aug 02 23:06:23 2014
Archived Log entry 50 added for thread 1 sequence 48 ID 0x92fcc890 dest 1:

此时的A库(已经从Primary切换为Standby了):

23:04:56 SYS@lunarp>select thread#,max(sequence#) from v$archived_log group by thread#;

   THREAD# MAX(SEQUENCE#)
---------- --------------
         1             48

Elapsed: 00:00:00.06
23:07:00 SYS@lunarp>select thread#,applied,max(sequence#) from v$archived_log where applied='YES' group by thread#,applied;

   THREAD# APPLIED   MAX(SEQUENCE#)
---------- --------- --------------
         1 YES                   48

Elapsed: 00:00:00.04
23:12:57 SYS@lunarp>

Sat Aug 02 23:06:22 2014
Archived Log entry 88 added for thread 1 sequence 48 rlc 853060791 ID 0x92fcc890 dest 2:
RFS[2]: No standby redo logfiles created
RFS[2]: Opened log for thread 1 sequence 49 dbid -1830388907 branch 853060791
Sat Aug 02 23:06:27 2014
Media Recovery Log /stage/fast_recovery_area/LUNARP/archivelog/2014_08_02/o1_mf_1_48_9xvqh6hl_.arc
Media Recovery Waiting for thread 1 sequence 49 (in transit)

此时的B库(已经切换为Standby 切换为Cascade Standby了)

SQL> select thread#,max(sequence#) from v$archived_log group by thread#;

   THREAD# MAX(SEQUENCE#)
---------- --------------
         1             48

SQL> recover managed standby database cancel;
ORA-16136: Managed Standby Recovery not active


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

Database altered.

SQL> 
SQL> select thread#,applied,max(sequence#) from v$archived_log where applied='YES' group by thread#,applied;

   THREAD# APPLIED   MAX(SEQUENCE#)
---------- --------- --------------
         1 YES                   48

SQL> 

Sun Aug 03 07:06:34 2014
RFS[8]: Opened log for thread 1 sequence 48 dbid -1830388907 branch 853060791
Archived Log entry 75 added for thread 1 sequence 48 rlc 853060791 ID 0x92fcc890 dest 3:
Sun Aug 03 07:11:34 2014
ALTER DATABASE RECOVER  managed standby database cancel  
ORA-16136 signalled during: ALTER DATABASE RECOVER  managed standby database cancel  ...
Sun Aug 03 07:11:45 2014
alter database recover managed standby database using current logfile disconnect from session
Attempt to start background Managed Standby Recovery process (lunars)
Sun Aug 03 07:11:45 2014
MRP0 started with pid=34, OS id=20717 
MRP0: Background Managed Standby Recovery process started (lunars)
 started logmerger process
Sun Aug 03 07:11:50 2014
Managed Standby Recovery starting Real Time Apply
Parallel Media Recovery started with 2 slaves
Waiting for all non-current ORLs to be archived...
All non-current ORLs have been archived.
Media Recovery Log /stage/fast_recovery_area/LUNARS/archivelog/2014_08_02/o1_mf_1_31_9xsv85l5_.arc
Completed: alter database recover managed standby database using current logfile disconnect from session
Media Recovery Log /stage/fast_recovery_area/LUNARS/archivelog/2014_08_02/o1_mf_1_32_9xsv879v_.arc
Media Recovery Log /stage/fast_recovery_area/LUNARS/archivelog/2014_08_03/o1_mf_1_33_9xto475l_.arc
Media Recovery Log /stage/fast_recovery_area/LUNARS/archivelog/2014_08_03/o1_mf_1_34_9xto4q5w_.arc
Sun Aug 03 07:12:01 2014
Media Recovery Log /stage/fast_recovery_area/LUNARS/archivelog/2014_08_03/o1_mf_1_35_9xtp69j7_.arc
Media Recovery Log /stage/fast_recovery_area/LUNARS/archivelog/2014_08_03/o1_mf_1_36_9xtpvoj1_.arc
Media Recovery Log /stage/fast_recovery_area/LUNARS/archivelog/2014_08_03/o1_mf_1_37_9xtq4hwb_.arc
Media Recovery Log /stage/fast_recovery_area/LUNARS/archivelog/2014_08_03/o1_mf_1_38_9xtqb2lp_.arc
Media Recovery Log /stage/fast_recovery_area/LUNARS/archivelog/2014_08_03/o1_mf_1_39_9xtqb7l9_.arc
Identified End-Of-Redo (switchover) for thread 1 sequence 39 at SCN 0x0.14ca59
Resetting standby activation ID 2464533536 (0x92e5cc20)
Media Recovery End-Of-Redo indicator encountered
Media Recovery Continuing
Media Recovery Log /stage/fast_recovery_area/LUNARS/archivelog/2014_08_03/o1_mf_1_40_9xtvowds_.arc
Media Recovery Log /stage/fast_recovery_area/LUNARS/archivelog/2014_08_03/o1_mf_1_41_9xtvowk2_.arc
Media Recovery Log /stage/fast_recovery_area/LUNARS/archivelog/2014_08_03/o1_mf_1_42_9xtvow7w_.arc
Media Recovery Log /stage/fast_recovery_area/LUNARS/archivelog/2014_08_03/o1_mf_1_43_9xtvowj5_.arc
Media Recovery Log /stage/fast_recovery_area/LUNARS/archivelog/2014_08_03/o1_mf_1_44_9xtvownm_.arc
Media Recovery Log /stage/fast_recovery_area/LUNARS/archivelog/2014_08_03/o1_mf_1_45_9xtvowop_.arc
Media Recovery Log /stage/fast_recovery_area/LUNARS/archivelog/2014_08_03/o1_mf_1_46_9xtvowqg_.arc
Media Recovery Log /stage/fast_recovery_area/LUNARS/archivelog/2014_08_03/o1_mf_1_47_9xtvowtt_.arc
Media Recovery Log /stage/fast_recovery_area/LUNARS/archivelog/2014_08_03/o1_mf_1_48_9xtvqtdm_.arc
Media Recovery Waiting for thread 1 sequence 49
发表在 Dataguard | 标签为 , , | 留下评论

Linux上,使用screen在后台执行scp(或者其他长时间的操作)

如果有些操作需要长时间执行,没有vnc的时候(也不通过写脚本的方式,比如scp命令),那么可以通过screen放到后台操作:
在OEL 5.8上缺省就安装了screen,但是在OEL 5.10上,需要自己单独安装。
下面,我使用Oracle的yum源安装screen:

[root@lunar ~]# cd /etc/yum.repos.d
[root@lunar yum.repos.d]# wget http://public-yum.oracle.com/public-yum-el5.repo
--2014-08-02 16:36:47--  http://public-yum.oracle.com/public-yum-el5.repo
Resolving public-yum.oracle.com... 198.172.88.104
Connecting to public-yum.oracle.com|198.172.88.104|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 4550 (4.4K) 1
Saving to: `public-yum-el5.repo.2'

100%[=============================================================================================================================>] 4,550       --.-K/s   in 0s      

2014-08-02 16:36:51 (80.1 MB/s) - `public-yum-el5.repo.2' saved [4550/4550]

[root@lunar yum.repos.d]# yum install screen*
Loaded plugins: rhnplugin, security
This system is not registered with ULN.
You can use up2date --register to register.
ULN support will be disabled.
el5_latest                                                                                                                                      | 1.4 kB     00:00     
ol5_UEK_latest                                                                                                                                  | 1.2 kB     00:00     
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package screen.x86_64 0:4.0.3-4.el5 set to be updated
--> Finished Dependency Resolution

Dependencies Resolved

=======================================================================================================================================================================
 Package                              Arch                                 Version                                      Repository                                Size
=======================================================================================================================================================================
Installing:
 screen                               x86_64                               4.0.3-4.el5                                  el5_latest                               571 k

Transaction Summary
=======================================================================================================================================================================
Install       1 Package(s)
Upgrade       0 Package(s)

Total download size: 571 k
Is this ok [y/N]: y
Downloading Packages:
screen-4.0.3-4.el5.x86_64.rpm                                                                                                                   | 571 kB     00:03     
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing     : screen                                                                                                                                          1/1 

Installed:
  screen.x86_64 0:4.0.3-4.el5                                                                                                                                          

Complete!
[root@lunar yum.repos.d]# 

scp oracle@192.168.56.66:/tmp/lunarstb.pfile .
scp oracle@192.168.56.66:/tmp/lunar.stb.ctl .

下面的例子就是使用screen在后台创建窗口,执行scp传输rman备份集:
首先可以创建一个窗口,起名字为lunar(可以开多个窗口):

[root@lunar ~]# screen -S lunar

接着,你会看到一个全新的shell:


[root@lunar ~]# su - oracle
[oracle@lunar ~]$ . lunar.env 
[oracle@lunar ~]$ env|grep ORA
ORACLE_SID=lunar
ORACLE_BASE=/u01/app/oracle
ORACLE_HOME=/u01/app/oracle/product/11.2.0.3/dbhome_1
[oracle@lunar ~]$ cd /stage
[oracle@lunar stage]$ cd backup
[oracle@lunar backup]$ ls
arch_0hpdl9i1_1_1.rman  arch_0jpdl9i5_1_1.rman  bk.sql                  full_0fpdl9gl_1_1.rman  pfile_lunar.ora
arch_0ipdl9i1_1_1.rman  bk.log                  full_0epdl9gl_1_1.rman  full_0gpdl9ho_1_1.rman  PRIMA_CONTROL.bkp
[oracle@lunar backup]$ ll
total 165412
-rw-r----- 1 oracle oinstall  5302272 Jul 17 21:16 arch_0hpdl9i1_1_1.rman
-rw-r----- 1 oracle oinstall 23611392 Jul 17 21:16 arch_0ipdl9i1_1_1.rman
-rw-r----- 1 oracle oinstall 11265024 Jul 17 21:16 arch_0jpdl9i5_1_1.rman
-rw-r--r-- 1 oracle oinstall     5155 Jul 17 21:16 bk.log
-rw-r--r-- 1 oracle oinstall      405 Jul 17 21:15 bk.sql
-rw-r----- 1 oracle oinstall 56680448 Jul 17 21:16 full_0epdl9gl_1_1.rman
-rw-r----- 1 oracle oinstall 61087744 Jul 17 21:16 full_0fpdl9gl_1_1.rman
-rw-r----- 1 oracle oinstall  1114112 Jul 17 21:16 full_0gpdl9ho_1_1.rman
-rw-r--r-- 1 oracle oinstall      624 Jul 17 21:32 pfile_lunar.ora
-rw-r----- 1 oracle oinstall 10092544 Jul 17 21:16 PRIMA_CONTROL.bkp
[oracle@lunar backup]$ scp * oracle@192.168.56.26:/stage/backup/
oracle@192.168.56.26's password: 

[detached]

按Ctrl+a+d,就可以讲这个窗口detached。
然后使用screen -ls可以看到刚才的窗口的进程号等信息:
[root@lunar ~]# screen -ls
There is a screen on:
11012.lunar (Detached)
1 Socket in /var/run/screen/S-root.

[root@lunar ~]# ps -ef|grep 11012
root 11012 1 0 08:10 ? 00:00:00 SCREEN -S lunar
root 11013 11012 0 08:10 pts/2 00:00:00 /bin/bash
root 11087 10627 0 08:14 pts/0 00:00:00 grep 11012
使用screen -r pid可以继续大刚才的窗口中:

[root@lunar ~]# screen -r 11012
[oracle@lunar stage]$ cd backup
[oracle@lunar backup]$ ls
arch_0hpdl9i1_1_1.rman  arch_0jpdl9i5_1_1.rman  bk.sql                  full_0fpdl9gl_1_1.rman  pfile_lunar.ora
arch_0ipdl9i1_1_1.rman  bk.log                  full_0epdl9gl_1_1.rman  full_0gpdl9ho_1_1.rman  PRIMA_CONTROL.bkp
[oracle@lunar backup]$ ll
total 165412
-rw-r----- 1 oracle oinstall  5302272 Jul 17 21:16 arch_0hpdl9i1_1_1.rman
-rw-r----- 1 oracle oinstall 23611392 Jul 17 21:16 arch_0ipdl9i1_1_1.rman
-rw-r----- 1 oracle oinstall 11265024 Jul 17 21:16 arch_0jpdl9i5_1_1.rman
-rw-r--r-- 1 oracle oinstall     5155 Jul 17 21:16 bk.log
-rw-r--r-- 1 oracle oinstall      405 Jul 17 21:15 bk.sql
-rw-r----- 1 oracle oinstall 56680448 Jul 17 21:16 full_0epdl9gl_1_1.rman
-rw-r----- 1 oracle oinstall 61087744 Jul 17 21:16 full_0fpdl9gl_1_1.rman
-rw-r----- 1 oracle oinstall  1114112 Jul 17 21:16 full_0gpdl9ho_1_1.rman
-rw-r--r-- 1 oracle oinstall      624 Jul 17 21:32 pfile_lunar.ora
-rw-r----- 1 oracle oinstall 10092544 Jul 17 21:16 PRIMA_CONTROL.bkp
[oracle@lunar backup]$ scp * oracle@192.168.56.26:/stage/backup/
oracle@192.168.56.26's password:
arch_0hpdl9i1_1_1.rman                                                                                                               100% 5178KB   5.1MB/s   00:00
arch_0ipdl9i1_1_1.rman                                                                                                               100%   23MB  22.5MB/s   00:01
arch_0jpdl9i5_1_1.rman                                                                                                               100%   11MB  10.7MB/s   00:01
bk.log                                                                                                                               100% 5155     5.0KB/s   00:00
bk.sql                                                                                                                               100%  405     0.4KB/s   00:00
full_0epdl9gl_1_1.rman                                                                                                               100%   54MB  13.5MB/s   00:04
full_0fpdl9gl_1_1.rman                                                                                                               100%   58MB   4.2MB/s   00:14
full_0gpdl9ho_1_1.rman                                                                                                               100% 1088KB   1.1MB/s   00:00
pfile_lunar.ora                                                                                                                      100%  624     0.6KB/s   00:00
PRIMA_CONTROL.bkp                                                                                                                    100% 9856KB   4.8MB/s   00:02
[oracle@lunar backup]$ logout
[root@lunar ~]# 

要退出这个screen,只需要ctrl+d

screen的详细解释:
语法

# screen [-AmRvx -ls -wipe][-d <作业名称>][-h <行数>][-r <作业名称>][-s ][-S <作业名称>]

参数说明

-A  将所有的视窗都调整为目前终端机的大小。
-d <作业名称>  将指定的screen作业离线。
-h <行数>  指定视窗的缓冲区行数。
-m  即使目前已在作业中的screen作业,仍强制建立新的screen作业。
-r <作业名称>  恢复离线的screen作业。
-R  先试图恢复离线的作业。若找不到离线的作业,即建立新的screen作业。
-s  指定建立新视窗时,所要执行的shell。
-S <作业名称>  指定screen作业的名称。
-v  显示版本信息。
-x  恢复之前离线的screen作业。
-ls或–list  显示目前所有的screen作业。
-wipe  检查目前所有的screen作业,并删除已经无法使用的screen作业。

四、常用screen参数

screen -S yourname -> 新建一个叫yourname的session
screen -ls -> 列出当前所有的session
screen -r yourname -> 回到yourname这个session
screen -d yourname -> 远程detach某个session
screen -d -r yourname -> 结束当前session并回到yourname这个session

在每个screen session 下,所有命令都以 ctrl+a(Ctrl+a+) 开始。
Ctrl+a+ ? -> 显示所有键绑定信息
Ctrl+a+ c -> 创建一个新的运行shell的窗口并切换到该窗口
Ctrl+a+ n -> Next,切换到下一个 window
Ctrl+a+ p -> Previous,切换到前一个 window
Ctrl+a+ 0..9 -> 切换到第 0..9 个 window
Ctrl+a [Space] -> 由视窗0循序切换到视窗9
Ctrl+a+ Ctrl+a+ -> 在两个最近使用的 window 间切换
Ctrl+a+ x -> 锁住当前的 window,需用用户密码解锁
Ctrl+a+ d -> detach,暂时离开当前session,将目前的 screen session (可能含有多个 windows) 丢到后台执行,并会回到还没进 screen 时的状态,此时在 screen session 里,每个 window 内运行的 process (无论是前台/后台)都在继续执行,即使 logout 也不影响。
Ctrl+a+ z -> 把当前session放到后台执行,用 shell 的 fg 命令则可回去。
Ctrl+a+ w -> 显示所有窗口列表
Ctrl+a+ t -> Time,显示当前时间,和系统的 load
Ctrl+a+ k -> kill window,强行关闭当前的 window
Ctrl+a+ [ -> 进入 copy mode,在 copy mode 下可以回滚、搜索、复制就像用使用 vi 一样
C-b Backward,PageUp
C-f Forward,PageDown
H(大写) High,将光标移至左上角
L Low,将光标移至左下角
0 移到行首
$ 行末
w forward one word,以字为单位往前移
b backward one word,以字为单位往后移
Space 第一次按为标记区起点,第二次按为终点
Esc 结束 copy mode
Ctrl+a+ ] -> Paste,把刚刚在 copy mode 选定的内容贴上

发表在 FAQ | 标签为 , | 留下评论

配置Cascade Standby

环境介绍:
1,VM1: OEL5.8+Oracle 11.2.0.3,考虑到笔记本的性能不行,因此最初考虑的是这个VM兼顾了Physical Primary 和Casecade Standby的重任。数据库是文件系统
2,VM2: OEL5.10+11.2.0.4,数据库是ASM的环境(Oracle Restart),作为Physical Standby。

考虑到版本兼容的问题,下一篇我讲切换他们的角色;
1,让VM2做为Cascade Standby的角色(因为不同版本,不能使用正常的open,只能open upgrade,因此,如果作为Physical Standby的话,不能放倒Open read only上)。
2,让VM1上的2个11.2.0.3的库分别作为Primary和Physical standby角色

创建standby controlfile和pfile:

07:37:17 SYS@lunar>alter database create standby controlfile as '/tmp/lunar.stb.ctl';

Database altered.

Elapsed: 00:00:02.16
07:37:35 SYS@lunar>

07:45:46 SYS@lunar>create pfile='/tmp/lunarstb.pfile' from spfile;

File created.

Elapsed: 00:00:00.24
07:46:13 SYS@lunar>

创建需要的目录:

07:43:20 SYS@lunar>show parameter reco

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
control_file_record_keep_time        integer     7
db_recovery_file_dest                string      /stage/fast_recovery_area
db_recovery_file_dest_size           big integer 1190198K
db_unrecoverable_scn_tracking        boolean     TRUE
recovery_parallelism                 integer     0
07:43:27 SYS@lunar>
07:44:34 SYS@lunar>show parameter audit

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
audit_file_dest                      string      /u01/app/oracle/admin/lunar/ad
                                                 ump
audit_sys_operations                 boolean     FALSE
audit_syslog_level                   string
audit_trail                          string      NONE
07:44:38 SYS@lunar>

使用备份进行恢复:

[oracle@lunar trace]$ rman target /

Recovery Manager: Release 11.2.0.3.0 - Production on Sat Aug 2 07:43:12 2014

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

connected to target database: LUNAR (DBID=2464578389)

RMAN> list backup summary;

using target database control file instead of recovery catalog

List of Backups
===============
Key     TY LV S Device Type Completion Time #Pieces #Copies Compressed Tag
------- -- -- - ----------- --------------- ------- ------- ---------- ---
1       B  F  A DISK        17-JUL-14       1       1       NO         TAG20140717T211558
2       B  F  A DISK        17-JUL-14       1       1       YES        TAG20140717T211604
3       B  F  A DISK        17-JUL-14       1       1       YES        TAG20140717T211604
4       B  F  A DISK        17-JUL-14       1       1       YES        TAG20140717T211604
5       B  A  A DISK        17-JUL-14       1       1       YES        TAG20140717T211649
6       B  A  A DISK        17-JUL-14       1       1       YES        TAG20140717T211649
7       B  A  A DISK        17-JUL-14       1       1       YES        TAG20140717T211649

RMAN> list backup;


List of Backup Sets
===================


BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
1       Full    9.61M      DISK        00:00:04     17-JUL-14      
        BP Key: 1   Status: AVAILABLE  Compressed: NO  Tag: TAG20140717T211558
        Piece Name: /stage/backup/PRIMA_CONTROL.bkp
  Standby Control File Included: Ckp SCN: 1178911      Ckp time: 17-JUL-14

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
2       Full    54.05M     DISK        00:00:32     17-JUL-14      
        BP Key: 2   Status: AVAILABLE  Compressed: YES  Tag: TAG20140717T211604
        Piece Name: /stage/backup/full_0epdl9gl_1_1.rman
  List of Datafiles in backup set 2
  File LV Type Ckp SCN    Ckp Time  Name
  ---- -- ---- ---------- --------- ----
  2       Full 1178928    17-JUL-14 /stage/lunar/sysaux01.dbf
  3       Full 1178928    17-JUL-14 /stage/lunar/undotbs01.dbf
  5       Full 1178928    17-JUL-14 /stage/lunar/soe01.dbf

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
3       Full    58.25M     DISK        00:00:33     17-JUL-14      
        BP Key: 3   Status: AVAILABLE  Compressed: YES  Tag: TAG20140717T211604
        Piece Name: /stage/backup/full_0fpdl9gl_1_1.rman
  List of Datafiles in backup set 3
  File LV Type Ckp SCN    Ckp Time  Name
  ---- -- ---- ---------- --------- ----
  1       Full 1178929    17-JUL-14 /stage/lunar/system01.dbf
  4       Full 1178929    17-JUL-14 /stage/lunar/users01.dbf
  6       Full 1178929    17-JUL-14 /stage/lunar/lunar01.dbf

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
4       Full    1.05M      DISK        00:00:03     17-JUL-14      
        BP Key: 4   Status: AVAILABLE  Compressed: YES  Tag: TAG20140717T211604
        Piece Name: /stage/backup/full_0gpdl9ho_1_1.rman
  Control File Included: Ckp SCN: 1178948      Ckp time: 17-JUL-14

BS Key  Size       Device Type Elapsed Time Completion Time
------- ---------- ----------- ------------ ---------------
5       5.06M      DISK        00:00:02     17-JUL-14      
        BP Key: 5   Status: AVAILABLE  Compressed: YES  Tag: TAG20140717T211649
        Piece Name: /stage/backup/arch_0hpdl9i1_1_1.rman

  List of Archived Logs in backup set 5
  Thrd Seq     Low SCN    Low Time  Next SCN   Next Time
  ---- ------- ---------- --------- ---------- ---------
  1    1       1069557    16-JUL-14 1080642    16-JUL-14
  1    2       1080642    16-JUL-14 1080645    16-JUL-14
  1    3       1080645    16-JUL-14 1080649    16-JUL-14
  1    4       1080649    16-JUL-14 1080680    16-JUL-14
  1    5       1080680    16-JUL-14 1080684    16-JUL-14

BS Key  Size       Device Type Elapsed Time Completion Time
------- ---------- ----------- ------------ ---------------
6       22.52M     DISK        00:00:06     17-JUL-14      
        BP Key: 6   Status: AVAILABLE  Compressed: YES  Tag: TAG20140717T211649
        Piece Name: /stage/backup/arch_0ipdl9i1_1_1.rman

  List of Archived Logs in backup set 6
  Thrd Seq     Low SCN    Low Time  Next SCN   Next Time
  ---- ------- ---------- --------- ---------- ---------
  1    6       1080684    16-JUL-14 1113407    16-JUL-14
  1    7       1113407    16-JUL-14 1145484    17-JUL-14

BS Key  Size       Device Type Elapsed Time Completion Time
------- ---------- ----------- ------------ ---------------
7       10.74M     DISK        00:00:03     17-JUL-14      
        BP Key: 7   Status: AVAILABLE  Compressed: YES  Tag: TAG20140717T211649
        Piece Name: /stage/backup/arch_0jpdl9i5_1_1.rman

  List of Archived Logs in backup set 7
  Thrd Seq     Low SCN    Low Time  Next SCN   Next Time
  ---- ------- ---------- --------- ---------- ---------
  1    8       1145484    17-JUL-14 1178967    17-JUL-14
  1    9       1178967    17-JUL-14 1178977    17-JUL-14

RMAN> 

使用screen在后台传输rman备份集:

[root@lunar ~]# screen -S lunar
[root@lunar ~]# su - oracle
[oracle@lunar ~]$ . lunar.env 
[oracle@lunar ~]$ env|grep ORA
ORACLE_SID=lunar
ORACLE_BASE=/u01/app/oracle
ORACLE_HOME=/u01/app/oracle/product/11.2.0.3/dbhome_1
[oracle@lunar ~]$ cd /stage
[oracle@lunar stage]$ cd backup
[oracle@lunar backup]$ ls
arch_0hpdl9i1_1_1.rman  arch_0jpdl9i5_1_1.rman  bk.sql                  full_0fpdl9gl_1_1.rman  pfile_lunar.ora
arch_0ipdl9i1_1_1.rman  bk.log                  full_0epdl9gl_1_1.rman  full_0gpdl9ho_1_1.rman  PRIMA_CONTROL.bkp
[oracle@lunar backup]$ ll
total 165412
-rw-r----- 1 oracle oinstall  5302272 Jul 17 21:16 arch_0hpdl9i1_1_1.rman
-rw-r----- 1 oracle oinstall 23611392 Jul 17 21:16 arch_0ipdl9i1_1_1.rman
-rw-r----- 1 oracle oinstall 11265024 Jul 17 21:16 arch_0jpdl9i5_1_1.rman
-rw-r--r-- 1 oracle oinstall     5155 Jul 17 21:16 bk.log
-rw-r--r-- 1 oracle oinstall      405 Jul 17 21:15 bk.sql
-rw-r----- 1 oracle oinstall 56680448 Jul 17 21:16 full_0epdl9gl_1_1.rman
-rw-r----- 1 oracle oinstall 61087744 Jul 17 21:16 full_0fpdl9gl_1_1.rman
-rw-r----- 1 oracle oinstall  1114112 Jul 17 21:16 full_0gpdl9ho_1_1.rman
-rw-r--r-- 1 oracle oinstall      624 Jul 17 21:32 pfile_lunar.ora
-rw-r----- 1 oracle oinstall 10092544 Jul 17 21:16 PRIMA_CONTROL.bkp
[oracle@lunar backup]$ scp * oracle@192.168.56.26:/stage/backup/
oracle@192.168.56.26's password: 

[detached]
[root@lunar ~]# screen -ls
There is a screen on:
        11012.lunar     (Detached)
1 Socket in /var/run/screen/S-root.

[root@lunar ~]# ps -ef|grep 11012
root     11012     1  0 08:10 ?        00:00:00 SCREEN -S lunar
root     11013 11012  0 08:10 pts/2    00:00:00 /bin/bash
root     11087 10627  0 08:14 pts/0    00:00:00 grep 11012
[root@lunar ~]# screen -r 11012
[oracle@lunar stage]$ cd backup
[oracle@lunar backup]$ ls
arch_0hpdl9i1_1_1.rman  arch_0jpdl9i5_1_1.rman  bk.sql                  full_0fpdl9gl_1_1.rman  pfile_lunar.ora
arch_0ipdl9i1_1_1.rman  bk.log                  full_0epdl9gl_1_1.rman  full_0gpdl9ho_1_1.rman  PRIMA_CONTROL.bkp
[oracle@lunar backup]$ ll
total 165412
-rw-r----- 1 oracle oinstall  5302272 Jul 17 21:16 arch_0hpdl9i1_1_1.rman
-rw-r----- 1 oracle oinstall 23611392 Jul 17 21:16 arch_0ipdl9i1_1_1.rman
-rw-r----- 1 oracle oinstall 11265024 Jul 17 21:16 arch_0jpdl9i5_1_1.rman
-rw-r--r-- 1 oracle oinstall     5155 Jul 17 21:16 bk.log
-rw-r--r-- 1 oracle oinstall      405 Jul 17 21:15 bk.sql
-rw-r----- 1 oracle oinstall 56680448 Jul 17 21:16 full_0epdl9gl_1_1.rman
-rw-r----- 1 oracle oinstall 61087744 Jul 17 21:16 full_0fpdl9gl_1_1.rman
-rw-r----- 1 oracle oinstall  1114112 Jul 17 21:16 full_0gpdl9ho_1_1.rman
-rw-r--r-- 1 oracle oinstall      624 Jul 17 21:32 pfile_lunar.ora
-rw-r----- 1 oracle oinstall 10092544 Jul 17 21:16 PRIMA_CONTROL.bkp
[oracle@lunar backup]$ scp * oracle@192.168.56.26:/stage/backup/
oracle@192.168.56.26's password:
arch_0hpdl9i1_1_1.rman                                                                                                               100% 5178KB   5.1MB/s   00:00
arch_0ipdl9i1_1_1.rman                                                                                                               100%   23MB  22.5MB/s   00:01
arch_0jpdl9i5_1_1.rman                                                                                                               100%   11MB  10.7MB/s   00:01
bk.log                                                                                                                               100% 5155     5.0KB/s   00:00
bk.sql                                                                                                                               100%  405     0.4KB/s   00:00
full_0epdl9gl_1_1.rman                                                                                                               100%   54MB  13.5MB/s   00:04
full_0fpdl9gl_1_1.rman                                                                                                               100%   58MB   4.2MB/s   00:14
full_0gpdl9ho_1_1.rman                                                                                                               100% 1088KB   1.1MB/s   00:00
pfile_lunar.ora                                                                                                                      100%  624     0.6KB/s   00:00
PRIMA_CONTROL.bkp                                                                                                                    100% 9856KB   4.8MB/s   00:02
[oracle@lunar backup]$ logout
[root@lunar ~]# 

安装cascade的screen(这个步骤跟本次操作没有关系,不过是临时遇到了,顺手做了一下):

[root@lunar ~]# cd /etc/yum.repos.d
[root@lunar yum.repos.d]# wget http://public-yum.oracle.com/public-yum-el5.repo
--2014-08-02 16:36:47--  http://public-yum.oracle.com/public-yum-el5.repo
Resolving public-yum.oracle.com... 198.172.88.104
Connecting to public-yum.oracle.com|198.172.88.104|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 4550 (4.4K) 1
Saving to: `public-yum-el5.repo.2'

100%[=============================================================================================================================>] 4,550       --.-K/s   in 0s      

2014-08-02 16:36:51 (80.1 MB/s) - `public-yum-el5.repo.2' saved [4550/4550]

[root@lunar yum.repos.d]# yum install screen*
Loaded plugins: rhnplugin, security
This system is not registered with ULN.
You can use up2date --register to register.
ULN support will be disabled.
el5_latest                                                                                                                                      | 1.4 kB     00:00     
ol5_UEK_latest                                                                                                                                  | 1.2 kB     00:00     
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package screen.x86_64 0:4.0.3-4.el5 set to be updated
--> Finished Dependency Resolution

Dependencies Resolved

=======================================================================================================================================================================
 Package                              Arch                                 Version                                      Repository                                Size
=======================================================================================================================================================================
Installing:
 screen                               x86_64                               4.0.3-4.el5                                  el5_latest                               571 k

Transaction Summary
=======================================================================================================================================================================
Install       1 Package(s)
Upgrade       0 Package(s)

Total download size: 571 k
Is this ok [y/N]: y
Downloading Packages:
screen-4.0.3-4.el5.x86_64.rpm                                                                                                                   | 571 kB     00:03     
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing     : screen                                                                                                                                          1/1 

Installed:
  screen.x86_64 0:4.0.3-4.el5                                                                                                                                          

Complete!
[root@lunar yum.repos.d]# 

scp oracle@192.168.56.66:/tmp/lunarstb.pfile .
scp oracle@192.168.56.66:/tmp/lunar.stb.ctl .

配置主库的参数:

[oracle@lunar backup]$ cat lunarstb.pfile
*.audit_file_dest='/u01/app/oracle/admin/lunar/adump'
*.audit_trail='none'
*.compatible='11.2.0.3.0'
*.control_files='/stage/lunar/control01.ctl','/stage/lunar/control02.ctl'
*.db_block_size=8192
*.db_domain=''
*.db_name='lunar'
*.db_recovery_file_dest='/stage/fast_recovery_area'
*.db_recovery_file_dest_size=1218762752
*.deferred_segment_creation=FALSE
*.diagnostic_dest='/u01/app/oracle'
*.filesystemio_options='setall'
*.open_cursors=300
*.pga_aggregate_target=153092096
*.processes=150
*.remote_login_passwordfile='EXCLUSIVE'
*.sec_return_server_release_banner=FALSE
*.sga_target=629145600
*.undo_tablespace='UNDOTBS1'
*.db_unique_name='lunarp'
*.log_archive_config='DG_CONFIG=(lunarp,lunars,lunarc)'
*.fal_server='lunars'
*.fal_client='lunarp'
*.log_archive_dest_1='LOCATION=USE_DB_RECOVERY_FILE_DEST VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=lunarp'
*.log_archive_dest_2='SERVICE=lunars LGWR SYNC AFFIRM VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=lunars'
*.log_archive_dest_3='SERVICE=lunarc LGWR SYNC AFFIRM VALID_FOR=(STANDBY_LOGFILES,STANDBY_ROLE) DB_UNIQUE_NAME=lunarc'
*.log_archive_dest_state_1='ENABLE'
*.log_archive_dest_state_2='ENABLE'
*.log_archive_dest_state_3='ENABLE'
*.log_file_name_convert='+DATA/lunars/onlinelog/','/stage/lunar/'
*.db_file_name_convert='+DATA/lunars/datafile/','/stage/lunar/'
*.standby_file_management=auto
*.service_names='lunar'

Physical Standby的参数文件:

*.db_unique_name='lunars'
*.log_archive_config='DG_CONFIG=(lunarp,lunars,lunarc)'
*.fal_server='lunarp'
*.fal_client='lunars'
*.log_archive_dest_1='LOCATION=USE_DB_RECOVERY_FILE_DEST VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=lunars'
*.log_archive_dest_2='SERVICE=lunarp LGWR SYNC AFFIRM VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=lunarp'
*.log_archive_dest_3='SERVICE=lunarc LGWR SYNC AFFIRM VALID_FOR=(STANDBY_LOGFILES,STANDBY_ROLE) DB_UNIQUE_NAME=lunarc'
*.log_archive_dest_state_1='ENABLE'
*.log_archive_dest_state_2='ENABLE'
*.log_archive_dest_state_3='ENABLE'
*.log_file_name_convert='/stage/lunar/','+DATA'
*.db_file_name_convert='/stage/lunar/','+DATA'
*.standby_file_management=auto
*.DB_CREATE_FILE_DEST='+DATA'
*.DB_CREATE_ONLINE_LOG_DEST_1='+DATA'
*.control_files='+data/lunars/control01.ctl','+data/lunars/control02.ctl'
*.service_names='lunar'

Cascade Standby的参数:

*.db_unique_name='lunarc'
log_archive_config='DG_CONFIG=(lunarp,lunars,lunarc)'
*.fal_server='lunarp','lunars'
*.fal_client='lunarc'
*.log_archive_dest_1='LOCATION=USE_DB_RECOVERY_FILE_DEST VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=lunarc'
*.log_archive_dest_2='SERVICE=lunars LGWR SYNC AFFIRM VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=lunars'
*.log_archive_dest_state_1='ENABLE'
*.log_archive_dest_state_2='ENABLE'
*.log_file_name_convert='/stage/lunar/','/stage/lunar/'
*.db_file_name_convert='/stage/lunar/','/stage/lunar/'
*.standby_file_management=auto
*.service_names='lunar'

其余的过程就简单了,跟普通的ADG没什么分别:
1,分别在physical standby和cascade standby上做恢复standby controlfile和restore database。
2,使用alter database recover managed standby database using current logfile disconnect from session;应用日志了。
3,添加standby redo log:
alter database add standby logfile group 4(‘+DATA’) size 50M;
alter database add standby logfile group 5(‘+DATA’) size 50M;
alter database add standby logfile group 6(‘+DATA’) size 50M;
alter database add standby logfile group 7(‘+DATA’) size 50M;

最终的同步信息:
配置完成后,主库信息:

18:30:03 SYS@lunarp>show parameter name

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
db_file_name_convert                 string      +DATA/lunars/, /stage/lunar/
db_name                              string      lunar
db_unique_name                       string      lunarp
global_names                         boolean     FALSE
instance_name                        string      lunarp
lock_name_space                      string
log_file_name_convert                string      +DATA/lunars/, /stage/lunar/
processor_group_name                 string
service_names                        string      lunar
18:30:14 SYS@lunarp>
18:30:14 SYS@lunarp>SELECT PROCESS, STATUS, THREAD#, SEQUENCE#, BLOCK#, BLOCKS FROM  V$MANAGED_STANDBY;

PROCESS   STATUS          THREAD#  SEQUENCE#     BLOCK#     BLOCKS
--------- ------------ ---------- ---------- ---------- ----------
ARCH      CLOSING               1         32          1       1071
ARCH      CLOSING               1         29          1        476
ARCH      CLOSING               1          8      69633        405
ARCH      CLOSING               1         32          1       1071
LGWR      WRITING               1         33      42656          1

Elapsed: 00:00:00.01
18:31:19 SYS@lunarp>archive log list
Database log mode              Archive Mode
Automatic archival             Enabled
Archive destination            USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence     31
Next log sequence to archive   33
Current log sequence           33
18:32:34 SYS@lunarp>

Physical Standby的信息:

18:30:38 SYS@lunarc>show parameter name

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
db_file_name_convert                 string      /stage/lunar/, /tempdisk/lunar
                                                 c/
db_name                              string      lunar
db_unique_name                       string      lunarc
global_names                         boolean     FALSE
instance_name                        string      lunarc
lock_name_space                      string
log_file_name_convert                string      /stage/lunar/, /tempdisk/lunar
                                                 c/
processor_group_name                 string
service_names                        string      lunar
18:30:41 SYS@lunarc>
18:31:47 SYS@lunarc>SELECT PROCESS, STATUS, THREAD#, SEQUENCE#, BLOCK#, BLOCKS FROM  V$MANAGED_STANDBY;

PROCESS   STATUS          THREAD#  SEQUENCE#     BLOCK#     BLOCKS
--------- ------------ ---------- ---------- ---------- ----------
ARCH      CLOSING               1         31       2048        646
ARCH      CLOSING               1         32          1       1071
ARCH      OPENING               1         10          0          0
ARCH      CONNECTED             0          0          0          0
MRP0      WAIT_FOR_LOG          1         33          0          0
RFS       IDLE                  0          0          0          0
RFS       IDLE                  0          0          0          0
RFS       IDLE                  0          0          0          0
RFS       IDLE                  0          0          0          0

9 rows selected.

Elapsed: 00:00:00.00
18:31:48 SYS@lunarc>

Cascade Standby的信息:

SQL> show parameter name
NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
cell_offloadgroup_name               string
db_file_name_convert                 string      /stage/lunar/, +DATA/lunars/
db_name                              string      lunar
db_unique_name                       string      lunars
global_names                         boolean     FALSE
instance_name                        string      lunars
lock_name_space                      string
log_file_name_convert                string      /stage/lunar/, +DATA/lunars/
processor_group_name                 string
service_names                        string      lunar
SQL> SELECT PROCESS, STATUS, THREAD#, SEQUENCE#, BLOCK#, BLOCKS FROM  V$MANAGED_STANDBY;

PROCESS   STATUS          THREAD#  SEQUENCE#     BLOCK#     BLOCKS
--------- ------------ ---------- ---------- ---------- ----------
ARCH      CLOSING               1         31          1       2693
ARCH      CLOSING               1         32          1       1071
ARCH      CONNECTED             0          0          0          0
ARCH      CLOSING               1         32          1       1071
RFS       IDLE                  0          0          0          0
RFS       IDLE                  0          0          0          0
RFS       IDLE                  1         33      42696          1

7 rows selected.

SQL> 

切换是很里灵活的,后续将任意切换

发表在 Dataguard | 标签为 , , | 留下评论

Standalone – 修改主机名和IP地址

新本本性能一般,用VM跑RAC很费劲,因此从朋友那里copy了一个STANDALONE(ASM+SINGLE DATABASE),然后直接修改主机名后,发现css信息异常,且HAS不能启动……
直接修改主机名为lunar后,HAS的信息为:

[root@lunar bin]# crs_stat -t -v
Name           Type           R/RA   F/FT   Target    State     Host        
----------------------------------------------------------------------
ora.DATA.dg    ora....up.type 0/5    0/     ONLINE    OFFLINE                -----注意,ora.DATA.dg 异常了
ora....ER.lsnr ora....er.type 0/5    0/     ONLINE    ONLINE    dabaobao    
ora.asm        ora.asm.type   0/5    0/     ONLINE    ONLINE    dabaobao    
ora.cssd       ora.cssd.type  0/5    0/5    ONLINE    ONLINE    dabaobao    
ora.diskmon    ora....on.type 0/10   0/5    OFFLINE   OFFLINE               --本来这个就不应该启动
ora.evmd       ora.evm.type   0/10   0/5    ONLINE    ONLINE    dabaobao    
ora.ons        ora.ons.type   0/3    0/     OFFLINE   OFFLINE               
[root@lunar bin]#crsctl status res -init
NAME=ora.DATA.dg
TYPE=ora.diskgroup.type
TARGET=ONLINE
STATE=OFFLINE

NAME=ora.LISTENER.lsnr
TYPE=ora.listener.type
TARGET=ONLINE
STATE=ONLINE on dabaobao

NAME=ora.asm
TYPE=ora.asm.type
TARGET=ONLINE
STATE=ONLINE on dabaobao

NAME=ora.cssd
TYPE=ora.cssd.type
TARGET=ONLINE
STATE=ONLINE on dabaobao

NAME=ora.diskmon
TYPE=ora.diskmon.type
TARGET=OFFLINE
STATE=OFFLINE

NAME=ora.evmd
TYPE=ora.evm.type
TARGET=ONLINE
STATE=ONLINE on dabaobao

NAME=ora.ons
TYPE=ora.ons.type
TARGET=OFFLINE
STATE=OFFLINE

[root@lunar bin]# crsctl status res -t
--------------------------------------------------------------------------------
NAME           TARGET  STATE        SERVER                   STATE_DETAILS       
--------------------------------------------------------------------------------
Local Resources
--------------------------------------------------------------------------------
ora.DATA.dg
               ONLINE  OFFLINE      dabaobao                                     
ora.LISTENER.lsnr
               ONLINE  ONLINE       dabaobao                                     
ora.asm
               ONLINE  ONLINE       dabaobao                 Started             
ora.ons
               OFFLINE OFFLINE      dabaobao                                     
--------------------------------------------------------------------------------
Cluster Resources
--------------------------------------------------------------------------------
ora.cssd
      1        ONLINE  ONLINE       dabaobao                                     
ora.diskmon
      1        OFFLINE OFFLINE                                                   
ora.evmd
      1        ONLINE  ONLINE       dabaobao                                     
[root@lunar bin]# crsctl check has
CRS-4638: Oracle High Availability Services is online
[root@lunar bin]

重启has后,发现HAS启动不了,报错如下:

[root@lunar ~]# crsctl start has
CLSU-00100: Operating System function: opendir failed with error data: 2
CLSU-00101: Operating System error message: No such file or directory
CLSU-00103: error location: scrsearch1
CLSU-00104: additional error information: cant open scr home dir scls_scr_getval
CRS-4000: Command Start failed, or completed with errors.
[root@lunar ~]#

根据“error location: scrsearch1”和“cant open scr home dir scls_scr_getval”,可以看出这个跟修改主机名有关系,将主机名称修改会议前的dabaobao:

[root@lunar install]# hostname dabaobao
[root@lunar install]# exit
logout
Last login: Sun Jul 13 09:39:31 2014 from 192.168.56.1
[root@dabaobao ~]# 
[root@dabaobao ~]# 

修改回到以前的主机名“dabaobao”以后,再次重启has,可以启动了,可见,HAS的架构非常简单……

[root@dabaobao ~]# crsctl start has
CRS-4123: Oracle High Availability Services has been started.
[root@dabaobao ~]# ps -ef|grep d.bin
grid      3192     1  0 08:56 ?        00:00:02 /u01/app/grid/product/11.2.0/db_1/bin/evmd.bin
grid      3271     1  0 08:56 ?        00:00:03 /u01/app/grid/product/11.2.0/db_1/bin/ocssd.bin 
grid      5324     1  2 10:00 ?        00:00:02 /u01/app/grid/product/11.2.0/db_1/bin/ohasd.bin reboot
root      5478  5293  0 10:02 pts/2    00:00:00 grep d.bin
[root@dabaobao ~]# crsctl status res -t
--------------------------------------------------------------------------------
NAME           TARGET  STATE        SERVER                   STATE_DETAILS       
--------------------------------------------------------------------------------
Local Resources
--------------------------------------------------------------------------------
ora.DATA.dg
               ONLINE  OFFLINE      dabaobao                                     
ora.LISTENER.lsnr
               ONLINE  ONLINE       dabaobao                                     
ora.asm
               ONLINE  ONLINE       dabaobao                 Started             
ora.ons
               OFFLINE OFFLINE      dabaobao                                     
--------------------------------------------------------------------------------
Cluster Resources
--------------------------------------------------------------------------------
ora.cssd
      1        ONLINE  ONLINE       dabaobao                                     
ora.diskmon
      1        OFFLINE OFFLINE                                                   
ora.evmd
      1        ONLINE  ONLINE       dabaobao                                     
[root@dabaobao ~]# 

这里,出了ora.DATA.dg这个资源异常外,其他资源是正常状态,此时,我们使用roothas.pl删除HAS的配置:

[root@dabaobao install]# ./roothas.pl -deconfig -force
Using configuration parameter file: ./crsconfig_params
CRS resources for listeners are still configured
PRKO-2573 : ONS daemon is already stopped.
CRS-2673: Attempting to stop 'ora.asm' on 'dabaobao'
ORA-21561: OID generation failed
CRS-5022: Stop of resource "ora.asm" failed: current state is "UNKNOWN"
CRS-2675: Stop of 'ora.asm' on 'dabaobao' failed
CRS-4000: Command Stop failed, or completed with errors.
CRS-2791: Starting shutdown of Oracle High Availability Services-managed resources on 'dabaobao'
CRS-2673: Attempting to stop 'ora.asm' on 'dabaobao'
ORA-21561: OID generation failed
CRS-5022: Stop of resource "ora.asm" failed: current state is "UNKNOWN"
CRS-2675: Stop of 'ora.asm' on 'dabaobao' failed
CRS-2679: Attempting to clean 'ora.asm' on 'dabaobao'
ORA-21561: OID generation failed
CRS-5022: Stop of resource "ora.asm" failed: current state is "UNKNOWN"
CRS-2678: 'ora.asm' on 'dabaobao' has experienced an unrecoverable failure
CRS-2799: Failed to shut down resource 'ora.asm' on 'dabaobao'
CRS-2795: Shutdown of Oracle High Availability Services-managed resources on 'dabaobao' has failed
CRS-4687: Shutdown command has completed with errors.
CRS-4000: Command Stop failed, or completed with errors.
You must kill ohasd processes or reboot the system to properly 
cleanup the processes started by Oracle clusterware
Successfully deconfigured Oracle Restart stack
[root@dabaobao install]#

然后,修改主机名为lunar,再次使用roothas.pl,让他自动根据当前的主机名和IP来生成配置信息:

[root@dabaobao install]# hostname lunar
[root@dabaobao install]# 
[root@dabaobao install]# exit
logout
 
[root@lunar install]# ./roothas.pl
Using configuration parameter file: ./crsconfig_params
LOCAL ADD MODE 
Creating OCR keys for user 'grid', privgrp 'oinstall'..
Operation successful.
LOCAL ONLY MODE 
Successfully accumulated necessary OCR keys.
Creating OCR keys for user 'root', privgrp 'root'..
Operation successful.
CRS-4664: Node lunar successfully pinned.
Adding Clusterware entries to inittab

lunar     2014/07/13 10:14:08     /u01/app/grid/product/11.2.0/db_1/cdata/lunar/backup_20140713_101408.olr
Successfully configured Oracle Grid Infrastructure for a Standalone Server
[root@lunar install]# 
[root@lunar install]# crsctl start has
CRS-4640: Oracle High Availability Services is already active
CRS-4000: Command Start failed, or completed with errors.
[root@lunar install]# 

可见,这里已经生产了节点名为lunar的has配置信息

[root@lunar install]# crsctl status res -t
--------------------------------------------------------------------------------
NAME           TARGET  STATE        SERVER                   STATE_DETAILS       
--------------------------------------------------------------------------------
Local Resources
--------------------------------------------------------------------------------
ora.ons
               OFFLINE OFFLINE      lunar                                        
--------------------------------------------------------------------------------
Cluster Resources
--------------------------------------------------------------------------------
ora.cssd
      1        OFFLINE OFFLINE                                                   
ora.diskmon
      1        OFFLINE OFFLINE                                                   
ora.evmd
      1        ONLINE  ONLINE       lunar                                        
[root@lunar install]#

添加asm:

[root@lunar bin]# su - grid
[grid@lunar ~]$ srvctl add asm
[grid@lunar ~]$ srvctl start asm
[grid@lunar ~]$ 
[root@lunar install]# crsctl status res -t
--------------------------------------------------------------------------------
NAME           TARGET  STATE        SERVER                   STATE_DETAILS       
--------------------------------------------------------------------------------
Local Resources
--------------------------------------------------------------------------------
ora.asm
               ONLINE  ONLINE       lunar                    Started             
ora.ons
               OFFLINE OFFLINE      lunar                                        
--------------------------------------------------------------------------------
Cluster Resources
--------------------------------------------------------------------------------
ora.cssd
      1        ONLINE  ONLINE       lunar                                        
ora.diskmon
      1        OFFLINE OFFLINE                                                   
ora.evmd
      1        ONLINE  ONLINE       lunar                                        
[root@lunar install]#
[root@lunar install]# crsctl modify resource "ora.asm" -attr "AUTO_START=1"

添加ASM DISKGROUP:

[grid@lunar ~]$ vi init+ASM.ora
asm_diskgroups='DATA'
instance_type='asm'
large_pool_size=12M
remote_login_passwordfile='EXCLUSIVE'

SQL> shutdown immediate
ASM diskgroups dismounted
ASM instance shutdown
SQL> startup pfile=/home/grid/init+ASM.ora
ASM instance started

Total System Global Area 1135747072 bytes
Fixed Size                  2260728 bytes
Variable Size            1108320520 bytes
ASM Cache                  25165824 bytes
ORA-15032: not all alterations performed
ORA-15017: diskgroup "DATA" cannot be mounted
ORA-15063: ASM discovered an insufficient number of disks for diskgroup "DATA"


SQL> 

这个错误是因为没有找到合适的disk,于是修改参数:

[grid@lunar ~]$ vi init+ASM.ora 
asm_diskgroups='DATA'
asm_diskstring= "/dev/asm-disk*"
instance_type='asm'
large_pool_size=12M
remote_login_passwordfile='EXCLUSIVE'
~

[grid@lunar ~]$ sqlplus / as sysasm

SQL*Plus: Release 11.2.0.4.0 Production on Sun Jul 13 10:40:17 2014

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


Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Automatic Storage Management option

SQL> shutdown abort
ASM instance shutdown
SQL> startup pfile=/home/grid/init+ASM.ora
ASM instance started

Total System Global Area 1135747072 bytes
Fixed Size                  2260728 bytes
Variable Size            1108320520 bytes
ASM Cache                  25165824 bytes
ASM diskgroups mounted
ASM diskgroups volume enabled
SQL>

可以看到,现在磁盘组都mount上了
然后我们创建spfile,准备重启has:


SQL> create spfile='+DATA' from pfile='/home/grid/init+ASM.ora';

File created.

SQL> show parameter spfile;

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
spfile                               string
SQL> 
[root@lunar install]# crsctl status res -t
--------------------------------------------------------------------------------
NAME           TARGET  STATE        SERVER                   STATE_DETAILS       
--------------------------------------------------------------------------------
Local Resources
--------------------------------------------------------------------------------
ora.DATA.dg
               ONLINE  ONLINE       lunar                                        
ora.asm
               ONLINE  ONLINE       lunar                    Started             
ora.ons
               OFFLINE OFFLINE      lunar                                        
--------------------------------------------------------------------------------
Cluster Resources
--------------------------------------------------------------------------------
ora.cssd
      1        ONLINE  ONLINE       lunar                                        
ora.diskmon
      1        OFFLINE OFFLINE                                                   
ora.evmd
      1        ONLINE  ONLINE       lunar                                        
[root@lunar install]# crsctl modify resource "ora.DATA.dg" -attr "AUTO_START=1"
[root@lunar install]#

重启HAS:

[root@lunar install]# crsctl stop has
CRS-2791: Starting shutdown of Oracle High Availability Services-managed resources on 'lunar'
CRS-2673: Attempting to stop 'ora.DATA.dg' on 'lunar'
CRS-2677: Stop of 'ora.DATA.dg' on 'lunar' succeeded
CRS-2673: Attempting to stop 'ora.asm' on 'lunar'
CRS-2677: Stop of 'ora.asm' on 'lunar' succeeded
CRS-2673: Attempting to stop 'ora.cssd' on 'lunar'
CRS-2677: Stop of 'ora.cssd' on 'lunar' succeeded
CRS-2673: Attempting to stop 'ora.evmd' on 'lunar'
CRS-2677: Stop of 'ora.evmd' on 'lunar' succeeded
CRS-2793: Shutdown of Oracle High Availability Services-managed resources on 'lunar' has completed
CRS-4133: Oracle High Availability Services has been stopped.
[root@lunar install]# crsctl start has
CRS-4123: Oracle High Availability Services has been started.
[root@lunar install]# 
[root@lunar install]# crsctl status res -t
--------------------------------------------------------------------------------
NAME           TARGET  STATE        SERVER                   STATE_DETAILS       
--------------------------------------------------------------------------------
Local Resources
--------------------------------------------------------------------------------
ora.DATA.dg
               ONLINE  OFFLINE      lunar                                        
ora.asm
               ONLINE  OFFLINE      lunar                    Instance Shutdown,S 
                                                             TARTING             
ora.ons
               OFFLINE OFFLINE      lunar                                        
--------------------------------------------------------------------------------
Cluster Resources
--------------------------------------------------------------------------------
ora.cssd
      1        ONLINE  ONLINE       lunar                                        
ora.diskmon
      1        OFFLINE OFFLINE                                                   
ora.evmd
      1        ONLINE  INTERMEDIATE lunar                                        
[root@lunar install]#

等待一会儿,一切ok了:

[root@lunar install]# crsctl status res -t
--------------------------------------------------------------------------------
NAME           TARGET  STATE        SERVER                   STATE_DETAILS       
--------------------------------------------------------------------------------
Local Resources
--------------------------------------------------------------------------------
ora.DATA.dg
               ONLINE  ONLINE       lunar                                        
ora.asm
               ONLINE  ONLINE       lunar                    Started             
ora.ons
               OFFLINE OFFLINE      lunar                                        
--------------------------------------------------------------------------------
Cluster Resources
--------------------------------------------------------------------------------
ora.cssd
      1        ONLINE  ONLINE       lunar                                        
ora.diskmon
      1        OFFLINE OFFLINE                                                   
ora.evmd
      1        ONLINE  ONLINE       lunar                                        
[root@lunar install]# 

总结:
1,在发现has或者crs异常时,不要stop crs或者stop has
2,修改主机名或者IP时,发现错误了,不要stop crs或者stop has(后续的一些操作需要这些资源)
3,在HAS环境中修改主机名和IP的过程:
(1)先用roothas.pl -deconfig -force清理老配置
(2)修改主机名(/etc/hosts,/etc/sysconfig/network,hostname等等)
(3)./roothas.pl (自动根据当前配置生成新的配置信息)
(4)添加ASM资源
(5)添加磁盘组
(6)重启HAS

发表在 ASM, RAC | 标签为 , , | 留下评论

测试在线重定义功能

9i开始,Oracle引入了在线重定义功能,但是bug比较多,10g时,如果数据量比较大,有些特殊场景,也有bug。
因此,前几天有同事需要测试在线重定义的功能,我查了下MOS,做个demo,做一个功能测试,如果生产上在低版本数据库执行在线重定义功能时,请仔细查看MOS上相关的常见问题。

22:28:49 SQL> select * from v$version;

BANNER
----------------------------------------------------------------
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi
PL/SQL Release 10.2.0.4.0 - Production
CORE    10.2.0.4.0      Production
TNS for Linux: Version 10.2.0.4.0 - Production
NLSRTL Version 10.2.0.4.0 - Production

已用时间:  00: 00: 00.01
22:30:24 SQL> select 'www.lunar2013.com' lunar,sysdate from dual;

LUNAR                            SYSDATE
-------------------------------- --------------
www.lunar2013.com                05-7月 -14

已用时间:  00: 00: 00.00
22:31:11 SQL> 

–创建测试表

CREATE TABLE unpar_table (
a NUMBER, y number,
name VARCHAR2(100), date_used date);

alter table unpar_table ADD (CONSTRAINT unpar_table_pk PRIMARY KEY (a,y));

-- load table with 1,000,000 rows
begin
	for i in 1 .. 1000
	loop
		for j in 1 .. 1000
		loop
		insert into unpar_table values ( i, j, dbms_random.random, sysdate-j );
		end loop;
	end loop;
end;
/
commit;

–收集统计信息

EXEC DBMS_STATS.gather_table_stats(user, 'unpar_table', cascade => TRUE);
SELECT num_rows FROM user_tables WHERE table_name = 'UNPAR_TABLE';

–创建空的分区表

CREATE TABLE par_table (
a NUMBER, y number,
name VARCHAR2(100),date_used DATE)
PARTITION BY RANGE (date_used)
(PARTITION unpar_table_12 VALUES LESS THAN (TO_DATE('10/07/2012', 'DD/MM/YYYY')),
PARTITION unpar_table_15 VALUES LESS THAN (TO_DATE('15/07/2012', 'DD/MM/YYYY')),
PARTITION unpar_table_MX VALUES LESS THAN (MAXVALUE));

–执行Redefinition.can_redef_table,验证unpar_table表是否可以在线重定义,如果不可以会给出建议:
EXEC Dbms_Redefinition.can_redef_table(USER, ‘unpar_table’);
执行这一步的时候,如果缺少如下权限,那么会报如下错误:
第 1 行出现错误:
ORA-06550: 第 1 行, 第 7 列:
PLS-00201: 必须声明标识符 ‘DBMS_REDEFINITION’
ORA-06550: 第 1 行, 第 7 列:
解决方法:
grant execute on dbms_redefinition to lunar;

-- This procedure (DBMS_REDEFINITION.start_redef_table) creates a materialized view based on a CTAS, as we can see below with
-- the PREBUILT container table.
BEGIN
DBMS_REDEFINITION.start_redef_table(
uname => USER,
orig_table => 'unpar_table',
int_table => 'par_table');
END;
/

执行这一步的时候,如果缺少如下权限,那么会报如下错误:
第 1 行出现错误:
ORA-01031: 权限不足
ORA-06512: 在 “SYS.DBMS_REDEFINITION”, line 50
ORA-06512: 在 “SYS.DBMS_REDEFINITION”, line 1343
ORA-06512: 在 line 2
解决方法:
grant create any table to lunar;
grant alter any table to lunar;
grant drop any table to lunar;
grant lock any table to lunar;
grant select any table to lunar;

22:16:46 SQL> select mview_name,container_name, build_mode from user_mviews;

MVIEW_NAME                     CONTAINER_NAME                 BUILD_MOD
------------------------------ ------------------------------ ---------
PAR_TABLE                      PAR_TABLE                      PREBUILT

–开启DBMS_REDEFINITION.start_redef_table后,向unpar_table表中插入1000行数据
此时,系统会使用mview log来记录该表的变化,可以查询MLOG$_UNPAR_TABLE来确认这一点:

begin
	for i in 1001 .. 1010
	loop
		for j in 1001 .. 1100
		loop
		insert into unpar_table values ( i, j, dbms_random.random, sysdate-j );
		end loop;
	end loop;
end;
/
commit;

22:17:07 SQL> select count(*) from MLOG$_UNPAR_TABLE;

  COUNT(*)
----------
      1000

已用时间:  00: 00: 00.01
22:17:12 SQL> select count(*) from unpar_table;

  COUNT(*)
----------
   1001000

已用时间:  00: 00: 00.07
22:17:27 SQL> select count(*) from par_table;

  COUNT(*)
----------
   1000000

已用时间:  00: 00: 00.20
22:17:48 SQL> 

–执行dbms_redefinition.sync_interim_table,类似MVIEW FAST REFRESH
–该操作将MLOG$_UNPAR_TABLE的内容同步到par_table,并在同步后purge自己
–在执行dbms_redefinition.finish_redef_table之前,可以执行多次

BEGIN
dbms_redefinition.sync_interim_table(
uname => USER,
orig_table => 'unpar_table',
int_table => 'par_table');
END;

22:18:35 SQL> select count(*) from MLOG$_UNPAR_TABLE;

  COUNT(*)
----------
         0

已用时间:  00: 00: 00.00
22:22:52 SQL> select count(*) from unpar_table;

  COUNT(*)
----------
   1001000

已用时间:  00: 00: 00.06
22:22:58 SQL> select count(*) from par_table;

  COUNT(*)
----------
   1001000

已用时间:  00: 00: 00.06
22:23:03 SQL> 

ALTER TABLE par_table ADD (CONSTRAINT par_table_pk2 PRIMARY KEY (a,y));
EXEC DBMS_STATS.gather_table_stats(USER, 'par_table', cascade => TRUE);

–完成在线重定义的操作,切换两个表:

BEGIN
dbms_redefinition.finish_redef_table(
uname => USER,
orig_table => 'unpar_table',
int_table => 'par_table');
END;
/

22:27:49 SQL> select count(*) from MLOG$_UNPAR_TABLE;
select count(*) from MLOG$_UNPAR_TABLE
                     *
第 1 行出现错误:
ORA-00942: 表或视图不存在


已用时间:  00: 00: 00.00
22:28:02 SQL> select count(*) from unpar_table;

  COUNT(*)
----------
   1001000

已用时间:  00: 00: 00.06
22:28:10 SQL> select count(*) from par_table;

  COUNT(*)
----------
   1001000

已用时间:  00: 00: 00.06
22:28:15 SQL> 

22:28:32 SQL> SELECT partitioned FROM user_tables WHERE table_name = 'UNPAR_TABLE';

PAR
---
YES

已用时间:  00: 00: 00.02
22:28:34 SQL> SELECT partition_name, num_rows FROM user_tab_partitions WHERE table_name = 'UNPAR_TABLE';

PARTITION_NAME                   NUM_ROWS
------------------------------ ----------
UNPAR_TABLE_12                     274384
UNPAR_TABLE_15                       5000
UNPAR_TABLE_MX                     721140

已用时间:  00: 00: 00.13
22:28:38 SQL> 

22:28:38 SQL> drop TABLE par_table cascade constraints;

表已删除。

已用时间:  00: 00: 00.06
22:28:49 SQL> 
发表在 FAQ | 标签为 , | 留下评论

exadata巡检报告的模板

最近有几个兄弟要exadata巡检报告的模板,完善了一下,大概200页左右:
1

2

3

4

5

6

7


由于里面有大量客户的资料,因此暂时设置为需要口令下载的,有需要的兄弟直接联系我

后续如果有机会,将不断更新,加入新的内容,O(∩_∩)O哈哈~

不过现在没有环境了,有需要的可以跟我联系,我免费检查,这样一举两得,我完善了自己的知识库,朋友们可以完成工作任务,O(∩_∩)O哈哈~

Exadata_HealthCheck_模板下载地址:
Exadata_HealthCheck_模板

发表在 日常运维 | 标签为 , , | 10 条评论

让“select min(xxx),max(xxx) from xxx”走索引

首先,做一个测试表:

[oracle@lunar /]$ ss

SQL*Plus: Release 11.2.0.3.0 Production on Sat Jun 7 21:29:52 2014

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

Welcome Lunar's oracle world!

Love you , baby !

Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning and Real Application Testing options

SYS@lunar>conn lunar/lunar
Welcome Lunar's oracle world!

Love you , baby !

Connected.
LUNAR@lunar>create table lunar as select * from dba_extents;

Table created.

Elapsed: 00:00:04.61

在extent_id列上创建非唯一索引:

LUNAR@lunar>create index idx_lunar_extent_id on lunar(extent_id) ;

Index created.

Elapsed: 00:00:00.02

LUNAR@lunar>EXEC DBMS_STATS.GATHER_TABLE_STATS(OWNNAME => 'LUNAR',TABNAME => 'LUNAR',DEGREE => 5,
 2  CASCADE => TRUE,ESTIMATE_PERCENT => DBMS_STATS.AUTO_SAMPLE_SIZE);

PL/SQL procedure successfully completed.

Elapsed: 00:00:01.45

下面的语句没有走索引:

LUNAR@lunar>select min(extent_id),max(extent_id) from lunar;

MIN(EXTENT_ID) MAX(EXTENT_ID)
-------------- --------------
             0             61

Elapsed: 00:00:00.01

Execution Plan
----------------------------------------------------------
Plan hash value: 291688323

----------------------------------------------------------------------------
| Id  | Operation          | Name  | Rows  | Bytes | Cost (%CPU)| Time     |
----------------------------------------------------------------------------
|   0 | SELECT STATEMENT   |       |     1 |     3 |    16   (0)| 00:00:01 |
|   1 |  SORT AGGREGATE    |       |     1 |     3 |            |          |
|   2 |   TABLE ACCESS FULL| LUNAR |  5223 | 15669 |    16   (0)| 00:00:01 |
----------------------------------------------------------------------------


Statistics
----------------------------------------------------------
          0  recursive calls
          0  db block gets
         51  consistent gets
          0  physical reads
          0  redo size
        610  bytes sent via SQL*Net to client
        524  bytes received via SQL*Net from client
          2  SQL*Net roundtrips to/from client
          0  sorts (memory)
          0  sorts (disk)
          1  rows processed

LUNAR@lunar>

手工指定IDX_LUNAR_EXTENT_ID时,也不走索引:

LUNAR@lunar>select /*+ index(lunar IDX_LUNAR_EXTENT_ID) */ min(extent_id),max(extent_id) from lunar;

MIN(EXTENT_ID) MAX(EXTENT_ID)
-------------- --------------
             0             61

Elapsed: 00:00:00.01

Execution Plan
----------------------------------------------------------
Plan hash value: 291688323

----------------------------------------------------------------------------
| Id  | Operation          | Name  | Rows  | Bytes | Cost (%CPU)| Time     |
----------------------------------------------------------------------------
|   0 | SELECT STATEMENT   |       |     1 |     3 |    16   (0)| 00:00:01 |
|   1 |  SORT AGGREGATE    |       |     1 |     3 |            |          |
|   2 |   TABLE ACCESS FULL| LUNAR |  5223 | 15669 |    16   (0)| 00:00:01 |
----------------------------------------------------------------------------


Statistics
----------------------------------------------------------
          1  recursive calls
          0  db block gets
         50  consistent gets
          0  physical reads
          0  redo size
        610  bytes sent via SQL*Net to client
        524  bytes received via SQL*Net from client
          2  SQL*Net roundtrips to/from client
          0  sorts (memory)
          0  sorts (disk)
          1  rows processed

LUNAR@lunar>

指定该列为非空时,可以走索引(Oracle的索引不保存空值):

LUNAR@lunar>alter table lunar modify extent_id not null;

Table altered.

Elapsed: 00:00:00.24
LUNAR@lunar>

可以看到,无论是否使用hint都走索引了:

LUNAR@lunar>set autotrace on
LUNAR@lunar>select /*+ index(lunar IDX_LUNAR_EXTENT_ID) */ min(extent_id),max(extent_id) from lunar;

MIN(EXTENT_ID) MAX(EXTENT_ID)
-------------- --------------
             0             61

Elapsed: 00:00:00.00

Execution Plan
----------------------------------------------------------
Plan hash value: 1897601393

----------------------------------------------------------------------------------------
| Id  | Operation        | Name                | Rows  | Bytes | Cost (%CPU)| Time     |
----------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT |                     |     1 |     3 |    11   (0)| 00:00:01 |
|   1 |  SORT AGGREGATE  |                     |     1 |     3 |            |          |
|   2 |   INDEX FULL SCAN| IDX_LUNAR_EXTENT_ID |  5223 | 15669 |    11   (0)| 00:00:01 |
----------------------------------------------------------------------------------------
注意: 使用hint时,走的是“INDEX FULL SCAN”

Statistics
----------------------------------------------------------
          0  recursive calls
          0  db block gets
         11  consistent gets
          0  physical reads
          0  redo size
        610  bytes sent via SQL*Net to client
        524  bytes received via SQL*Net from client
          2  SQL*Net roundtrips to/from client
          0  sorts (memory)
          0  sorts (disk)
          1  rows processed

LUNAR@lunar>select min(extent_id),max(extent_id) from lunar;

MIN(EXTENT_ID) MAX(EXTENT_ID)
-------------- --------------
             0             61

Elapsed: 00:00:00.01

Execution Plan
----------------------------------------------------------
Plan hash value: 2695027278

---------------------------------------------------------------------------------------------
| Id  | Operation             | Name                | Rows  | Bytes | Cost (%CPU)| Time     |
---------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT      |                     |     1 |     3 |     4   (0)| 00:00:01 |
|   1 |  SORT AGGREGATE       |                     |     1 |     3 |            |          |
|   2 |   INDEX FAST FULL SCAN| IDX_LUNAR_EXTENT_ID |  5223 | 15669 |     4   (0)| 00:00:01 |
---------------------------------------------------------------------------------------------
注意: 不使用hint时,走的是“INDEX FAST FULL SCAN”


Statistics
----------------------------------------------------------
          1  recursive calls
          0  db block gets
         15  consistent gets
          0  physical reads
          0  redo size
        610  bytes sent via SQL*Net to client
        524  bytes received via SQL*Net from client
          2  SQL*Net roundtrips to/from client
          0  sorts (memory)
          0  sorts (disk)
          1  rows processed

LUNAR@lunar>

再次验证,依然这个结果:
LUNAR@lunar>alter table lunar modify extent_id null;

Table altered.

Elapsed: 00:00:00.01

LUNAR@lunar>select min(extent_id),max(extent_id) from lunar;

MIN(EXTENT_ID) MAX(EXTENT_ID)
-------------- --------------
             0             61

Elapsed: 00:00:00.01

Execution Plan
----------------------------------------------------------
Plan hash value: 291688323

----------------------------------------------------------------------------
| Id  | Operation          | Name  | Rows  | Bytes | Cost (%CPU)| Time     |
----------------------------------------------------------------------------
|   0 | SELECT STATEMENT   |       |     1 |     3 |    16   (0)| 00:00:01 |
|   1 |  SORT AGGREGATE    |       |     1 |     3 |            |          |
|   2 |   TABLE ACCESS FULL| LUNAR |  5223 | 15669 |    16   (0)| 00:00:01 |
----------------------------------------------------------------------------


Statistics
----------------------------------------------------------
         22  recursive calls
          0  db block gets
         75  consistent gets
          0  physical reads
          0  redo size
        610  bytes sent via SQL*Net to client
        524  bytes received via SQL*Net from client
          2  SQL*Net roundtrips to/from client
          6  sorts (memory)
          0  sorts (disk)
          1  rows processed

LUNAR@lunar>

单独查询最小值或者最大值时,也可以走索引,采用“INDEX FULL SCAN (MIN/MAX)”:

LUNAR@lunar>select min(extent_id) from lunar;

MIN(EXTENT_ID)
--------------
             0

Elapsed: 00:00:00.01

Execution Plan
----------------------------------------------------------
Plan hash value: 4158629481

--------------------------------------------------------------------------------------------------
| Id  | Operation                  | Name                | Rows  | Bytes | Cost (%CPU)| Time     |
--------------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT           |                     |     1 |     3 |     2   (0)| 00:00:01 |
|   1 |  SORT AGGREGATE            |                     |     1 |     3 |            |          |
|   2 |   INDEX FULL SCAN (MIN/MAX)| IDX_LUNAR_EXTENT_ID |     1 |     3 |     2   (0)| 00:00:01 |
--------------------------------------------------------------------------------------------------


Statistics
----------------------------------------------------------
          1  recursive calls
          0  db block gets
          2  consistent gets
          0  physical reads
          0  redo size
        531  bytes sent via SQL*Net to client
        524  bytes received via SQL*Net from client
          2  SQL*Net roundtrips to/from client
          0  sorts (memory)
          0  sorts (disk)
          1  rows processed

LUNAR@lunar>select max(extent_id) from lunar;

MAX(EXTENT_ID)
--------------
            61

Elapsed: 00:00:00.01

Execution Plan
----------------------------------------------------------
Plan hash value: 4158629481

--------------------------------------------------------------------------------------------------
| Id  | Operation                  | Name                | Rows  | Bytes | Cost (%CPU)| Time     |
--------------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT           |                     |     1 |     3 |     2   (0)| 00:00:01 |
|   1 |  SORT AGGREGATE            |                     |     1 |     3 |            |          |
|   2 |   INDEX FULL SCAN (MIN/MAX)| IDX_LUNAR_EXTENT_ID |     1 |     3 |     2   (0)| 00:00:01 |
--------------------------------------------------------------------------------------------------


Statistics
----------------------------------------------------------
          1  recursive calls
          0  db block gets
          2  consistent gets
          0  physical reads
          0  redo size
        532  bytes sent via SQL*Net to client
        524  bytes received via SQL*Net from client
          2  SQL*Net roundtrips to/from client
          0  sorts (memory)
          0  sorts (disk)
          1  rows processed

LUNAR@lunar>

假设,在不能修改表结构的情况下,怎么才能让“select min(extent_id),max(extent_id) from lunar”走索引呢?
参考了网上的一些建议,改写sql如下:

LUNAR@lunar>select 
  2  (select min(extent_id) from lunar) as min_extent_id,
  3  (select max(extent_id) from lunar) as max_extent_id
  4  from dual;

MIN_EXTENT_ID MAX_EXTENT_ID
------------- -------------
            0            61

Elapsed: 00:00:00.01

Execution Plan
----------------------------------------------------------
Plan hash value: 778639039

--------------------------------------------------------------------------------------------------
| Id  | Operation                  | Name                | Rows  | Bytes | Cost (%CPU)| Time     |
--------------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT           |                     |     1 |       |     2   (0)| 00:00:01 |
|   1 |  SORT AGGREGATE            |                     |     1 |     3 |            |          |
|   2 |   INDEX FULL SCAN (MIN/MAX)| IDX_LUNAR_EXTENT_ID |     1 |     3 |     2   (0)| 00:00:01 |
|   3 |  SORT AGGREGATE            |                     |     1 |     3 |            |          |
|   4 |   INDEX FULL SCAN (MIN/MAX)| IDX_LUNAR_EXTENT_ID |     1 |     3 |     2   (0)| 00:00:01 |
|   5 |  FAST DUAL                 |                     |     1 |       |     2   (0)| 00:00:01 |
--------------------------------------------------------------------------------------------------


Statistics
----------------------------------------------------------
          1  recursive calls
          0  db block gets
          4  consistent gets
          0  physical reads
          0  redo size
        608  bytes sent via SQL*Net to client
        524  bytes received via SQL*Net from client
          2  SQL*Net roundtrips to/from client
          0  sorts (memory)
          0  sorts (disk)
          1  rows processed

LUNAR@lunar>
发表在 Performence Tuning | 标签为 | 留下评论