程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> Oracle數據庫 >> Oracle教程 >> Oracle內存數據庫Timesten的使用(1)

Oracle內存數據庫Timesten的使用(1)

編輯:Oracle教程

Oracle內存數據庫Timesten的使用(1)


Timesten安裝


開發環境信息
192.168.57.80 /opt/timesten/TimesTen
Daemon pid 12239 port 53396 instance ttgjds
TimesTen server pid 12248 started on port 53397

啟動和停止Timesten數據庫

啟動Timesten

[root@bogon bin]# ttDaemonAdmin -start
TimesTen Daemon startup OK.
[root@bogon bin]# ttDaemonAdmin -force -start

停止Timesten

[root@bogon bin]# ttDaemonAdmin -stop
TimesTen Daemon stopped.

重啟Timesten

[timesten@bogon info]$ ttDaemonAdmin -restart
TimesTen Daemon stopped.
TimesTen Daemon startup OK.

查看Timesten的狀態

[root@bogon bin]# ttstatus
TimesTen status report as of Thu Jul 30 14:35:00 2015

Daemon pid 13029 port 53396 instance ttgjds
TimesTen server pid 13038 started on port 53397
------------------------------------------------------------------------
Data store /opt/timesten/TimesTen/ttgjds/info/DemoDataStore/test_1122
There are no connections to the data store
Replication policy  : Manual
Cache Agent policy  : Manual
PL/SQL enabled.
------------------------------------------------------------------------
Data store /opt/timesten/ttdata/database/gjds
There are no connections to the data store
Replication policy  : Manual
Cache Agent policy  : Manual
PL/SQL enabled.
------------------------------------------------------------------------
Data store /opt/timesten/TimesTen/ttgjds/info/DemoDataStore/sampledb_1122
There are no connections to the data store
Replication policy  : Manual
Cache Agent policy  : Manual
PL/SQL enabled.
------------------------------------------------------------------------
Accessible by group timesten
End of report

創建內存數據庫

timesten采用ODBC方式連接數據庫,比如創建一個名為cachedb_gjds的數據庫

#首先打開配置文件
vi $TIMESTEN_HOME/info/sys.odbc.ini

在[ODBC Data Sources]中添加cachedb_gjds=TimesTen 11.2.2 Client Driver,如下所示

[ODBC Data Sources]
TT_1122=TimesTen 11.2.2 Driver
sampledb_1122=TimesTen 11.2.2 Driver
cachedb1_1122=TimesTen 11.2.2 Driver
repdb1_1122=TimesTen 11.2.2 Driver
repdb2_1122=TimesTen 11.2.2 Driver
sampledbCS_1122=TimesTen 11.2.2 Client Driver
cachedb1CS_1122=TimesTen 11.2.2 Client Driver
repdb1CS_1122=TimesTen 11.2.2 Client Driver
repdb2CS_1122=TimesTen 11.2.2 Client Driver
cachedb_gjds=TimesTen 11.2.2 Client Driver

然後添加下面的內容

#中括號中是DSN名稱
[cachedb_gjds]
Driver=/opt/oracle/TimesTen/tt1122/lib/libtten.so
#ds路徑cachedb_gjds不能是一個文件夾
DataStore=/opt/oracle/TimesTen/ttdata/gjds/cachedb_gjds
#內存大小
PermSize=40
#臨時空間一般是PermSize/4
TempSize=32
#是否允許PLSQL連接
PLSQL=1
#數據庫字符集,注意這裡要與Oracle一致
DatabaseCharacterSet=ZHS16GBK
#連接的字符集
ConnectionCharacterSet=ZHS16GBK
#Oracle TNS名稱
OracleNetServiceName=orcl

Timesten基本使用

1、連接Timesten,Timesten默認是不需要用戶名和密碼的
使用ttisql DSN_NAME或者ttisql “DSN=DSN_NAME;[attributes…]”

[timesten@bogon info]$ ttisql cachedb_gjds

Copyright (c) 1996, 2015, Oracle and/or its affiliates. All rights reserved.
Type ? or "help" for help, type "exit" to quit ttIsql.



connect "DSN=cachedb_gjds";
Connection successful: DSN=cachedb_gjds;UID=timesten;DataStore=/opt/oracle/TimesTen/ttdata/gjds/cachedb_gjds;DatabaseCharacterSet=ZHS16GBK;ConnectionCharacterSet=ZHS16GBK;DRIVER=/opt/oracle/TimesTen/tt1122/lib/libtten.so;PermSize=40;TempSize=32;TypeMode=0;OracleNetServiceName=ORCL;
(Default setting AutoCommit=1)
Command>

2、創建用戶

#Timesten創建用戶與Oracle一致
Command> create user gjds identified by gjds;

User created.

Command> grant connect to gjds;
Command> grant create table to gjds;
Command> grant create view to gjds;
Command> grant admin to gjds;
#用戶創建完之後使用connect切換用戶
Command> connect "DSN=cachedb_gjds;uid=gjds;pwd=gjds"
       > ;
Connection successful: DSN=cachedb_gjds;UID=gjds;DataStore=/opt/oracle/TimesTen/ttdattionCharacterSet=ZHS16GBK;DRIVER=/opt/oracle/TimesTen/tt1122/lib/libtten.so;PermSize=
(Default setting AutoCommit=1)
con1: Command>

3、創建表

Command> CREATE TABLE "TEST"."TIMESTEN_SYNC_TEST" ( 
       > "ID" varchar2(10 byte) NOT NULL,
       > "NAME" varchar2(50 byte),
       > "AGE" number
       >  );
#創建表的語法跟Oracle是一模一樣的,Timesten的語法幾乎與Oracle一致
Command> tables
  TEST.TIMESTEN_SYNC_TEST
1 table found.
#使用tables可以查看數據庫中所有的表信息
Command>INSERT INTO TIMESTEN_SYNC_TEST VALUES('1','1',20);

其他語法與Oracle一致,在此不再贅述。

配置Oracle客戶端

Timesten已經安裝Oracle客戶端,可以不用重復安裝,安裝目錄TIMESTEN_HOME/ttoracle_home/instantclient_11_2
默認的沒有TNS_ADMIN環境變量,需要手動添加

[timesten@bogon support]$vi ~/.bash_profile
#添加 export TNS_ADMIN=/opt/oracle/TimesTen/tt1122/ttoracle_home/instantclient_11_2/network/admin

將tnsnames.ora復制到TNS_ADMIN目錄
添加如下內容

ORCL =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.57.62)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = orcl)
    )
  )

創建一個與Oracle關聯的用戶

語法同創建用戶的語法,用戶名要與Oracle數據庫的用戶名一致。
使用下面的方式登錄用戶

[timesten@bogon info]$ ttisql "DSN=cachedb_gjds;uid=test;pwd=test;OraclePwd=test"

Copyright (c) 1996, 2015, Oracle and/or its affiliates. All rights reserved.
Type ? or "help" for help, type "exit" to quit ttIsql.



connect "DSN=cachedb_gjds;uid=test;pwd=********;OraclePwd=********";
Connection successful: DSN=cachedb_gjds;UID=test;DataStore=/opt/oracle/TimesTen/ttdata/gjds/cachedb_gjds;DatabaseCharacterSet=ZHS16GBK;ConnectionCharacterSet=ZHS16GBK;DRIVER=/opt/oracle/TimesTen/tt1122/lib/libtten.so;PermSize=40;TempSize=32;TypeMode=0;OracleNetServiceName=ORCL;
(Default setting AutoCommit=1)
Command>

這樣登錄就與Oracle用戶建立了連接

使用工具創建表並導入Oracle數據

#ttTableSchemaFromOraQueryGet(['tblOwner'], 'tblName', 'Query')
#只能生成建表語句,不能創建表,需要手動執行下建表語句
Command> call ttTableSchemaFromOraQueryGet('TEST','TIMESTEN_SYNC_TEST','SELECT * FROM TEST.TIMESTEN_SYNC_TEST');
< CREATE TABLE "TEST"."TIMESTEN_SYNC_TEST" ( 
"ID" varchar2(10 byte) NOT NULL,
"NAME" varchar2(50 byte),
"AGE" number
 ) >
1 row found.

#ttLoadFromOracle(['tblOwner'], 'tblName', 'Query' [,numThreads])
#從Oracle數據庫將表的數據導入
Command> CALL ttLoadFromOracle ('TEST','TIMESTEN_SYNC_TEST','SELECT * FROM TEST.TIMESTEN_SYNC_TEST');
< 1 >
1 row found.
Command> select * from TIMESTEN_SYNC_TEST;                                           
< 1, 2, 18 >
1 row found.
Command> tables
  TEST.TIMESTEN_SYNC_TEST
1 table found.

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved