zoukankan      html  css  js  c++  java
  • Timesten cache group 配置

     操作系统windows 7,timesten 11g,oracle 11g

    timesten cache group的详细信息可以在timesten官方的技术文档Cahce User's Guide的pdf文件中找到,下文是对原文的翻译加自己的一些总结。

     oracle上的操作

    1. 创建表空间cachetblsp,将被timesten user和cache administration user使用,该表空间应该只用于存储cache相关的对象,而不要与其他应用共享。

    sqlplus sys as sysdba
    Enter password: password
    SQL> CREATE TABLESPACE cachetblsp DATAFILE 'datfttuser.dbf' SIZE 100M;

    2. 创建timesten user,需要执行initCacheGlobalSchema.sql脚本,并将刚刚创建的表空间名传递进来。该脚本位于%TimesTen_install_dir%/oraclescripts

    可以在进入sqlplus前就先切换到脚本所在的目录cd TimesTen_install_dir/oraclescripts,或者使用该脚本的绝对路径来运行。

    SQL> @initCacheGlobalSchema "cachetblsp"

    initCacheGlobalSchema.sql包含如下信息:

    ■ 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

    3.创建cache administration user,这里用户名使用cacheuser,密码使用oracle。运行%TimesTen_install_dir%/oraclescripts目录下的脚本grantCacheAdminPrivileges.sql,并将cacheuser作为参数传入。 

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

    4.创建一个用户,这里用户名是oratt,并授予最小权限集,该用户的表将被cache到timesten中:

    SQL> CREATE USER oratt IDENTIFIED BY oracle;
    SQL> GRANT CREATE SESSION, RESOURCE TO oratt;

     使用oratt用户重新登录oracle,然后建表。readtab表将设为read only cache,writetab将设为异步writethrough cache group

    SQL> CREATE TABLE readtab (keyval NUMBER NOT NULL PRIMARY KEY, str VARCHAR2(32));
    SQL> CREATE TABLE writetab (pk NUMBER NOT NULL PRIMARY KEY, attr VARCHAR2(40));

     插入一些数据

    SQL> INSERT INTO readtab VALUES (1, 'Hello');
    SQL> INSERT INTO readtab VALUES (2, 'World');
    SQL> INSERT INTO writetab VALUES (100, 'TimesTen');
    SQL> INSERT INTO writetab VALUES (101, 'IMDB');
    SQL> COMMIT;

    授予相应的权限

    SQL> GRANT SELECT ON readtab TO cacheuser;
    SQL> GRANT SELECT ON writetab TO cacheuser;
    SQL> GRANT INSERT ON writetab TO cacheuser;
    SQL> GRANT UPDATE ON writetab TO cacheuser;
    SQL> GRANT DELETE ON writetab TO cacheuser;

    timesten上的操作 

    1.创建timesten dsn

    timesten的字符集必须和oracle的字符集相同,在创建之前可以在sqlplus中输入如下命令查看oracle使用的字符集

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

    我这里oracle中使用的是ZHS16GBK,因此在创建的timesten中选择相应的字符集。

    可以使用系统DSN或者用户DSN,我这里DSN名称是cachealone1,在odbc的设置中官方文档给出需要设置的属性有4项:

    ■ Data Store Path + Name: c:\temp\alone1

    注意:数据文件实际上存放在c:\temp\

    一定要先建立文件夹c:\temp\,否则后面执行ttisql cachealone1,创建的时候会报出错误

    836: Cannot create data store shared-memory segment, error 3


    ■ Permanent Data Size: 64(单位是M)
    ■ Oracle Net Service Name: orcl(一般情况下是orcl如不清楚可以参考这里)。也可以在sqlplus中用sys登录oracle,输入如下命令查看:

    sqlplus sys as sysdba;
    Enter password: password
    SQL>select value from v$parameter where name='service_names'

    ■ Database Character Set: ZHS16GBK

    另外,使用可写的cache时,要在IMDB cache选项栏下的oracle password中输入oracle cacheuser的密码。其他属性使用默认设置

    2.创建timesten中的用户

    在命令行下输入ttIsql cachealone1,创建刚刚配置好的timesten实例,并以操作系统用户连接该实例。

    ttIsql cachealone1

    (1)需要创建一个cache manager user,用来执行cache grid和cache group的操作。原文中有两句话值得注意:

    TimesTen cache manager user must have the same name as an Oracle user that can access the cached Oracle tables.

    The password of the cache manager user can be different than the password of the Oracle user with the same name.

    如下命令创建一个cache manager user:cacheuser

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

    (2)一个或多个拥有cache table的cache table users,cache表的拥有者和表名要和oracle中相应的需要被cache的表名和表拥有者名字相同。 但密码可以不同

    对每一个oracle中需要被cache的表,需要分别在timesten中为需要被cache的表的拥有者创建同名用户,及创建同名的要被cache的表。

    You must create a TimesTen cache table user with the same name as an Oracle schema user for each schema user who owns or will own Oracle tables to be cached in the TimesTen database. The password of a cache table user can be different than the password of the Oracle schema user with the same name.

    The owner and name of a TimesTen cache table is the same as the owner and name of the corresponding cached Oracle table.

    如下命令创建一个cache table user oratt

    Command> CREATE USER oratt IDENTIFIED BY timesten;

    (3)在timesten中设置cache administration user的用户名和密码

    如果有连接到dsn,用exit退出。在cmd命令行中输入如下命令,用刚刚建立的cache manager user,cacheuser登录。

    ttIsql "DSN=cachealone1;UID=cacheuser;PWD=timesten;OraclePWD=oracle"

    然后输入如下命令,设置cache administration user的用户名和密码,而且只需要设置一次。

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

    执行到这一步时出现ORA-12154的错误

    刚开始以为是oracle net service name设置有误,但查询后发现没错。后来看到这篇文章http://space.itpub.net/7734298/viewspace-711467

    里面的错误信息中TNS_ADMIN和ORACLE_HOME有信息,而我则全部是空。觉得应该是环境变量的问题,然后增加这两个环境变量,就成功了。添加环境变量:

    TNS_ADMIN = "E:\oracle\product\11.2.0\dbhome_1\network\admin",

    ORACLE_HOME= "E:\oracle\product\11.2.0\dbhome_1"

    3.创建cache grid

    在创建cache group之前需要先建立cache grid,只有cache grid的第一个数据库成员需要执行这个操作。当以cache manager user 登录后,输入如下命令创建一个cache grid "myGrid"

    Command> call ttGridCreate('myGrid');

    将timesten和刚建好的cache grid 关联起来

    Command> call ttGridNameSet('myGrid');

    启动cache代理,如果建立了read only cache,需要启动该代理才能使用。该代理负责timesten database之间的沟通以及oracle和timesten cache database之间的数据流。

    Command> call ttCacheStart;

    在安装timesten时如果未设置tns_admin路径,则会出现如下错误

    5209: Cannot start cache agent because no tns_admin specified during installati
    on - use ttModInstall -tns_admin to fix.. Cannot start cache agent because no tn
    s_admin specified during installation - use ttModInstall -tns_admin to fix.
    The command failed.

    需要先设置tns_admin路径才可以启动cache代理,退出dsn的连接,然后在命令行下输入:

    ttModInstall -tns_admin E:\oracle\product\11.2.0\dbhome_1\network\admin

    然后重新连入dsn,再次执行call ttCacheStart;

    4.创建cache groups

    创建一个只读cache group readcache用于高速缓存oracle中的表oratt.readtab
    以及一个异步writethrough(AWT) cache group用于高速缓存oracle中的表oratt.writetab

    需要先以cache manager user登录后,才能执行如下命令

    Command> CREATE READONLY CACHE GROUP readcache
        > AUTOREFRESH INTERVAL 5 SECONDS
        > FROM oratt.readtab
        > (keyval NUMBER NOT NULL PRIMARY KEY, str VARCHAR2(32));
    Command> CREATE ASYNCHRONOUS WRITETHROUGH CACHE GROUP writecache
        > FROM oratt.writetab
        > (pk NUMBER NOT NULL PRIMARY KEY, attr VARCHAR2(40));

    原文中创建dynamic AWT global cache group,但是windows下并不支持global cache group

    启动复制agent,如果数据库中有asynchronous writethrough cache groups就必须要启动这个agent,这个进程负责TT数据库之间,TT和oracle之间的数据复制。

    Command> call ttrepstart;

    输入cachegroups命令可以查看建立的cache group的信息

    Command> cachegroups;

    5.使用read-only cache group

    当以cache manager user 登录后,需要先手动从oracle中载入readcache中相应cache表的内容

    Command> LOAD CACHE GROUP readcache COMMIT EVERY 256 ROWS;
    2 cache instances affected.
    Command> exit

    在使用查询前需要先授予cacheuser select的权限。先退出timesten的连接,输入如下命令以实例管理员重新连接

    ttIsql cachealone1

    然后授予权限

    Command> GRANT SELECT ON oratt.readtab TO cacheuser;

    用exit退出连接后,用cacheuser重新连接

    ttIsql "DSN=cachealone1;UID=cacheuser;PWD=timesten;OraclePWD=oracle"

    查询oratt.readtab中的数据

    Command> SELECT * FROM oratt.readtab;
    < 1, Hello >
    < 2, World >
    2 rows found.

    在sqlplus中对oracle中的表readtab做一些更新操作

    SQL> INSERT INTO readtab VALUES (3, 'Welcome');
    SQL> DELETE FROM readtab WHERE keyval=2;
    SQL> UPDATE readtab SET str='Hi' WHERE keyval=1;
    SQL> COMMIT;

    5秒后会自动刷新,重新在timesten中查询,可以看到结果同步过来了。

    Command> SELECT * FROM oratt.readtab;
    < 1, Hi >
    < 3, Welcome >
    2 rows found.
    Command> exit

    6.使用异步writethrough cache group

    异步writethrough的特点就是当在timesten中更新表时,不是将更新结果实时同步到oracle中的,而是异步的方式。详细信息可以参考Cahce User's Guide的pdf文档。

    同样,在使用前需要先授予cacheuser相应的权限。先退出timesten的连接,输入如下命令以实例管理员重新连接

    ttIsql cachealone1

    然后授予权限

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

    用exit退出连接后,用cacheuser重新连接

    ttIsql "DSN=cachealone1;UID=cacheuser;PWD=timesten;OraclePWD=oracle"

    查询oratt.writetab中的数据

    Command> SELECT * FROM oratt.writetab WHERE pk=100;
    < 100, TimesTen >
    1 row found.
    Command> exit

    更新数据

    Command> INSERT INTO oratt.writetab VALUES (102, 'Cache');
    Command> DELETE FROM oratt.writetab WHERE pk=101;
    Command> UPDATE oratt.writetab SET attr='Oracle' WHERE pk=100;
    Command> COMMIT;
    Command> exit

    在oracle中查询数据,可以看到数据已经更新了。

    SQL> SELECT * FROM writetab;

    其他注意事项:

    如果重启电脑,需要重新在timesten中开启cache代理,运行call ttCacheStart;如果有启用异步writethrough,还需要重新启动复制代理,运行call ttrepstart;

    然后还需要重新载入cache数据,LOAD CACHE GROUP readcache COMMIT EVERY 256 ROWS;

    需要注意的是,执行load及refresh之前需要先修改AUTOREFRESH STATE为PAUSED,可以通过如下命令修改,但如果属于重启电脑就不需要了:

    ALTER CACHE GROUP event_cache SET AUTOREFRESH STATE PAUSED;

    参考文献

    http://blog.csdn.net/zjx198934/article/details/6146979

    http://www.dbasky.com/oracle/timesten_study_5_configure_imdb_cache.html

  • 相关阅读:
    U盘出现大量乱码文件,并且不能彻底删除
    使用命令生成配置文件
    input只读属性readonly和disabled的区别
    将sublime添加到鼠标右键
    mysql-front导入数据失败:“在多字节的目标代码页中,没有此 Unicode 字符可以映射到的字符”
    typeof运算符
    react input 设置默认值
    时间格式转换
    去除字符串首尾空格
    ES6基础知识汇总
  • 原文地址:https://www.cnblogs.com/restran/p/2835357.html
Copyright © 2011-2022 走看看