TimesTen 应用层数据库缓存学习:3. 环境准备 - DB 11gR2版本

本文通过一个例子讲述在建立Cache Group之前的准备工作。
准备工作包含4个部分。
1. 在Oracle数据库中创建用户
2. 为TimesTen数据库创建DSN
3. 在TimesTen 数据库中建立用户
4. 在TimesTen数据库中设置cache administration用户名和口令

本例演示环境包括一个Oracle数据库TTORCL,版本为11.2.0.2.0;一个TimesTen数据库cachedb1_1122作为其缓存,版本为11.2.2.2.0 (32 bit Linux/x86)。Oracle中需要缓存的数据为用户tthr拥有。
所有在Oracle中新建的用户口令为oracle, 在TimesTen中建立的用户口令为timesten。TimesTen和Oracle中的缓存管理用户名皆为: cacheadm
* 使用以下的语句连接到Oracle数据库
DBA:$ sqlplus sys/oracle@ttorcl as sysdba
应用用户:$ sqlplus tthr/oracle@ttorcl
* 使用以下的语句连接到TimesTen数据库
DBA: $ ttisql cachedb1_1122
Cache Admin:$ ttisql 'dsn=cachedb1_1122;uid=cacheadm;pwd=timesten;oraclepwd=oracle'
应用用户:$ ttisql 'dsn=cachedb1_1122;uid=tthr;pwd=timesten

在Oracle数据库中创建用户

这一部分我们需要在Oracle数据库中提供三个用户,一个名为TIMESTEN的用户,一个schema 用户,一个cache admin user。
除TIMESTEN用户名不可改变外,一般schema用户都已经存在,在我们后续的例子中,我们设定schema用户为tthr,cache admin用户为cacheadm
每一个TimesTen数据库只能对应一个cache admin user,但一个cache admin user可以管理多个TimesTen数据库

TIMESTEN用户

$ cd $TT_HOME/oraclescripts/
# 此目录下包含许多在Oracle中执行,设置TimesTen Cache Group的脚本
$ ls
cacheCleanUp.sql  cacheInfo.sql  grantCacheAdminPrivileges.sql  initCacheAdminSchema.sql  initCacheGlobalSchema.sql  initCacheGridSchema.sql  README.TXT

# 下面的语句中,ttorcl为Oracle数据库的实例名,在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 =
      (SERVICE_NAME = orcl)
    )
  )

$ sqlplus sys/oracle@ttorcl as sysdba

SQL*Plus: Release 11.2.0.2.0 Production on Sat Apr 9 01:14:36 2016

Copyright (c) 1982, 2010, Oracle.  All rights reserved.


Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> CREATE TABLESPACE cachetblsp DATAFILE 'cachetblsp.dbf' SIZE 100M;

Tablespace created.
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.

应用Schema用户

应用Schema用户通常已经存在,后续建立的cache group就是要cache这个schema user的表,作为示例,这里还是演示其过程,本例中,Schema用户为tthr,
我们使用TimesTen安装中自带的HR Schema

$ cd $TT_HOME/quickstart/sample_scripts/hrschema/
$ ls
hr_cre_tt.sql  hr_idx_tt.sql  hr_popul_tt.sql  README.TXT
$ sqlplus sys/oracle@ttorcl as sysdba

SQL*Plus: Release 11.2.0.2.0 Production on Sat Apr 9 01:27:29 2016

Copyright (c) 1982, 2010, Oracle.  All rights reserved.


Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> drop user tthr cascade;

User dropped.

SQL> create user tthr identified by oracle;

User created.

SQL> GRANT CREATE SESSION, RESOURCE, CREATE VIEW TO tthr;      

Grant succeeded.
SQL> connect sys as sysdba
Enter password: 
Connected.

SQL> select * from dba_sys_privs where grantee='RESOURCE';

GRANTEE                        PRIVILEGE                                ADM
------------------------------ ---------------------------------------- ---
RESOURCE                       CREATE TRIGGER                           NO
RESOURCE                       CREATE SEQUENCE                          NO
RESOURCE                       CREATE TYPE                              NO
RESOURCE                       CREATE PROCEDURE                         NO
RESOURCE                       CREATE CLUSTER                           NO
RESOURCE                       CREATE OPERATOR                          NO
RESOURCE                       CREATE INDEXTYPE                         NO
RESOURCE                       CREATE TABLE                             NO

8 rows selected.
SQL> connect tthr/oracle
Connected.

SQL> @hr_cre_tt.sql <-建表
SQL> @hr_idx_tt.sql <-建索引
SQL> @hr_popul_tt.sql <-加载数据

Cache 管理用户

$ cd $TT_HOME/oraclescripts/
$ sqlplus sys/oracle@ttorcl as sysdba

SQL*Plus: Release 11.2.0.2.0 Production on Sat Apr 9 01:47:17 2016

Copyright (c) 1982, 2010, Oracle.  All rights reserved.


Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> CREATE USER cacheadm IDENTIFIED BY oracle
DEFAULT TABLESPACE cachetblsp QUOTA UNLIMITED ON cachetblsp; 

User created.
SQL> @grantCacheAdminPrivileges "cacheadm"   

Please enter the administrator user id
The value chosen for administrator user id is cacheadm

***************** Initialization for cache admin begins ******************
0. Granting the CREATE SESSION privilege to CACHEADMIN
1. Granting the TT_CACHE_ADMIN_ROLE to CACHEADMIN
2. Granting the DBMS_LOCK package privilege to CACHEADMIN
3. Granting the RESOURCE  privilege to CACHEADMIN
4. Granting the CREATE PROCEDURE  privilege to CACHEADMIN
5. Granting the CREATE ANY TRIGGER  privilege to CACHEADMIN
6. Granting the DBMS_LOB package privilege to CACHEADMIN
7. Granting the SELECT on SYS.ALL_OBJECTS privilege to CACHEADMIN
8. Granting the SELECT on SYS.ALL_SYNONYMS privilege to CACHEADMIN
9. Checking if the cache administrator user has permissions on the default
tablespace
     Permission exists
11. Granting the CREATE ANY TYPE privilege to CACHEADMIN
********* Initialization for cache admin user done successfully *********

为TimesTen数据库创建DSN

此处建立的DSN是作为Oracle数据库的缓存,最关键的是其字符集属性必须与Oracle一致
从Oracle中,查询到字符集为AL32UTF8

$ sqlplus -S sys/oracle@ttorcl as sysdba
SELECT value FROM nls_database_parameters WHERE parameter='NLS_CHARACTERSET';

VALUE
--------------------------------------------------------------------------------
AL32UTF8

使用TimesTen安装自带的样例DSN: cachedb1_1122,修改字符集和Oracle服务属性

[cachedb1_1122]
Driver=/home/oracle/app/oracle/product/TimesTen/tt1122/lib/libtten.so
DataStore=/home/oracle/app/oracle/product/TimesTen/tt1122/info/DemoDataStore/cachedb1_1122
PermSize=40
TempSize=32
PLSQL=1
DatabaseCharacterSet=AL32UTF8
OracleNetServiceName=TTORCL

然后在TimesTen中确定字符集属性与Oracle一致


Command> call ttconfiguration('DataBaseCharacterSet');
< DataBaseCharacterSet, AL32UTF8 >

在TimesTen 数据库中建立用户

在TimesTen中需要建立两个用户
1. Cache Manager
Cache管理用户,执行各种Cache Group和Cache grid操作,通常与Oracle中的Cache Admin用户名一致,本例为cacheadmin
2. Schema用户
对应Oracle中的Schema用户,用户名必须一致,本例为tthr

Then, you must create a user with the same name as an Oracle Database schema user for each schema user who owns or will own Oracle Database tables to be cached in the TimesTen database. We refer to these users as cache table users, because the TimesTen cache tables are to be owned by these users. Therefore, the owner and name of a TimesTen cache table is the same as the owner and name of the corresponding cached Oracle Database table. The password of a cache table user can be different than the password of the Oracle Database schema user with the same name.

$ ttisql -v1 cachedb1_1122
Command> CREATE USER cacheadm IDENTIFIED BY timesten;

User created.

Command> GRANT CREATE SESSION, CACHE_MANAGER, CREATE ANY TABLE, DROP ANY TABLE TO cacheadm;


User created.

Command> CREATE USER tthr IDENTIFIED BY timesten;

User created.
Command> GRANT CREATE SESSION, CREATE ANY TABLE to tthr;

这里需要指出的是对于Cache管理用户的授权,之所以赋予DROP ANY TABLE是为了cacheuser可以DROP CACHE GROUP,因为DROP CACHE GROUP需要删除相关的cache table
之后,还需要根据Cache Group的类型对Cache管理员授权,对于Read Only Cache Group,需要有对标的SELECT权限;对于AWT Group,除SELECT外,还需要有UPDATE, DELETE, INSERT权限

在TimesTen数据库中设置cache administration用户名和口令

其实就是在TT中缓存了访问Oracle的用户名和口令,下面这段话说明为何需要设置此用户名和口令

You must set the cache administration user name and password in the TimesTen database before any cache grid or cache group operation can be issued with the ttCacheUidPwdSet built-in procedure. The cache agent connects to the Oracle database as this user to create and maintain Oracle Database objects that store information used to manage a cache grid and enforce predefined behaviors of particular cache group types. In addition, both the cache and replication agents connect to the Oracle database with the credentials set with the ttCacheUidPwdSet built-in procedure to manage Oracle database operations.

并非所有的操作都会使用ttCacheUidPwdSet 设置的用户名和口令,一些操作如passthrough会使用连接属性中的OraclePwd属性

When you connect to the TimesTen database to work with AWT or read-only cache groups, TimesTen uses the credentials set with the ttCacheUidPwdSet built-in procedure when connecting to the Oracle database on behalf of these cache groups.

When you connect to the TimesTen database to work with SWT or user managed cache groups or passthrough operations, TimesTen connects to the Oracle database using the current user’s credentials as the user name and the OraclePwd connection attribute as the Oracle password. Thus, the correct user name and Oracle database password that should be used for connecting to the Oracle database must be set correctly in the connection string or with the connection attributes.

$ ttAdmin -cacheUidPwdSet -cacheUid cacheadm -cachePwd oracle cachedb1_1122
$ ttAdmin -cacheUidGet cachedb1_1122
Cache User Id                   : CACHEADM

或者
$ ttIsql "DSN=cachedb1_1122;UID=cacheadm;PWD=timesten"
Command> call ttCacheUidPwdSet('cacheadm','oracle');
Command> call ttCacheUidGet();
< CACHEADM >

参考

  • Oracle® TimesTen Application-Tier Database Cache User’s Guide 11g Release 2 (11.2.2)| 2 Getting Started
  • Oracle® TimesTen Application-Tier Database Cache User’s Guide 11g Release 2 (11.2.2)| 3 Setting Up a Caching Infrastructure
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值