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

本文主要是介绍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 sysdbaSQL*Plus: Release 12.1.0.2.0 Production on Sat Apr 23 13:57:21 2016Copyright (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 optionsSQL> 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 sysdbaSQL*Plus: Release 12.1.0.2.0 Production on Sat Apr 23 13:59:39 2016Copyright (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 optionsSQL> 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  YES8 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 sysdbaSQL*Plus: Release 12.1.0.2.0 Production on Sat Apr 23 14:32:06 2016Copyright (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 optionsSQL> 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
tablespacePermission 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 应用层数据库缓存学习:3. 环境准备 - DB 12cR1版本的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/677717

相关文章

SQL Server 查询数据库及数据文件大小的方法

《SQLServer查询数据库及数据文件大小的方法》文章介绍了查询数据库大小的SQL方法及存储过程实现,涵盖当前数据库、所有数据库的总大小及文件明细,本文结合实例代码给大家介绍的非常详细,感兴趣的... 目录1. 直接使用SQL1.1 查询当前数据库大小1.2 查询所有数据库的大小1.3 查询每个数据库的详

MySQL中REPLACE函数与语句举例详解

《MySQL中REPLACE函数与语句举例详解》在MySQL中REPLACE函数是一个用于处理字符串的强大工具,它的主要功能是替换字符串中的某些子字符串,:本文主要介绍MySQL中REPLACE函... 目录一、REPLACE()函数语法:参数说明:功能说明:示例:二、REPLACE INTO语句语法:参数

Java实现本地缓存的四种方法实现与对比

《Java实现本地缓存的四种方法实现与对比》本地缓存的优点就是速度非常快,没有网络消耗,本地缓存比如caffine,guavacache这些都是比较常用的,下面我们来看看这四种缓存的具体实现吧... 目录1、HashMap2、Guava Cache3、Caffeine4、Encache本地缓存比如 caff

MySQL设置密码复杂度策略的完整步骤(附代码示例)

《MySQL设置密码复杂度策略的完整步骤(附代码示例)》MySQL密码策略还可能包括密码复杂度的检查,如是否要求密码包含大写字母、小写字母、数字和特殊字符等,:本文主要介绍MySQL设置密码复杂度... 目录前言1. 使用 validate_password 插件1.1 启用 validate_passwo

MySQL 数据库表操作完全指南:创建、读取、更新与删除实战

《MySQL数据库表操作完全指南:创建、读取、更新与删除实战》本文系统讲解MySQL表的增删查改(CURD)操作,涵盖创建、更新、查询、删除及插入查询结果,也是贯穿各类项目开发全流程的基础数据交互原... 目录mysql系列前言一、Create(创建)并插入数据1.1 单行数据 + 全列插入1.2 多行数据

MySQL中优化CPU使用的详细指南

《MySQL中优化CPU使用的详细指南》优化MySQL的CPU使用可以显著提高数据库的性能和响应时间,本文为大家整理了一些优化CPU使用的方法,大家可以根据需要进行选择... 目录一、优化查询和索引1.1 优化查询语句1.2 创建和优化索引1.3 避免全表扫描二、调整mysql配置参数2.1 调整线程数2.

MySQL 临时表与复制表操作全流程案例

《MySQL临时表与复制表操作全流程案例》本文介绍MySQL临时表与复制表的区别与使用,涵盖生命周期、存储机制、操作限制、创建方法及常见问题,本文结合实例代码给大家介绍的非常详细,感兴趣的朋友跟随小... 目录一、mysql 临时表(一)核心特性拓展(二)操作全流程案例1. 复杂查询中的临时表应用2. 临时

MySQL 数据库表与查询操作实战案例

《MySQL数据库表与查询操作实战案例》本文将通过实际案例,详细介绍MySQL中数据库表的设计、数据插入以及常用的查询操作,帮助初学者快速上手,感兴趣的朋友跟随小编一起看看吧... 目录mysql 数据库表操作与查询实战案例项目一:产品相关数据库设计与创建一、数据库及表结构设计二、数据库与表的创建项目二:员

MySQL实现多源复制的示例代码

《MySQL实现多源复制的示例代码》MySQL的多源复制允许一个从服务器从多个主服务器复制数据,这在需要将多个数据源汇聚到一个数据库实例时非常有用,下面就来详细的介绍一下,感兴趣的可以了解一下... 目录一、多源复制原理二、多源复制配置步骤2.1 主服务器配置Master1配置Master2配置2.2 从服

Python学习笔记之getattr和hasattr用法示例详解

《Python学习笔记之getattr和hasattr用法示例详解》在Python中,hasattr()、getattr()和setattr()是一组内置函数,用于对对象的属性进行操作和查询,这篇文章... 目录1.getattr用法详解1.1 基本作用1.2 示例1.3 原理2.hasattr用法详解2.