从TimesTen 7版本过渡到TimesTen 11g,在Cache Group这一块,操作上要复杂些,下面介绍如何在TimesTen 11g中创建Cache Group。主要参考标准文档Oracle In-Memory Database Cache User’s Guide 中的第二章 Getting Started。我的环境是RedHat 4 32bit ,TimesTen 11.2。
1. 安装Oracle软件
为了和TimesTen 11g 中底层的OCI接口以及CRS(Oracle Clusterware)的兼容,建议安装11.1.0.7或者以上版本。当然其它版本的Oracle估计也可以,但没有经过完全官方测试,在有些功能上可能会有问题,我就在11.1.0.6的版本上碰到无法卸载TimesTen 11g注册资源的问题,但如果只是普通的功能应该没什么问题。实验中我创建了操作系统用户oracle,且其.bash_profile设置如下:
export EDITOR=vi
export ORACLE_SID=devdb1
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/11.1.0/db_11g
export NLS_LANG=american_america.zhs16gbk
export
PATH=$ORACLE_HOME/bin: /bin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/X11R6/bin:$PATH:$HOME/bin
建议先装Oracle,再装TimesTen,这样安装TimesTen的时候可以直接设置TNS_ADMIN的路径,即tnsnames.ora文件所在的路径,位于$ORACLE_HOME/network/admin目录下。如果先装的是TimesTen,后装的Oracle,则要通过ttmodinstall来重新配置TNS_ADMIN路径。我的$ORACLE_HOME/network/admin/tnsnames.ora配置如下:
DEVDB1 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = rac1)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = devdb1)
)
)
2. 创建timesten用户及/etc/TimesTen目录
为了便于管理,不建议用oracle用户或者root用户安装TimesTen,实验中我单独创建了操作系统用户timesten,并使之属于dba以及oinstall组,Primary Group为dba。
用root用户创建/etc/TimesTen目录,TimesTen的大小写要一致,并更改所属用户为刚创建的timesten:
root#mkdir /etc/TimesTen
root#chown timesten:dba /etc/TimesTen
3. 安装TimesTen软件
可以去http://www.oracle.com/technology/software/products/timesten/index.html 下载最新的TimesTen版本11.2.1.4.0 (timesten112140.linux86.tar.gz),然后解压安装。
在安装的时候要注意的地方:
- TNS_ADMIN的设置
Please enter a value for TNS_ADMIN (s=skip)? [ ]
/u01/app/oracle/product/11.1.0/db_11g/network/admin
- Enable PL/SQL
Would you like to enable PL/SQL for this instance? [ yes ]yes
- 选择文档以及Demo的安装
Do you want to install QuickStart and the TimesTen Documentation? [ no ] yes
4. 设置环境变量
修改timesten用户的.bash_profile,增加如下设置:
export ORACLE_SID=devdb1
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/11.1.0/db_11g
export TT_HOME=/home/timesten/TimesTen/tt1121
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:$TT_HOME/lib
export PATH=$ORACLE_HOME/bin:$TT_HOME/bin:$PATH:$HOME/bin
要注意的是LD_LIBRARY_PATH,因为cache connect要调用oracle下的一些动态链接库,所以一定要设置准确,64位平台上可能名字叫lib64。退出并重新登录,使环境变量起作用。
5. 初始化配置
现在我们跟着文档Oracle In-Memory Database Cache User’s Guide 的第二章Getting Started一步步做,这个初始化工作都一样的,做一次就可以了。建议大家先把这一章读一遍,知道里面到底是要做些什么,Oracle里面涉及到如下几个用户:
- TIMESTEN
这个用户名字无法修改指定,是直接通过timesten的安装脚本产生的,这个用户是使用Cache Grid的时候要用的,专门管理Cache Grid的元数据信息。当然你如果直接修改其脚本可以达到修改用户名的目的,但以后使用Cache Grid时肯定会碰到问题。可以认为是TimesTen在Oracle这边的定制用户。
- cacheuser
这个用户是用于管理Cache Connect,比如drop cache group,create cache group,启动关闭cache agent等日常维护操作。
- oratt
真正的最终数据所在的schema用户,所以在生产系统中,这个用户是我们经常要用到的,比如对表进行insert、update、delete等时,就要用这个用户了。
[timesten@rac1 oraclescripts]$ cd $TT_HOME/oraclescripts
[timesten@rac1 oraclescripts]$ pwd
/home/timesten/TimesTen/tt1121/oraclescripts
[timesten@rac1 oraclescripts]$ sqlplus / as sysdba
//为管理cache group创建单独的Oracle表空间
SQL> create tablespace cachetblsp datafile ‘datfttuser.dbf’ size 100m;
//在Oracle中创建TimesTen用户以及配置对应的表空间
SQL> @initCacheGlobalSchema "cachetblsp"
Please enter the tablespace where TIMESTEN user is to be created
The value chosen for tablespace is cachetblsp
******* 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 procedure successfully completed.
//创建表所属的用户
SQL> create user oratt identified by oracle default tablespace users;
//赋予权限
SQL> grant create session,resource to oratt;
Grant succeeded.
//创建Cache Group的管理员用户
SQL> create user cacheuser identified by oracle default tablespace cachetblsp quota unlimited on cachetblsp;
User created.
//赋予相应的权限
SQL> @grantCacheAdminPrivileges "cacheuser"
Please enter the administrator user id
The value chosen for administrator user id is cacheuser
***************** Initialization for cache admin begins ******************
0. Granting the CREATE SESSION privilege to CACHEUSER
1. Granting the TT_CACHE_ADMIN_ROLE to CACHEUSER
2. Granting the DBMS_LOCK package privilege to CACHEUSER
3. Granting the RESOURCE privilege to CACHEUSER
4. Granting the CREATE ANY PROCEDURE privilege to CACHEUSER
5. Granting the CREATE ANY TRIGGER privilege to CACHEUSER
6. Checking if the cache administrator user has permissions on the default
tablespace
Permission exists
7. Granting the CREATE ANY TYPE privilege to CACHEUSER
********* Initialization for cache admin user done successfully *********
6. 在Oracle中创建表以及初始化数据
su – timesten
//记得要先启动oracle listener
sqlplus oratt/oracle@devdb1
//创建表以及数据并赋予cacheuser用户相关表的访问权限,scott.sql可以在这儿下载
SQL>@ scott.sql
//为了后面维护上的方便,讲相应的权限预先都赋予给cacheuser用户。在真实的环境中,不必要把所有的权限都给cacheuser用户,它需要什么要的操作的时候就赋予它什么样的权限即可
SQL>grant all on bonus to cacheuser;
SQL>grant all on salgrade to cacheuser;
SQL>grant all on dept to cacheuser;
SQL>grant all on emp to cacheuser;
7. 在TimesTen配置DSN以及相关设置
//配置sys.odbc.ini
[tt_workshop]
Driver=/home/timesten/TimesTen/tt1121/lib/libtten.so
DataStore=/home/timesten/datastore/tt_workshop
DatabaseCharacterSet=ZHS16GBK
PermSize=100
TempSize=32
CkptFrequency=120
CkptLogVolume=0
PLSQL=1
OracleNetServiceName=devdb1
//创建缺少的目录
mkdir -p /home/timesten/datastore
//不带用户登录,即为缺省的安装用户,相当于sys用户
[timesten@rac1 oraclescripts]$ ttisql tt_workshop
Command> create user cacheuser identified by timesten;
Command> grant create session,cache_manager,create any table to cacheuser;
Command> create user oratt identified by timesten;
Command> grant create session,create any table to oratt;
Command> exit
//用cacheuser用户登录
[timesten@rac1]$ttisql "dsn=tt_workshop;uid=cacheuser;pwd=timesten;oraclepwd=oracle"
//设置Cache Group管理用户信息并创建Cache Grid
Command> call ttcacheuidpwdset(’cacheuser’,'oracle’);
//TimesTen 11g 所有的cache group必须隶属于一个Cache Grid
Command> call ttgridcreate(’mygrid’);
Command> call ttgridnameset(’mygrid’);
Command> exit
至此,所有准备工作全部完成。
8. 创建只读Cache Group
//cache group的创建都是通过cacheuser用户来进行的
ttisql "dsn=tt_workshop;uid=cacheuser;pwd=timesten;oraclepwd=oracle"
Command> call ttcachestart;
Command> create readonly cache group ro
Autorefresh interval 5 seconds mode incremental
from
oratt.salgrade(
grade number primary key,
losal number,
hisal number );
Command> cachegroups;
Command> load cache group ro commit every 10 rows;
Command> exit;
//通过真正的数据拥有者oratt登录进去检查,如果还是通过cacheuser用户查询oratt.salgrade表的话,会报权限不够的错误,可以赋与cacheuser相关权限也可以查询grant select on oratt.salgrade to cacheuser;
ttisql "dsn=tt_workshop;uid=oratt;pwd=timesten;oraclepwd=oracle"
Command>select * from oratt.salgrade;
< 1, 700, 1200 >
< 2, 1201, 1400 >
< 3, 1401, 2000 >
< 4, 2001, 3000 >
< 5, 3001, 9999 >
//在Oracle中针对Oratt.salgrade表插入一条记录并提交
SQL>insert into oratt.salgrade values(6,10000,15000);
SQL>commit;
//在TimesTen中验证刚插入的记录已经同步到TimesTen中
Command> select * from oratt.salgrade;
< 1, 700, 1200 >
< 2, 1201, 1400 >
< 3, 1401, 2000 >
< 4, 2001, 3000 >
< 5, 3001, 9999 >
< 6, 10000, 15000 >
6 rows found.
要注意的是整个timesten只有两种用户cacheuser,oratt。而oracle有三个用户timesten(必须),cacheuser(管理员),oratt(schemauser)
9. 创建本地的AWT Cache Group
ttisql "dsn=tt_workshop;uid=cacheuser;pwd=timesten;oraclepwd=oracle"
Command> create asynchronous writethrough cache group awt from
oratt. bonus(
empno number(4) primary key,
ename varchar2(10),
sal number,
comm number
) ;
//AWT是通过replication agent和oracle同步的,所以必须启动replication agent,否则数据同步不过去
Command> call ttrepstart;
Command> exit;
//通过oratt进行数据操作
ttisql "dsn=tt_workshop;uid=oratt;pwd=timesten;oraclepwd=oracle"
Command> desc oratt.bonus;
Command> insert into oratt.bonus values(7566,’jones’,5000,4500);
1 row inserted.
Command> commit;
Command>
//在Oracle检查数据是否已近过来
SQL> select * from oratt.bonus;
EMPNO ENAME SAL COMM
———- ———- ———- ————————————
7566 jones 5000 4500
至此实验完成,要注意的是用户之间的切换,如果实在不想切换,也可以一次性把相关的权限都赋予给某个用户,比如cacheuser。
文章 (RSS)
January 14th, 2010于10:40 am
[...] TimesTen 11g 中创建Cache Group 14 01 [...]