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

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

本例演示环境包括一个Oracle数据库TTORCL(对应于12c的可插拔数据库pdborcl),版本为12.1.0.2.0;一个TimesTen数据库cachedb1_1122作为其缓存,版本为11.2.2.8.11 (64 bit Linux/x86_64)。Oracle中需要缓存的数据为用户tthr拥有。
所有在Oracle中新建的用户口令均为oracle, 在TimesTen中建立的用户口令均为timesten。TimesTen和Oracle中的缓存管理用户名皆为: cacheadm
Oracle和TimesTen共用一个tnsnames.ora,内容如下:

# tnsnames.ora Network Configuration File: /u01/app/oracle/product/12.1.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 =
        (SERVER = DEDICATED)
      (SERVICE_NAME = pdborcl)
    )
  )


PDBORCL =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
    )
    (CONNECT_DATA =
        (SERVER = DEDICATED)
      (SERVICE_NAME = pdborcl)
    )
  )
  • 使用以下的语句连接到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中设置

$ sqlplus sys/oracle@ttorcl as sysdba

SQL*Plus: Release 12.1.0.2.0 Production on Sat Apr 23 13:57:21 2016

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


Connected to:
Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics 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 12.1.0.2.0 Production on Sat Apr 23 13:59:39 2016

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


Connected to:
Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options

SQL> create user tthr identified by oracle;

User created.

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

Grant succeeded.

SQL> alter user tthr quota unlimited on users;
User altered.

SQL> connect sys as sysdba
Enter password: 
Connected.
SQL> select * from dba_sys_privs where grantee='RESOURCE';

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

8 rows selected.

SQL> connect tthr/oracle@ttorcl
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 12.1.0.2.0 Production on Sat Apr 23 14:32:06 2016

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


Connected to:
Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options

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

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 CACHEADM
1. Granting the TT_CACHE_ADMIN_ROLE to CACHEADM
2. Granting the DBMS_LOCK package privilege to CACHEADM
3. Granting the CREATE SEQUENCE privilege to CACHEADM
4. Granting the CREATE CLUSTER privilege to CACHEADM
5. Granting the CREATE OPERATOR privilege to CACHEADM
6. Granting the CREATE INDEXTYPE privilege to CACHEADM
7. Granting the CREATE TABLE privilege to CACHEADM
8. Granting the CREATE PROCEDURE  privilege to CACHEADM
9. Granting the CREATE ANY TRIGGER  privilege to CACHEADM
10. Granting the GRANT UNLIMITED TABLESPACE privilege to CACHEADM
11. Granting the DBMS_LOB package privilege to CACHEADM
12. Granting the SELECT on SYS.ALL_OBJECTS privilege to CACHEADM
13. Granting the SELECT on SYS.ALL_SYNONYMS privilege to CACHEADM
14. Checking if the cache administrator user has permissions on the default
tablespace
     Permission exists
16. Granting the CREATE TYPE privilege to CACHEADM
17. Granting the SELECT on SYS.GV$LOCK privilege to CACHEADM (optional)
18. Granting the SELECT on SYS.GV$SESSION privilege  to CACHEADM (optional)
19. Granting the SELECT on SYS.DBA_DATA_FILES privilege  to CACHEADM (optional)
20. Granting the SELECT on SYS.USER_USERS privilege  to CACHEADM (optional)
21. Granting the SELECT on SYS.USER_FREE_SPACE privilege  to CACHEADM (optional)
22. Granting the SELECT on SYS.USER_TS_QUOTAS privilege  to CACHEADM (optional)
23. Granting the SELECT on SYS.USER_SYS_PRIVS privilege  to CACHEADM (optional)
********* 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/TimesTen/tt1122/lib/libtten.so
DataStore=/home/oracle/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
CREATE USER cacheadm IDENTIFIED BY timesten;
GRANT CREATE SESSION, CACHE_MANAGER, CREATE ANY TABLE, DROP ANY TABLE TO cacheadm;
CREATE USER tthr IDENTIFIED BY timesten;
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 >

最后,创建一个cache grid,这时一个固定套路,接下来皆可以创建缓存组了

$ ttisql -v1 -connstr "dsn=cachedb1_1122;uid=cacheadm;pwd=timesten;oraclepwd=oracle"
Command> call ttGridCreate ('samplegrid');
Command> call ttGridInfo;
< SAMPLEGRID, CACHEADM, Linux Intel x86, 32-bit, 11, 2, 2 >
Command> call ttGridNameSet ('samplegrid');
Command> call ttGridNameGet;
< SAMPLEGRID >

参考

  • 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

你可能感兴趣的:(timesten,DB12c,缓存组,cachegroup)