#debugfile /var/log/ha-debug
说明:调试日志文件文件,取默认值
logfile /var/log/ha-log
说明:系统运行日志文件,取默认值
#logfacility local0
说明:用于syslog()/logger的设备
keepalive 2
说明:心跳频率,自己设定。1:表示1秒;200ms:表示200毫秒
deadtime 30
说明:节点死亡时间阀值,就是从节点在过了10后还没有收到心跳就认为主节点死亡,自己设定
warntime 10
说明:发出警告时间,自己设定
udpport 694
说明:心跳信息传递的udp端口,自己设定
#bcast eth0 # Linux
说明:采用udp广播播来通知心跳,建议在副节点不只一台时使用
ucast eth0 172.30.31.68
说明:采用网卡eth0的udp单播来通知心跳,eth0的IP
#mcast eth0 225.0.0.1 694 1 0
说明:采用udp多播播来通知心跳,建议在副节点不只一台时使用
auto_failback off
说明:主节点重启成功后,资源是自动拿回到主节点还是等到副节点down调后拿回资源
node heartbeat1
说明:主节点名称,与uname –n保持一致。排在第一的默认为主节点,所以不要搞措顺序
node heartbeat2
说明:副节点名称,与uname –n保持一致
watchdog /dev/watchdog
说明:看门狗。如果本节点在超过一分钟后还没有发出心跳,那么本节点自动重启
以上这些是我个人认为必配项,下面这些是可选项
stonith baytech /etc/ha.d/conf/stonith.baytech
说明:主/副等所有节点的一种校验。
respawn userid /path/name/to/run
说明:和heartbeat必须一起启动的本地服务
ping 10.10.10.254
说明:伪节点IP,伪节点就是其失效时主/副节点不会正常工作但本身不是主/副节点之一。
respawn hacluster /usr/lib/heartbeat/ipfail
说明:与ping选项一起使用,取默认值。
baud 19200
说明:串口波特率,与serial一起使用。
serial /dev/ttyS0 # Linux
说明:采用串口来传递心跳信息。
Heartbeat安装及简单配置
ORA-01578坏块解决(2)
ORA-01578坏块解决(1)续集
如果在坏块之前,有rman备份,可以使用rman的备份来进行恢复,确保数据不会被丢失
1、使用rman进行恢复
[oracle@ECP-UC-DB1 ~]$ $ORACLE_HOME/bin/rman target /
Recovery Manager: Release 10.2.0.4.0 – Production on Sun Aug 14 22:21:13 2011
Copyright (c) 1982, 2007, Oracle. All rights reserved.
connected to target database: TEST (DBID=2056006906)
RMAN> blockrecover datafile 6 block 1477;
Starting blockrecover at 2011-08-14 22:21:16
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=145 devtype=DISK
channel ORA_DISK_1: restoring block(s)
channel ORA_DISK_1: specifying block(s) to restore from backup set
restoring blocks of datafile 00006
channel ORA_DISK_1: reading from backup piece /tmp/0fmk0ii5_1_1
channel ORA_DISK_1: restored block(s) from backup piece 1
piece handle=/tmp/0fmk0ii5_1_1 tag=TAG20110814T213357
channel ORA_DISK_1: block restore complete, elapsed time: 00:00:02
starting media recovery
media recovery complete, elapsed time: 00:00:03
Finished blockrecover at 2011-08-14 22:21:23
2、检查坏块是否被恢复
RMAN> backup check logical validate datafile 6;
Starting backup at 2011-08-14 22:22:11
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
input datafile fno=00006 name=/opt/oracle/oradata/test/xifenfei01.dbf
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 2011-08-14 22:22:12
RMAN> exit
Recovery Manager complete.
[oracle@ECP-UC-DB1 ~]$ sqlplus / as sysdba
SQL*Plus: Release 10.2.0.4.0 – Production on Sun Aug 14 22:22:17 2011
Copyright (c) 1982, 2007, Oracle. All Rights Reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 – 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> select file#,block#,blocks from v$database_block_corruption;
no rows selected
SQL> exit
Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 – 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
[oracle@ECP-UC-DB1 ~]$ dbv file =/opt/oracle/oradata/test/xifenfei01.dbf
DBVERIFY: Release 10.2.0.4.0 – Production on Sun Aug 14 22:22:38 2011
Copyright (c) 1982, 2007, Oracle. All rights reserved.
DBVERIFY – Verification starting : FILE = /opt/oracle/oradata/test/xifenfei01.dbf
DBVERIFY – Verification complete
Total Pages Examined : 2560
Total Pages Processed (Data) : 1372
Total Pages Failing (Data) : 0
Total Pages Processed (Index): 0
Total Pages Failing (Index): 0
Total Pages Processed (Other): 48
Total Pages Processed (Seg) : 0
Total Pages Failing (Seg) : 0
Total Pages Empty : 1140
Total Pages Marked Corrupt : 0
Total Pages Influx : 0
Highest block SCN : 1256690 (0.1256690)
3、验证数据是否正确
[oracle@ECP-UC-DB1 ~]$ sqlplus / as sysdba
SQL*Plus: Release 10.2.0.4.0 – Production on Sun Aug 14 22:34:18 2011
Copyright (c) 1982, 2007, Oracle. All Rights Reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 – 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> select count(*) from t_rep;
COUNT(*)
———-
49857
和ORA-01578坏块解决(1)中的模拟环境比较,数据恢复正确,坏块问题解决
ORA-01578坏块解决(1)
物化视图on prebuilt table
1、ORA-12059
执行语句:
CREATE MATERIALIZED VIEW mv_t2
on prebuilt TABLE
AS
SELECT * FROM SCOTT.emp
错误提示:
ORA-12059: prebuilt table “CHF”.”MV_T2″ does not exist
错误原因:
物化视图对应的表不存在(物化视图需要和表同名,结构相同)
解决方法:
CREATE TABLE mv_t2 AS
SELECT * FROM scott.emp WHERE 1=0;
2、ORA-23413
执行语句:
CREATE MATERIALIZED VIEW mv_t2
on prebuilt TABLE
WITH REDUCED PRECISION
refresh FAST on demand
AS
SELECT * FROM SCOTT.emp
错误提示:
ORA-23413: table “SCOTT”.”EMP” does not have a materialized view log
错误原因:
使用fast模式刷新物化视图,需要有物化视图日志
解决方法:
1)创建物化视图日志
CREATE MATERIALIZED VIEW LOG ON scott.emp ;
2)刷新模式改为force,其实实质是采用了complete刷新模式
3、ORA-12058
执行语句(mv log是基于rowid,表无主键)
CREATE MATERIALIZED VIEW mv_t2
on prebuilt TABLE
WITH REDUCED PRECISION
refresh FAST on DEMAND
WITH ROWID
AS
SELECT * FROM SCOTT.emp
错误提示:
ORA-12058: materialized view cannot use prebuilt table
错误原因:
fast刷新模式不能基于rowid进行
解决方法:
1)删除mv log,表添加主键,采用基于主键模式重新建mv log和物化视图
DROP MATERIALIZED VIEW mv_t1;
ALTER TABLE mv_t2 ADD PRIMARY KEY (EMPNO);
CREATE MATERIALIZED VIEW LOG ON scott.emp;
CREATE MATERIALIZED VIEW mv_t2
on prebuilt TABLE
WITH REDUCED PRECISION
refresh FAST on DEMAND
–WITH ROWID
AS
SELECT * FROM SCOTT.emp;
2)刷新模式改为force,其实实质是采用了complete刷新模式
4、总结
1)在执行创建物化视图之前,需要先创建同名、同结构表
2)如果使用fast模式刷新(疑惑在线重定义可以通过rowid实现,为什么直接通过物化视图就不可以),物化视图同表需要主键,需要物化视图日志
3)通过drop mv,发现同名表还存在,和on prebuilt table本质区别
bbed破坏数据文件
oracle 10g rman自动创建数据文件
oracle官方建议,如果修改过数据库结构后,需要立即重新备份数据库,我想通过试验验证该知识点。
试验过程是使用rman备份数据库,然后添加表空间,添加数据文件,创建表在新表空间和新数据文件上,然后关闭数据库,删除新添加的数据文件,再使用rman备份来恢复数据库。操作过程如下:
在线重定义原理探讨
1、准备测试表
SQL> create table t_d as select * from all_objects; Table created SQL> alter table t_d add primary key(object_id); Table altered SQL> create table t_d_t as select * from t_d where 1=0; Table created SQL> alter table t_d_t add primary key(object_id); Table altered SQL> select count(*) from T_D; COUNT(*) ---------- 48945 SQL> select count(*) from T_D_T; COUNT(*) ---------- 0
2、执行在线同步
SQL> EXEC DBMS_REDEFINITION.CAN_REDEF_TABLE(user, 'T_D', DBMS_REDEFINITION.CONS_USE_PK); PL/SQL procedure successfully completed SQL> EXEC DBMS_REDEFINITION.START_REDEF_TABLE(USER, 'T_D', 'T_D_T'); PL/SQL procedure successfully completed
3、查询相关物化视图
SQL> select owner,mview_name from user_mviews; OWNER MVIEW_NAME ------------------------------ ------------------------------ CHF T_D_T SQL> select log_owner,master,log_table from user_mview_logs; LOG_OWNER MASTER LOG_TABLE ------------------------------ ------------------------------ ------------------------------ CHF T_D MLOG$_T_D CREATE MATERIALIZED VIEW T_D_T ON PREBUILT TABLE REFRESH FAST ON DEMAND AS SELECT "T_D"."OWNER" "OWNER","T_D"."OBJECT_NAME" "OBJECT_NAME", "T_D"."SUBOBJECT_NAME" "SUBOBJECT_NAME","T_D"."OBJECT_ID" "OBJECT_ID", "T_D"."DATA_OBJECT_ID" "DATA_OBJECT_ID","T_D"."OBJECT_TYPE" "OBJECT_TYPE", "T_D"."CREATED" "CREATED","T_D"."LAST_DDL_TIME" "LAST_DDL_TIME", "T_D"."TIMESTAMP" "TIMESTAMP","T_D"."STATUS" "STATUS", "T_D"."TEMPORARY" "TEMPORARY","T_D"."GENERATED" "GENERATED", "T_D"."SECONDARY" "SECONDARY" FROM "CHF"."T_D" "T_D";
4、结束物化视图
SQL> EXEC DBMS_REDEFINITION.FINISH_REDEF_TABLE(USER, 'T_D', 'T_D_T'); PL/SQL procedure successfully completed
5、继续查询相关物化视图
SQL> select log_owner,master,log_table from user_mview_logs; SQL> select * from user_mviews; SQL> select owner,mview_name from user_mviews; OWNER MVIEW_NAME ------------------------------ ------------------------------ SQL> select log_owner,master,log_table from user_mview_logs; LOG_OWNER MASTER LOG_TABLE ------------------------------ ------------------------------ ------------------------ SQL> select count(*) from T_D_T; COUNT(*) ---------- 48945
6、由试验可以得出
6.1)在线重定义本质就是利用物化视图刷新实现数据迁移
6.2)DBMS_REDEFINITION.START_REDEF_TABLE实现功能:
6.2.1)创建含on prebuilt table的物化视图和物化视图日志
6.2.2)实现通过物化视图刷新当前表中数据进入中间表
6.3)dbms_redefinition.sync_interim_table实现物化视图刷新在执行5.2)操作过程中变化数据
6.4)DBMS_REDEFINITION.FINISH_REDEF_TABLE将锁定原表,防止表上的DML,物化视图执行刷新,完成刷新后,将删除物化视图和对应的日志,将中间表rename成目标表
7、如果表无主键时,区别有
7.1)执行在线定义语句,具体见表在线重定义(无主键)
7.2)创建物化视图语句上
create materialized view T_D_T on prebuilt table refresh fast on demand with rowid as select OWNER OWNER, OBJECT_NAME OBJECT_NAME, SUBOBJECT_NAME SUBOBJECT_NAME, OBJECT_ID OBJECT_ID, DATA_OBJECT_ID DATA_OBJECT_ID, OBJECT_TYPE OBJECT_TYPE, CREATED CREATED, LAST_DDL_TIME LAST_DDL_TIME, TIMESTAMP TIMESTAMP, STATUS STATUS, TEMPORARY TEMPORARY, GENERATED GENERATED, SECONDARY SECONDARY from "CHF"."T_D" "T_D";
RAC负载均衡配置
1、客户端均衡(Client-Side LB)
工作原理:当客户端发起连接时,会从地址列表中随机选取一个,再使用随机算法把连接请求分散到各个实例。
存在缺点:
1.1)分配连接时没有考虑每个节点的真实负载,最后分配不过不一定是平衡
1.2)随机算法需要长时间片,如果在短时间内同时发起多个连接,这些连接有可能被分配到一个节点上
1.3)有些情况下,连接可能被分配到故障节点上
配置方法:在tns中添加LOAD_BALANCE = YES条目
2、服务器端均衡(Server-Side LB)
工作原理:
2.1)该均衡实现是依赖于Listener收集的负载信息。在数据库运行过程中,PMON后台进程会收集数系统的负载信息,然后登记到Listener中。
2.2)PMON进程不仅会向本地的Listener注册,也会想其他节点上的Listener注册,但到底向何处注册,是由Remote_Listeners和Local_Listener这两个参数决定。Local_Listener不用设置,而Remote_Listeners需要设置,参数值有一个tnsnames项。
2.3)当收到客户端连接请求时,就会把连接转给负载最小的节点,这个节点可能是自己,也可能是其他节点,也就是Listener会转发客户端的连接请求。
配置方法:
SQL> show parameter listener; NAME TYPE VALUE ------------------------------------ ----------- ------------------------------ local_listener string remote_listener string LISTENERS_DEVDB tnsnames.ora LISTENERS_DEVDB = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = rac1-vip)(PORT = 1521)) (ADDRESS = (PROTOCOL = TCP)(HOST = rac2-vip)(PORT = 1521)) ) listener.ora(除掉SID_LIST_LISTENER_NAME项) LISTENER_RAC1 = (DESCRIPTION_LIST = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = rac1-vip)(PORT = 1521)(IP = FIRST)) (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.11)(PORT = 1521)(IP = FIRST)) ) )
3、两者联合使用
Server-Side LB和Client-Side LB不是互斥的,两者可以一起工作,这个时候客户端的连接请求会先从地址列表中随机选择一个地址,然后向该地址的Listener发送请求;Listener接到请求后,根据各个节点负载情况从中挑选出最合适的节点转发连接请求。
RAC Failover三种方式
1、Client-Side Connect Time Failover
1.1)在用户端tnsname中配置了多个地址,用户发起连接请求时,会先尝试连接地址表中的第一个地址,如果这个连接尝试失败,则继续尝试使用第二个地址,直至连接成功或者遍历了所有的地址。
1.2)这种Failover的特点是:在建立连接那一时刻起作用,一旦连接建立之后,节点出现故障都不会作处理,从而客户端的表现就是会话断开,用户程序必须重新建立连接。
启用该方法:在客户端tnsname.ora中添加FAILOVER=ON条目,因为这个参数默认值就是为NO,所以即使客户端不加该条目,也有这种Failover功能。
XFF_F = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.21)(PORT = 1521)) (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.22)(PORT = 1521)) (LOAD_BALANCE = yes) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = devdb) ) )
2、TAF(Transparent Application Failover)
2.1)在连接建立以后、应用系统运行过程中,如果某个实例发生故障,连接到这个实例上的用户会被自动迁移到其他的健康的实例上。对于应用程序而言,这个迁移过程是透明的,不需要用户的介入,当然在迁移过程中,未提交的事物会回滚。
2.2)与Client-Side Connect Time Failover比较起来,就是多了FAILOVER_MODE这一配置项,该配置项包含4个子项目
2.2.1)METHOD:可选值有BASIC和PRECONNECT
BASIC是指在感知到节点故障时才创建到其他实例的连接
PRECONNECT是在最初建立连接时就同时建立到所有实例的连接,当发生故障时,立刻就可以切换到其他链路上。
2.2.2)TYPE:可选值有SESSION和SELECT
两者的区别在于对select语句的处理,select表示如果发生故障迁移,正在执行的select语句将在新的节点上继续返回后续结果集;而session表示重新执行该select查询返回全部的结果。
2.2.3)DELAY表示重试间隔时间
2.2.4)RETRIES表示重试次数
XFF_T = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.21)(PORT = 1521)) (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.22)(PORT = 1521)) (LOAD_BALANCE = yes) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = devdb) (FAILOVER_MODE = (TYPE = SELECT) (METHOD = BASIC) (RETRIES = 180) (DELAY = 5) ) ) )
3、Server-Side TAF
3.1)Server-Side TAF具有TAF的所有特点
3.2)这种TAF是在服务器上配置,不需要在客户端进行相关配置,如果修改一个参数,不需要在所有的tns上修改,而只要修改服务器中的service即可
用户有两种角色可以选择
PREFERRED:首选实例,会优先选择拥有这个角色的实例提供服务
AVAILABLE:后备实例,当PREFERRED实例不可用时,才会转到AVAILABLE实例上
XFF_RAC = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.21)(PORT = 1521)) (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.22)(PORT = 1521)) (LOAD_BALANCE = yes) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = XFF) ) )