设置与Oracle数据库的连通性比较简单,但也是非常重要的工作。毕竟TimesTen与Oracle的集成,相较于独立的TimesTen,是使用更为广泛的场景。
  无论是后续建立Cache Group,还是简单的从Oracle加载数据到TimesTen,都需要预先设置TimesTen与Oracle数据库的连通性。
  首先看一张概念图:

  在TimesTen DSN的设置中,OracleNetServiceName指定了后端Oracle数据库的服务名,而实际的服务定义在tnsnames.ora中,这完全符合Oracle的惯例,简单来说,你可以新建一个tnsnames.ora, 把原有的Oracle服务的定义拷贝到这个文件,无论是单实例还是RAC,或者使用已有的tnsnames.ora。
  tnsnames.ora则指向实际的后端Oracle数据库,通常和TimesTen不在同一台主机上。
  那么,TimesTen在哪里去找这个tnsnames.ora文件呢? 可以在安装时指定,后者后续通过ttmodinstall中指定和修改,例如:
  [oracle@timesten-hol info]$ ttmodinstall
  The daemon for instance 'tt1122' is currently configured to use port 53392.
  Would you like to change this port? [ no ]
  The server for instance 'tt1122' is currently configured to use port 53393.
  Would you like to change this port? [ no ]
  TNS_ADMIN for the instance 'tt1122' is currently set to '/u01/app/oracle/product/11.2.0/dbhome_1/network/admin'.
  Would you like to change TNS_ADMIN for this instance? [ yes ] 
  实际上,是设置了一个$TNS_ADMIN的环境变量:
  [oracle@timesten-hol info]$ echo $TNS_ADMIN
  /u01/app/oracle/product/11.2.0/dbhome_1/network/admin
  [oracle@timesten-hol info]$ ls $TNS_ADMIN
  listener.ora  samples  shrept.lst  sqlnet.ora  tnsnames.ora
  [oracle@timesten-hol info]$ ls $TNS_ADMIN/tnsnames.ora
  /u01/app/oracle/product/11.2.0/dbhome_1/network/admin/tnsnames.ora
  $ cat $TNS_ADMIN/tnsnames.ora
  # tnsnames.ora Network Configuration File: /home/oracle/app/oracle/product/11.2.0/dbhome_1/network/admin/tnsnames.ora
  # Generated by Oracle configuration tools.
  TTORCL =
  (DESCRIPTION =
  (ADDRESS_LIST =
  (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
  )
  (CONNECT_DATA =
  (SID = orcl)
  )
  )
  然后可以使用sqlplus测试连接Oracle,如果成功,说明tnsnames.ora设置正确,Oracle数据库物理可达。
  注意sqlplus程序以及包含在TimesTen的安装程序中,无需安装Oracle的客户端。
  [oracle@timesten-hol info]$ sqlplus / as sysdba@ttorcl
  SQL*Plus: Release 11.2.0.2.0 Production on Wed Jul 13 06:27:44 2016
  Copyright (c) 1982, 2010, Oracle.  All rights reserved.
  Connected to:
  Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
  With the Partitioning, OLAP, Data Mining and Real Application Testing options
  SQL>
  然后可以测试通过timesten间接联通Oracle:
  $ ttisql -v1 "uid=tthr;pwd=timesten;dsn=cachedb1;oraclepwd=oracle"
  Command> passthrough 3
  Command> select * from product_component_version;
  < NLSRTL , 11.2.0.1.0, Production >
  < Oracle Database 11g Enterprise Edition , 11.2.0.1.0, 64bit Production >
  < PL/SQL , 11.2.0.1.0, Production >
  < TNS for Linux: , 11.2.0.1.0, Production >
  Command> passthrough 0
  Command> call ttversion;
  < 11, 2, 2, 6, 2 >
  以上, passthrough 3表示命令在Oracle中执行,passthrough 0表示在TimesTen本地执行。
  至此,我们已经可以确定TimesTen与Oracle数据库的连通性已经正确设置。