一. 安装TimesTen
TimesTen的安装很简单,直接执行安装程序,选择默认设置即可。在安装前,需要确认如下两点:
1.
2.
二. 配置TT数据库(即DSN)
TT数据库中,一个DSN即是一个TT实例。
1. 配置过程
在安装TT软件后,可通过如下步骤配置DSN:
1.
2.
3.
在选择DataSource Path时,要确保该目录已经存在。
且此处Database Character Set必须与Oracle的字符集相同,如果不同,后面还需要重新配置数据源。
4.
5.
6.
7.
正常情况下应如下图所示:
2. 查看TT状态
在cmd窗口,执行ttstatus检查tt状态:
C:\Documents and Settings\Administrator>ttstatus
TimesTen status report as of Tue Sep 11 11:02:45 2012
Daemon pid 696 port 53392 instance tt1122_32
TimesTen server pid 1244 started on port 53393
------------------------------------------------------------------------
Data store e:\mydemo\test_tt
There are 12 connections to the data store
Shared Memory KEY Global\test_tt.e||mydemo.SHM.10 HANDLE 0x288
PL/SQL Memory KEY Global\test_tt.e||mydemo.SHM.11 HANDLE 0x290 Address 0x5B8C000
0
Type
Process
Subdaemon
Subdaemon
Subdaemon
Subdaemon
Subdaemon
Subdaemon
Subdaemon
Subdaemon
Subdaemon
Subdaemon
Subdaemon
Replication policy
Cache Agent policy
PL/SQL enabled.
---------------------------------------------------------------------
Accessible by group WWW-B1818C3ACBB\None
End of report
可以看到 DataStore e:\mydemo\test_tt 已经在运行了,且有一些后台的服务线程也已经启动。且显示了相应的TimesTen监听端口号。比如主守护进程(Daemon)的端口号是17000;Server端的监听端口号是17002,这个端口号是当Client/Server配置的时候,远程Client端连接过来时,Server端这边的服务端口号;还有WebServer的端口号 17004,TimesTen自身带有一个自用的webserver的。
3. 创建TT用户
在command窗口,执行如下命令创建TT用户tt:
C:\Documents and Settings\Administrator>ttisql test_tt
Copyright (c) 1996-2011, Oracle.
Type ? or "help" for help, type "exit" to quit ttIsql.
connect "DSN=test_tt";
Connection successful: DSN=test_tt;UID=Administrator;DataStore=E:\MyDemo\test_tt
;DatabaseCharacterSet=ZHS16GBK;ConnectionCharacterSet=ZHS16GBK;DRIVER=C:\TimesTe
n\TT1122~1\bin\ttdv1122.dll;PermSize=64;TempSize=32;TypeMode=0;
(Default setting AutoCommit=1)
Command> create user tt identified by tt;
User created.
Command> grant all to tt;
Command> quit;
三. 设置Cache Connect
1. 创建Oracle用户
由于Cache Connect访问Oracle的时候,必须有一个用户在TimesTen和Oracle中是一样的,通过这个用户登录TimesTen之后,然后 Cache Connect的底层通过这个用户去和Oracle通讯,来进行数据的两边同步。在前面我们已经创建了用户tt,那么现在在oracle中,我们也创建同样的用户tt,并授予相应的Oracle权限。
以Oracle dba用户或系统用户登录Oracle,执行创建操作。
C:\Documents and Settings\Administrator>sqlplus system/test@test
SQL> create user tt identified by tt;
用户已创建。
SQL> grant connect,resource,create any trigger to tt;
授权成功。
SQL> grant dba to tt;
授权成功。
SQL> commit;
提交完成。
2. 更新DSN配置
在“控制面板 –> 管理工具 -> 数据源(ODBC)”的“系统DSN”页签,找到之前配置的数据源test_tt,执行如下步骤更新配置:
1.
2.
3.
3. 创建测试表
以tt用户登录Oracle,创建cache测试表。
SQL> connect tt/tt@orcl
已连接。
SQL> create table test(a int primary key, b char(10));
表已创建。
SQL> insert into test values(1,’aaa’);
已创建 1 行。
SQL> insert into test values(2,’bbb’);
已创建 1 行。
SQL> commit;
提交完成。
SQL>
4. 创建cache
C:\Documents and Settings\Administrator>ttisql test_tt
Command> call ttcacheuidpwdset(’tt’,'tt’);
Command> call ttcachestart;
5. 创建TimesTen表空间
在此之后要创建一个cache grid,只cache grid的第一个数据库成员需要执行这个操作。注意,只有cache manager user能创建和管理cache grid,一个cache database只能属于一个cache grid,然后可以使用过程ttgridinfo来检查是否创建成功。
在创建cache grid前,要先创建表空间,然后建timesten用户,操作创建grid才不会报错。
创建一个单独的表空间来管理缓存到timesten 的对象
SQL>create tablespace timesten datafile 'D:\oracle\product\10.2.0\oradata\orcl\timesten.dbf' size 50m;
6. 创建timesten 用户
运行initCacheGlobalSchema.sql脚本来创建用户,这用户拥有存储cache grid 和grid member信息的表。这个脚本在%TimesTen_install_dir%/oraclescripts 目录下。
在创建之前,请切换到脚本所在目录,再以oracle dba或system用户登录:
C:\TimesTen\tt1122_32\oraclescripts>
C:\TimesTen\tt1122_32\oraclescripts>sqlplus system/Younuoda2006@orcl
SQL> @initCacheGlobalSchema "timesten";
Please enter the tablespace where TIMESTEN user is to be created
The value chosen for tablespace is timesten
******* Creation of TIMESTEN schema and TT_CACHE_ADMIN_ROLE starts *******
1. Creating TIMESTEN schema
2. Creating TIMESTEN.TT_GRIDID table
3. Creating TIMESTEN.TT_GRIDINFO table
4. Creating TT_CACHE_ADMIN_ROLE role
5. Granting privileges to TT_CACHE_ADMIN_ROLE
** Creation of TIMESTEN schema and TT_CACHE_ADMIN_ROLE done successfully **
PL/SQL 过程已成功完成。
7. 创建Grid
执行ttisql test_dsn连接内存库,创建Grid。
C:\Documents and Settings\Administrator>ttisql test_tt
Command> call ttGridCreate('myGrid');
Command> call ttGridNameSet('myGrid');
8. 创建Cache Group
1.
Command> create readonly cache group test_cg
其中,test_cg为Cache Group的名,test为前面在Oracle中创建的测试表。
2.
Command> cachegroups ;
Cache Group TT.TEST_CG:
1 cache group found.
在未装载前,cache group的自动刷新状态是Paused。
3.
Command> load cache group read commit every 10 rows; (注:原文有问题read应该为test_cg)
4.
Command> select * from test;
< 1, aaa
< 2, bbb
2 rows found.
此后,在Oracle数据库中插入到test表的数据,5秒钟之后都会被刷新到TimesTen中来,Cache Connect正常运转了。
5.
C:\Documents and Settings\Administrator>ttstatus test_tt
TimesTen status report as of Thu Sep 13 16:18:14 2012
Daemon pid 2812 port 53392 instance tt1122_32
TimesTen server pid 2640 started on port 53393
------------------------------------------------------------------------
Data store e:\mydemo\test_tt
There are 16 connections to the data store
Shared Memory KEY Global\test_tt.e||mydemo.SHM.10 HANDLE 0x294
PL/SQL Memory KEY Global\test_tt.e||mydemo.SHM.11 HANDLE 0x298 Address 0x5B8C0000
Type
Cache Agent
Cache Agent
Cache Agent
Cache Agent
Cache Agent
Subdaemon
Subdaemon
Subdaemon
Subdaemon
Subdaemon
Subdaemon
Subdaemon
Subdaemon
Subdaemon
Subdaemon
Subdaemon
Replication policy
Cache Agent policy
TimesTen's Cache agent is running for this data store
PL/SQL enabled.
------------------------------------------------------------------------
Accessible by group WWW-B1818C3ACBB\None
End of report
四. 用SQL Developer连接TT
在使用SQL Developer前,要确保本机上已经安装jdk。建议安装jdk1.5或jdk1.6版本。
1.
2.
选择“+”图标,或是在“连接”上右键选择“新建”。
3.
其中,dsn、datastore、oraclenetservicename均已在系统DSN下配置。
4.
5.
五. 异常处理
1. connect test_tt报错
Command> connect test_tt;
The command failed.
检查之后,发现是在ODBC中设置DataStore的路径时出现错误,MyDemo目录是在E盘下而不是D盘。改了之后就能连接了。
2. 执行call ttcacheuidpwdset(’tt’,'tt’)报错
场景一:
Command> call ttcacheuidpwdset('tt','tt');
The command failed.
在testtt数据源中,要在General Connection页,在User Id这一栏填上tt,再点击Cache Connect页,看到Oracle User ID已经填上了tt。在Oracle ID一栏填上Oracle的Service Name,在Oracle Password一栏填上对应的密码。
场景二:
Command> call ttcacheuidpwdset('tt','tt');
Warning
be called.
Warning
be called.
Warning
to support caching LOBS from Oracle.
该错误是由于tt用户没有dba权限引起的。
需要在Oracle中,执行
SQL> grant dba to tt;
SQL> grant create any table to tt;
3. create readonly cache group报错
Command> create readonly cache group read
>
>
> (a int primary key, b char(10));
报错:
Warning
agent status
Warning
可通过重启cache解决:
Command> call ttcachestop;
Command> call ttcachestart;