Timesten配置异步写(AWT)Cache

之前写了篇timesten为Oracle配置IMDB Cache的方法,由于我后面需要做异步写(AWT)cache的配置,所以又重新整理了一份文档。在余下部分中,命令的前缀如果为空,表示实在cmd命令行下执行的,如果是SQL> 开头则表示是在oracel中执行的,如果是Command> 则表示是在timesten中执行的。


0.----------------------------------------------

1)如果安装timesten的时候没有设置TSN,需要设置。
否则,在后面的配置中会出现错误提示:no tns_admin specified during installation - use ttModInstall -tns_admin to fix..

2)设置环境变量:
TNS_ADMIN = C:\Oracle\product\11.1.0\db_1\NETWORK\ADMIN
ORACLE_HOME = C:\Oracle\product\11.1.0\db_1

设完环境变量后,如果有打开cmd终端,关闭后重新打开

3)在cmd下输入如下命令:

ttModInstall -tns_admin C:\Oracle\product\11.1.0\db_1\NETWORK\ADMIN

一路回车执行完

4)运行完后在cmd下执行

ttstatus 

查看timesten的daemon是否正常重启,因为我在测试时发现有时没有正常重启,应该是没有结束掉timesten的守护进程,
这时需要手动把timesten的守护进程结束,然后重启就可以。如果ttstatus不能正常查看,则执行下述命令,否则跳过。

4.1)运行如下命令尝试关闭守护进程:

ttDaemonAdmin -stop

运行完后给出下述错误提示
ttDaemonAdmin: cannot communicate with daemon, but a
pid file exists: C:\TimesTen\TT1122~1\srv\info/timestend.pid
indicating that there is a daemon, pid 1188.
Use the -force option to kill that process.

4.2)执行如下命令,手动结束pid为1188的进程(进程ID1188,因机器而异,我的刚好是1188)

ntsd -c q -p 1188

4.3)重新启动timesten的守护进程

ttDaemonAdmin -start

1.------------------------------------------
在oracle中操作,创建如下元素:
■ The timesten user
■ The Oracle tables owned by the timesten user to store information about cache grids
■ The TT_CACHE_ADMIN_ROLE role that defines privileges on these Oracle tables

在cmd下运行

cd C:\TimesTen\tt1122_32\oraclescripts
sqlplus sys/orcl as sysdba
SQL> CREATE TABLESPACE cachetblsp DATAFILE 'datfttuser.dbf' SIZE 100M;
SQL> @initCacheGlobalSchema "cachetblsp";

2.------------------------------------------
Then use SQL*Plus to perform the following operations:
■ Create a cache administration user.
■ Run the SQL*Plus script TimesTen_install_ dir/oraclescripts/grantCacheAdminPrivileges.sql to grant the cache administration user the minimum set of privileges required to perform cache grid and cache group operations.

在这里我将cache administration user命名为cacheuser

SQL> CREATE USER cacheuser IDENTIFIED BY oracle DEFAULT TABLESPACE cachetblsp QUOTA UNLIMITED ON cachetblsp;
SQL> @grantCacheAdminPrivileges "cacheuser";

3.------------------------------------------
查询Oracle的字符集

SQL> SELECT value FROM nls_database_parameters WHERE parameter='NLS_CHARACTERSET';
SQL> exit

timesten做cache时,字符集要与oracle相同,后面建timesten数据库要用到
4.-----------------------------------------------

这一步的前提条件:用户和表已建立,否则先建用户和表


1)用需要被cache的表的拥有者登录oracle

在我这里是oratt,密码oratt

sqlplus oratt/oratt

2)为cacheuser用户授予对oracle中需要被cache的表所需的权限
在我这里oracle中需要被cache的表是:event,event_data

SQL> GRANT SELECT ON event TO cacheuser;
SQL> GRANT INSERT ON event TO cacheuser;
SQL> GRANT UPDATE ON event TO cacheuser;
SQL> GRANT DELETE ON event TO cacheuser;

SQL> GRANT SELECT ON event_data TO cacheuser;
SQL> GRANT INSERT ON event_data TO cacheuser;
SQL> GRANT UPDATE ON event_data TO cacheuser;
SQL> GRANT DELETE ON event_data TO cacheuser;

SQL> exit

5.-----------------------------------------------
1)在timesten中创建DSN
在odbc中创建用户DSN或系统DSN
设置如下属性:
Data Source Name:tt_db
■ Data Store Path + Name: C:\timesten\tt_db\tt_db
(数据文件实际存储在C:\timesten\tt_db\)
■ Permanent Data Size: 64(根据需要设置)
■ Oracle Net Service Name: orcl
■ Oracle Password:oracle(与下面配置的oracle cache administrator的密码相同)
■ Database Character Set: ZHS16GBK(与之前查询的oracle字符集相同)
■ Transaction Log Directory:C:\timesten\tt_db\log

(事务日志保存在:C:\timesten\tt_db\log)
其他属性使用默认值
2)建立C:\timesten\tt_db,否则在下面的操作中执行ttisql gbgprs会出现836的错误
3)建立文件夹C:\timesten\tt_db\log,否则后面的操作会出现错误 715: Unable to access log directory
6.-----------------------------------------------
在timesten中创建两种用户:
A)cache manager用户,与Oracle中的一个能访问cache表的用户名相同,
这个用户的用户名可以是oracle中的cache administrator,schema user,或其他现存的用户。cache manager用户用于创建cache grid和cache groups
B)一个或多个cache table用户,与oracle中要被cache表的拥有者用户名相同(schema user)

 

1)创建cache manager用户

ttIsql tt_db
Command> CREATE USER cacheuser IDENTIFIED BY timesten;
Command> GRANT CREATE SESSION, CACHE_MANAGER, CREATE ANY TABLE TO cacheuser;

2)创建cache table用户并授予连接权限

在我这里建立了一个cache table用户oratt/oratt

Command> CREATE USER oratt IDENTIFIED BY oratt;
Command> GRANT CREATE SESSION TO oratt;
Command> exit

7.----------------------------------------------

1)用建好的cacheuser登录timesten,OraclePWD是与cacheuser同名的oracle中的cacheuser的密码。

Command> ttIsql "DSN=tt_db;UID=cacheuser;PWD=timesten;OraclePWD=oracle"

//如果是用oratt用户登录,则OraclePWD是与oratt同名的oracle中的oratt用户的密码。
//ttIsql "DSN=oratt;UID=orat;PWD=orat;OraclePWD=oratt"
//如果执行的操作不需要访问oracle,就可以不输入OraclePWD。例如做可写cache时,执行update和insert会修改oracle中相应的表。
//但理论上与oracle的通信是cacheuser用户的任务,但为什么以oratt登录时,在会对oracle产生操作时,也需要用到OraclePWD,这点还有些疑问

 

2)使用内置的存储过程ttCacheUidPwdSet来设置Oracle cache administration user name 和 password:

Command> call ttCacheUidPwdSet('cacheuser','oracle');

3)创建cache grid

Command> call ttGridCreate('myGrid');

4)关联timesten数据库和创建好的cache grid 'myGrid'

Command> call ttGridNameSet('myGrid');

5)创建cache groups
前提条件:oracle中已建好要被cache的表

注意:表定义要和oracle中一致,但是外键可去掉。我这里配置了基于时间的滑动窗口数据老化策略:

AGING USE event_date LIFETIME 30 second CYCLE 15 second ON

意思是基于event_date的时间,如果event_date的时间与当前时间差超过30秒,则自动从timesten中删除,每隔15秒会运行一次这样检查。由于我event_data的外键是event,且设置了on delete cascade所以event_data也会跟着删除。这样可以保证timesten中的数据最多保存45秒内的。时间设置的比较小,是为了方便测试。

second参数还可以设置为minute, hour, day。Aging的具体信息参考timesten的官方文档cache user guide

Command> CREATE ASYNCHRONOUS WRITETHROUGH CACHE GROUP cacheuser.event_cache
FROM oratt.EVENT
(
event_id NUMBER(10) not null,
event_date        DATE not null,
primary key (EVENT_ID, EVENT_DATE)
)
AGING USE event_date LIFETIME 30 second CYCLE 15 second ON,

oratt.EVENT_DATA
(
event_id NUMBER(10) not null,
data_value NUMBER not null,

primary key (EVENT_ID),
foreign key (EVENT_ID)
references oratt.EVENT (EVENT_ID) on delete cascade
)
;

 

6)启动复制代理
做可写cache需要启动复制代理

Command> call ttRepStart;

如果配置只读cache需要启动cache代理,如果只是可写cache,可以不用启动。
#call ttCacheStart;


也可以在cmd下执行“ttAdmin -repStart tt_db”命令来启动复制代理

/****************************************************************************
其他参考信息:

The replication agent does not start unless there is at least one AWT cache group or
replication scheme in the TimesTen database.

If the replication agent is running, it must be stopped before you can issue another
CREATE ASYNCHRONOUS WRITETHROUGH CACHE GROUP statement or a DROP
CACHE GROUP statement on an AWT cache group.

停止复制代理的方法:
call ttRepStop;
或者在cmd下执行
ttAdmin -repStop tt_db

You can set a replication agent start policy to determine how and when the replication
agent process starts on a TimesTen database.
The default start policy is manual which means the replication agent must be started
manually by calling the ttRepStart built-in procedure or running a ttAdmin
-repStart utility command. To manually stop a running replication agent process,
call the ttRepStop built-in procedure or run a ttAdmin -repStop utility
command.
The start policy can be set to always so that the replication agent starts automatically
when the TimesTen main daemon process starts. With the always start policy, the
replication agent cannot be stopped when the main daemon is running unless the start
policy is changed to either manual or norestart and then a manual stop is issued by
calling the ttRepStop built-in procedure or running a ttAdmin -repStop utility
command.
*****************************************************************************/

exit

7)设置复制代理启动策略为always(可选)

复制代理默认启动方式是manual,可以设置为always,这样当timesten的进程启动时,就会自动启动。
在cmd下运行

ttAdmin -repPolicy always tt_db

#cache代理的设置方法(如果有启动cache代理的话,可以配置)
ttAdmin -cachePolicy always tt_db


8)为timesten中的cacheuser配置访问timesten中的oratt用户的表的权限
用tt_db的实例管理员登录,如果不输入uid和pwd,默认是用当前windows用户登录

ttisql tt_db

Command> GRANT SELECT ON oratt.event TO cacheuser;
Command> GRANT INSERT ON oratt.event TO cacheuser;
Command> GRANT UPDATE ON oratt.event TO cacheuser;
Command> GRANT DELETE ON oratt.event TO cacheuser;

Command> GRANT SELECT ON oratt.event_data TO cacheuser;
Command> GRANT INSERT ON oratt.event_data TO cacheuser;
Command> GRANT UPDATE ON oratt.event_data TO cacheuser;
Command> GRANT DELETE ON oratt.event_data TO cacheuser;

8-------------------------------------------------------------
检查timesten和oracle之间的连通性
To test the connectivity between the TimesTen and Oracle databases, set the
passthrough level to 3 and execute the following query, to be processed on the Oracle
database, as the cache manager user:
passthrough 设置为3时,sql命令会强制在Oracle中执行,passthrough默认值为0

连接上tt_db后执行

Command> passthrough 3;
Command> SELECT * FROM V$VERSION;
Command> passthrough 0;

如果能查询到数据,表示与Oracle的连通是正常的
exit
9.-------------------------------------------
设置ram为总是在内存,默认策略是inuse
在cmd下输入:

ttadmin -rampolicy always tt_db

10.-----------------------------------------------

往timesten中插入数据测试

java连接timesten的方法可以参考这里

注意:数据在timesten中插入成功,并不表示在oracle中也会成功,因为有可能在timesten中的表删掉了一些外键,
而在oracle中执行时会因为外键不存在的问题而插入失败,此时数据不会插入到oracle中。
如果在oracle中查询不到刚刚插入的数据,可以设置passthrough 3,强制将sql语句在oracle中执行,来查看是否会出现错误。

Command> passthrough 3;
Command> insert ....
Command> passthrough 0;

11.----------------------------------------------------------------------

如果配置的permSize太小,后期需要修改,可以采用下面的方法:
修改permSize和tempSize
在odbc中修改,如果配置cache,需要停止cache代理和复制代理,连接上tt_db后执行如下命令:

Command> call ttCacheStop;
Command> call ttRepStop;

 

如果rampolicy设置为always,则需要先修改为manual

ttadmin -rampolicy manual "dsn=timesten_db";


然后需要ramunload,将数据库从内存中卸载,然后再加载。
使用实例管理员进行的操作

ttadmin -ramunload "dsn=timesten_db";
ttadmin -ramload "dsn=timesten_db";


最后可以重新启动cache代理和复制代理

Command> call ttCacheStart;
Command> call ttRepStart;

 

posted @ 2013-01-12 14:51  NaN-Hax  阅读(1339)  评论(0编辑  收藏  举报