TimesTen(타임스텐)은 MMDBMS업체이자 그 제품명이였다. 2005년 오라클에 합병되면서 Oracle TimesTen In-Memory Database로 이름이 바뀌었다.
MMDBMS를 설명하기 위해서는, DRDBMS를 먼저 설명해야 한다.
DRDBMS는 쿼리 처리에 필요한 데이터를 얻기 위해 디스크를 읽어 데이터를 주 기억장치에 적재한 후, 적재된 데이터를 다시 처리해 원하는 결과를 출력한다. 이러한 과정에서 디스크의 데이터를 메모리로 적재할때 속도 저하가 발생하고, 이를 극복하기 위해 버퍼 캐시나 디스크 읽기/쓰기 최적화를 위한 알고리즘을 개발해 성능향상을 도모했다.
하지만 MMDBMS는 모든 데이터가 처음부터 메모리에 존재한다. 따라서 디스크에서 읽어 메모리에 적재하는 작업이 필요없다. 그만큼 더 빠른 결과를 얻을 수 있다. 단순히 디스크에서 읽는 대신 메모리에서 읽도록 한 것이 아니라, 그로 인해 파생된 처리 프로세스까지 최적화 시킨 것이 MMDBMS이다. 예를 들면, 저장장치 캐시가 제거되어있고, 데이터의 읽기/쓰기 버퍼가 없으며, 인덱싱이 단순화되어있다.
메모리가 비싼 시절에는 상상도 못할 일이었지만, 요즘은 호스트에 수십기가는 보통이기 때문에 MMDBMS를 사용하는데 최대 걸림돌이었던 메모리 가격 문제가 어느정도 해결되었다. 재미있는건, DRDBMS도 느린 HDD대신 SSD 또는 SSD 캐시를 사용해 성능 향상을 도모하고 있다는 점이다. 메인 메모리보다는 플래시 메모리가 용량당 가격이 상대적으로 싸다.
대부분의 RDBMS는 디스크에 데이터를 저장하는 DRDBMS 기반이다. 하지만 옵션으로 MMDBMS형식을 지원하고 있다. 예를 들어 SQLite나 Apache Derby, Berkeley DB, MySQL 등은 설정을 통해 MMDBMS를 지원한다.
요즘엔 MMDB가 아닌 IMDB라고 불리는 경향이 있다.
휘발성인 메인 메모리에 데이터를 저장하기 때문에 시스템에 장애가 발생하면 데이터가 날아가는거 아니냐는 걱정은 하지 말자. 디스크에도 로그를 저장해 놓기 때문에 그런일은 없다.
최근에는 타임스텐에서 OCI 인터페이스도 지원하기 때문에, C/C++ 이식이 더 쉬워졌다.
timesten@wl ~/src # tar xvfz timesten112180.solx8664.tar.gz
timesten@wl ~/src # cd solx8664
timesten@wl ~/src/solx8664 # ./setup.sh
NOTE: Each TimesTen installation is identified by a unique instance name.
The instance name must be a non-null alphanumeric string, not longer
than 255 characters.
Please choose an instance name for this installation? [ tt1121 ]
Instance name will be 'tt1121'.
Is this correct? [ yes ]
Of the three components:
[1] Client/Server and Data Manager
[2] Data Manager Only
[3] Client Only
Which would you like to install? [ 1 ]
Of the following options :
[1] /export/home/timesten
[2] /export/home/timesten/src
[3] Specify a location
[q] Quit the installation
Where would you like to install the tt1121 instance of TimesTen? [ 1 ]
Where would you like to create the daemon home directory? [ /export/home/timesten/TimesTen/tt1121/info ]
The daemon logs will be located in /export/home/timesten/TimesTen/tt1121/info
Would you like to specify a different location for the daemon logs? [ no ]
Installing into /export/home/timesten/TimesTen/tt1121 ...
Uncompressing ...
NOTE: If you are configuring TimesTen for use with Oracle Clusterware, the
daemon port number must be the same across all TimesTen installations
managed within the same Oracle Clusterware cluster.
NOTE: All installations that replicate to each other must use the same daemon
port number that is set at installation time. The daemon port number can
be verified by running 'ttVersion'.
The default port number is 53388.
Do you want to use the default port number for the TimesTen daemon? [ yes ]
The daemon will run on the default port number (53388).
NOTE: For security, we recommend that you restrict access to the
TimesTen installation to members of a single OS group. Only members of
that OS group will be allowed to perform direct mode connections to
TimesTen, and only members of that OS group will be allowed to perform
operations that access TimesTen data stores, TimesTen files and shared
memory. The OS group defaults to the primary group of the instance
administrator. You can default to this group, choose another OS group
or you can make this instance world-accessible. If you choose to make
this instance world-accessible, all database files and shared memory
are readable and writable by all users.
Restrict access to the the TimesTen installation to the group 'timesten'? [ yes ]
In order to use the 'In-Memory Database Cache' feature in any databases
created within this installation, you must set a value for the TNS_ADMIN
environment variable. It can be left blank, and a value can be supplied later
using <install_dir>/bin/ttModInstall.
Please enter a value for TNS_ADMIN (s=skip)? [ ] s
Installing server components ...
What is the TCP/IP port number that you want the TimesTen Server to listen on? [ 53389 ]
Do you want to install QuickStart and the TimesTen Documentation? [ no ]
Would you like to install the documentation (without QuickStart)? [ yes ]
Where would you like to create the doc directory (s=skip)? [ /export/home/timesten/TimesTen/tt1121/doc ]
The TimesTen documentation has been installed in /export/home/timesten/TimesTen/tt1121/doc.
Installing client components ...
NOTE: The TimesTen daemon startup/shutdown scripts have not been installed.
Run the 'setuproot' script :
cd /export/home/timesten/TimesTen/tt1121/bin
./setuproot -install
This will move the TimesTen startup script into its appropriate location.
The startup script is currently located here :
'/export/home/timesten/TimesTen/tt1121/startup/tt_tt1121'.
The 11.2.1.8 Release Notes are located here :
'/export/home/timesten/TimesTen/tt1121/README.html'
Starting the daemon ...
TimesTen Daemon startup OK.
End of TimesTen installation.
timesten@wl ~/src/solx8664 $
여기까지 하면 Times Ten은 설치되었다. 시스템이 재시작될 때 자동으로 설치되도록 하려면 아래와 같이 한다.
root@wl ~ # cd ~timesten/TimesTen/tt1121/bin
root@wl /export/home/timesten/TimesTen/tt1121/bin # ./setuproot -install
Would you like to install the TimesTen daemon startup scripts into /etc/init.d? [ yes ]
Copying /export/home/timesten/TimesTen/tt1121/startup/tt_tt1121 to /etc/init.d
Successfully installed the following scripts :
/etc/init.d/tt_tt1121
/etc/rc0.d/K45tt_tt1121
/etc/rc1.d/K45tt_tt1121
/etc/rc2.d/S90tt_tt1121
root@wl /export/home/timesten/TimesTen/tt1121/bin #
설정
TNS_ADMIN 설정
설치시 미뤄뒀던 TNS_ADMIN을 설정하기 위해, tnsnames.ora 를 먼저 생성한다. 오라클과 연동할 것이 아니라면, 설정할 필요 없다.
timesten@wl ~ # ttmodinstall
The daemon for instance 'tt1121' is currently configured to use port 53388.
Would you like to change this port? [ no ]
The server for instance 'tt1121' is currently configured to use port 53389.
Would you like to change this port? [ no ]
TNS_ADMIN for the instance 'tt1121' is currently not set.
Would you like to change TNS_ADMIN for this instance? [ yes ]
Please enter a value for TNS_ADMIN (q=quit)? [ ] /export/home/timesten/TimesTen/tt1121/network/admin
Do you want to restart the daemon using the new configuration? [ yes ]
Restarting the daemon ...
TimesTen Daemon stopped.
TimesTen Daemon startup OK.
Instance tt1121 is now configured with TNS_ADMIN=/export/home/timesten/TimesTen/tt1121/network/admin
Done ...
메모리 데이터베이스로 사용하기
타임스텐을 사용하는 가장 간단한 예제가, 메모리 데이터베이스로 사용하는 방법에 대한 예제다. 별도의 연동 설정 없이 타임스텐에 데이터베이스를 생성하고 접속할 수 있다.
timesten@wl ~ # vi ~/TimesTen/tt1121/info/sys.odbc.ini
[TT_1121]
Driver=/export/home/timesten/TimesTen/tt1121/lib/libtten.so
DataStore=/export/home/timesten/TimesTen/tt1121/info/TT_1121
DatabaseCharacterSet=KO16MSWIN949
PermSize=32
TempSize=32
timesten@wl ~ # ttIsql TT_1121
Copyright (c) 1996-2011, Oracle. All rights reserved.
Type ? or "help" for help, type "exit" to quit ttIsql.
connect "DSN=TT_1121";
Connection successful: DSN=TT_1121;UID=timesten;DataStore=/export/home/timesten/TimesTen/tt1121/info/TT_1121;DatabaseCharacterSet=KO16MSWIN949;ConnectionCharacterSet=US7ASCII;DRIVER=/export/home/timesten/TimesTen/tt1121/lib/libtten.so;TypeMode=0;
(Default setting AutoCommit=1)
Command> create table a ( s number );
Command> insert into s values (1);
Command> select * from a;
데이터 로그는 디스크에 모두 저장해놓기 때문에 시스템이 꺼져도 데이터는 보존된다. sys.odbc.ini 에서 지정한 디렉토리에 가보면, .ini파일에 지정된 크기를 가진 파일이 생성되어있는 것을 볼 수 있다. 다음 예제를 위해 타임스텐을 종료하고, TT_1121 관련 파일들(DataStore 에 지정된 디렉토리에 있음)을 지운다.
타임스텐에서 오라클 데이터베이스에 접속할 계정과 그 계정이 사용할 테이블스페이스를, 오라클 데이터베이스에 생성하고 권한을 부여한다. 이 예제에서는 cacheuser 로 생성했다.
oracle@wl ~ $ cd ~timesten/TimesTen/tt1121/oraclescripts
oracle@wl /export/home/timesten/TimesTen/tt1121/oraclescripts $ sqlplus "sys as sysdba"
Enter password:
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.
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 PROCEDURE privilege to CACHEUSER
5. Granting the CREATE ANY TRIGGER privilege to CACHEUSER
6. Granting the DBMS_LOB package privilege to CACHEUSER
7. Granting the SELECT on SYS.ALL_OBJECTS privilege to CACHEUSER
8. Granting the SELECT on SYS.ALL_SYNONYMS privilege to CACHEUSER
9. Checking if the cache administrator user has permissions on the default tablespace
Permission exists
11. Granting the CREATE ANY TYPE privilege to CACHEUSER
********* Initialization for cache admin user done successfully *********
타임스텐 데이터베이스를 생성하고, 사용자를 생성하고 CACHE_MANAGER 권한을 부여한다.
timesten@wl ~ $ ttIsql TT_1121
Command> CREATE USER cacheuser IDENTIFIED BY timesten;
Command> GRANT CREATE SESSION, CACHE_MANAGER, CREATE ANY TABLE TO cacheuser;
이제 캐시 그룹을 설정할 차례다. 오라클에 캐시할 테이블을 지정하는 작업이다. 먼저 오라클 데이터베이스에서 샘플로 캐시할 테이블을 생성한다.
oracle@wl ~ # sqlplus cacheuser/oracle@orcl
SQL> create table a (s number primary key);
SQL> insert into a values (1);
SQL> insert into a values (2);
SQL> insert into a values (3);
SQL> commit;
위에서 생성한 a 테이블을 캐시할 캐시 그룹을 만든다.
timesten@wl ~ $ ttIsql "DSN=TT_1121;UID=cacheuser;PWD=timesten;OraclePWD=oracle"
Command> call ttGridNameSet('ttGrid');
Command>
CREATE READONLY CACHE GROUP test_a
FROM cacheuser.a (s number primary key); 1)
Command> select * from a; 2)
0 rows found.
Command> LOAD CACHE GROUP test_a COMMIT EVERY 256 ROWS; 3)
3 cache instances affected.
Command> select * from a;
< 1 >
< 2 >
< 3 >
3 rows found.
Command> ALTER CACHE GROUP test_a SET AUTOREFRESH INTERVAL 5 SECONDS; 4)
1) test_a 라는 읽기전용 캐시 그룹을 생성한다. 캐시될 테이블은 반드시 프라이머리키가 설정되어있어야 한다. 2) 타임스텐에서 a 테이블에 접근하면 아무것도 나오지 않는다. 이는 아직 캐시가 로드되지 않았기 때문이다. 3) 캐시를 로드하고 다시 해본다. 데이터가 제대로 나온다. 4) 매 5초마다 자동갱신하도록 설정한다.
Command> cachegroups;
Cache Group CACHEUSER.TEST_A:
Cache Group Type: Read Only
Autorefresh: Yes
Autorefresh Mode: Incremental
Autorefresh State: On
Autorefresh Interval: 5 Seconds
Autorefresh Status: ok
Aging: No aging defined
Root Table: CACHEUSER.A
Table Type: Read Only
1 cache group found.
timesten@wl ~ $ ttVersion
TimesTen Release 11.2.1.8.0 (64 bit Solaris/x86) (tt1121:53388) 2011-02-03T04:35:00Z
Instance admin: timesten
Instance home directory: /export/home/timesten/TimesTen/tt1121
Group owner: timesten
Daemon home directory: /export/home/timesten/TimesTen/tt1121/info
timesten@wl ~ $ ttStatus
TimesTen status report as of Wed Oct 19 15:55:53 2011
Daemon pid 24843 port 53388 instance tt1121
TimesTen server pid 24848 started on port 53389
------------------------------------------------------------------------
Accessible by group timesten
End of report