1 Managing TimesTen Databases

A TimesTen database is a collection of objects such as tables, views, and sequences. You can access and manipulate the TimesTen database through SQL statements. If your database does not exist, TimesTen creates the database with the specified attributes when the instance administrator connects to the database. You can free the database shared memory segment by disconnecting all existing connections to the TimesTen database.

This chapter describes first how to configure for a connection to the TimesTen database, because the configuration and management for your TimesTen database is contained in attributes within the connection definition.

Once you have created a database, you can perform the following:

  • Use the ttIsql utility to connect to the database and execute a SQL file or start an interactive SQL session. See "Batch mode vs. interactive mode" for more information.

  • Execute an application that uses the database.

The main topics are as follows:

Connecting to TimesTen with ODBC and JDBC drivers

As described in "TimesTen connection options" in the Oracle TimesTen In-Memory Database Introduction, applications use the TimesTen ODBC driver to access a TimesTen database. Applications can use the ODBC direct driver, the ODBC client driver, or an ODBC driver manager.

Figure 1-1 shows how an application can use different drivers and interfaces to access the TimesTen database.

Figure 1-1 Application access to TimesTen database diagram

Description of Figure 1-1 follows
Description of ''Figure 1-1 Application access to TimesTen database diagram''

  • Open source languages interact with TimesTen through the Oracle Database Programming Interface for C (ODPI-C). The languages currently supported are Python and Node.js. See the Oracle TimesTen In-Memory Database Open Source Languages Support Guide for more details.

  • C applications interact with TimesTen by linking directly with the TimesTen ODBC driver, by linking with the Windows ODBC driver manager, or by using the OCI or Pro*C/C++ interfaces that access the ODBC driver.

  • Java applications interact with TimesTen by loading the JDBC library.

  • C++ applications interact with TimesTen through a TimesTen-provided set of classes called TTClasses or by using the OCI or Pro*C/C++ interfaces that access the ODBC driver.

  • C# applications interact with TimesTen through Oracle Data Provider for .NET support for the TimesTen database.

Consider the following points:

  • An application that links directly with a TimesTen ODBC driver (whether it is linked with the direct driver or client driver) is limited to using only the driver with which it is linked. An application linked directly to a TimesTen ODBC driver can connect to multiple databases at the same time. The TimesTen direct and client drivers support multiple connections to multiple TimesTen databases.

    Note:

    This option offers less flexibility but better performance than linking with a driver manager.
  • An application can link with more than one TimesTen ODBC driver within the same application, even if the drivers are for different TimesTen databases. If the application loads more than one TimesTen ODBC driver, the application must use a driver manager, such as the Windows ODBC driver manager.

    An application might need multiple drivers if it needs to use both the TimesTen direct driver and the TimesTen Client driver.

    The Windows ODBC driver manager dynamically loads an ODBC driver at runtime. However, carefully evaluate the benefits of using the ODBC driver manager, because it may affect the performance of your application with its additional runtime overhead.

    Note:

    An application that is using an ODBC driver manager cannot use XLA.

For more information on how to compile an application that uses the TimesTen driver manager, see "Compiling and linking applications" in the Oracle TimesTen In-Memory Database C Developer's Guide, "Compiling Java applications" in the Oracle TimesTen In-Memory Database Java Developer's Guide, and "Compiling and linking applications" in the Oracle TimesTen In-Memory Database TTClasses Guide.

The following sections describe how to define TimesTen databases:

Connecting using TimesTen ODBC drivers

TimesTen includes the following TimesTen ODBC drivers:

  • TimesTen Data Manager driver: A TimesTen ODBC driver for use with direct connect applications.

  • TimesTen Client driver: A TimesTen Client ODBC driver for use with client/server applications.

TimesTen includes the following two versions of the TimesTen Data Manager driver (direct driver):

  • Production: Use the production version of the TimesTen Data Manager driver for most application development and for all deployment.

  • Debug: Use the debug version of the TimesTen Data Manager driver only if you encounter problems with TimesTen itself. This version performs additional internal error checking and is slower than the production version. On Linux and UNIX, the TimesTen debug libraries are compiled with the -g option to display additional debug information.

For TimesTen Classic support on Windows, you can install the "TimesTen Client 18.1" driver after choosing either the Typical or Custom setup.

On Linux and UNIX, depending on the options selected at install time, TimesTen may install the TimesTen Client driver and both the production version and the debug version of the TimesTen Data Manager driver.

Table 1-1 lists the TimesTen ODBC drivers for Linux and UNIX platforms.

Table 1-1 ODBC drivers provided for Linux and UNIX platforms

Platform Version Location and name

Linux

Production

timesten_home/install/lib/libtten.so

TimesTen Data Manager 18.1 driver.

Linux

Debug

timesten_home/install/lib/libttenD.so

TimesTen Data Manager 18.1 Debug driver.

Linux

Client

timesten_home/install/lib/libttclient.so

TimesTen Client 18.1 driver.

AIX

Production

timesten_home/install/lib/libtten.a

TimesTen Data Manager 18.1 driver.

AIX

Debug

timesten_home/install/lib/libttenD.a

TimesTen Data Manager 18.1 Debug driver.

AIX

Client

timesten_home/install/lib/libttclient.a

TimesTen Client 18.1 driver.


Connecting using the TimesTen JDBC driver and driver manager

JDBC enables Java applications to issue SQL statements to TimesTen and process the results. It is the primary interface for data access in the Java programming language. For TimesTen installations, JDBC is installed with TimesTen.

As shown in Figure 1-1, the TimesTen JDBC driver uses the ODBC driver to access TimesTen databases. For each JDBC method, the driver executes a set of ODBC functions to perform the appropriate operation. Since the JDBC driver depends on ODBC for all database operations, the first step in using JDBC is to define a TimesTen database and the ODBC driver that accesses it on behalf of JDBC.

The TimesTen JDBC API is implemented using native methods to bridge to the TimesTen native API and provides a driver manager that can support multiple drivers connecting to separate databases. The JDBC driver manager in the DriverManager class keeps track of all JDBC drivers that have been loaded and are available to the Java application. The application may load several drivers and access each driver independently. For example, both the TimesTen Client JDBC driver and the TimesTen Data Manager driver can be loaded by an application. Then, Java applications can access databases either on the local system or a remote system.

For a list of the Java functions supported by TimesTen, see "Support for interfaces in the java.sql package" in the Oracle TimesTen In-Memory Database Java Developer's Guide.

Specifying Data Source Names to identify TimesTen databases

When you connect from an application, you use a Data Source Name (DSN) to uniquely identify the particular TimesTen database to which you want to connect. Specifically, a DSN is a character-string name that identifies a TimesTen database and a collection of connection attributes that are to be used when connecting to the database. On Windows, the DSN also specifies the ODBC driver to be used to access the database.

You can also define a default DSN that can be used when a user or an application either does not specify a DSN or specifies a DSN that is not defined in the odbc.ini file at connect time. For details, see "Setting up a default DSN".

Note:

If a user tries to use a DSN that has connection attributes for which they do not have privileges, such as first connection attributes, they receive an error. For more information on first connection attribute privileges, see "Connection Attributes" in the Oracle TimesTen In-Memory Database Reference.

Even though the DSN uniquely identifies a TimesTen database, a database can be referenced by multiple DSNs. The difference between each of these unique DSNs is in the specification of the connection attributes to the database. This provides convenient names to different connection configurations for a single database.

Note:

According to the ODBC standard, when an attribute occurs multiple times in a connection string, the first value specified is used, not the last value.

A DSN has the following characteristics:

  • Its maximum length is 32 characters.

  • It is case insensitive.

  • It is composed of ASCII characters except for the following: ( ) [ ] { } , ; ? * = ! @ \ /

  • TimesTen does not recommend the use of spaces as part of the DSN. If a DSN contains a space, some TimesTen utilities truncate the DSN at the point where they encounter the space. In addition, a DSN cannot start or end with a space, or consist solely of spaces.

The following sections describe how to configure and manage your DSNs:

Overview of user and system DSNs

DSNs are resolved using a two-tiered naming system, where TimesTen first tries to resolve the DSN within the defined user DSNs and secondly within the defined system DSNs.

  • A user DSN can be used only by the user who created the DSN.

    • On Windows, user DSNs are defined from the User DSN tab of the ODBC Data Source Administrator.

    • On Linux and UNIX, define user DSNs in the user odbc.ini file. TimesTen locates this file by first finding if a file is specified by the ODBCINI environment variable. If not, TimesTen locates the $HOME/.odbc.ini file.

    Although a user DSN is private to the user who created it, it is only the DSN, consisting of the character-string name and its attributes, that is private. The underlying database can be referenced by other users' user DSNs or by system DSNs.

    TimesTen supports data sources for both TimesTen Data Manager driver and the TimesTen Client driver in the .odbc.ini file.

  • A system DSN can be used by any user on the system on which the system DSN is defined to connect to the TimesTen database.

    • On Windows, system DSNs are defined from the System DSN tab of the ODBC Data Source Administrator.

    • On Linux and UNIX, system DSNs are defined in the sys.odbc.ini file, which is referred to as the system odbc.ini file. TimesTen locates the system DSN file in the following order:

      • The file is located if it is specified by the SYSODBCINI environment variable.

      • In a non-root installation, the file is located in timesten_home/conf/sys.odbc.ini. In a root installation, the file is located in /var/TimesTen/InstanceName/sys.odbc.ini.

      • If not found in either the root or non-root locations, TimesTen looks for the /var/TimesTen/sys.odbc.ini file.

      • If not found in any of these locations, TimesTen looks on the system for the /etc/odbc.ini file.

Defining DSNs for direct or client/server connections

DSNs are created to uniquely identify a database, whether local or remote. The following explains the type of DSN to use for either a direct or client/server connection:

  • Data Manager DSN: A DSN that specifies a local database on a Linux or UNIX host. You can use either the production version or debug version of the TimesTen Data Manager driver.

    A Data Manager DSN refers to a database using a path name and a file name prefix. The database path name specifies the directory location of the database and the prefix for the database, such as /disk1/databases/AdminDS.

    Note:

    This path name and prefix does not define a file name, but the name of the directory where the database is located and the prefix for all database files. The actual files used by the database append file suffixes, such as /disk1/databases/AdminDS.ds0.

    A Data Manager DSN that refers to a given TimesTen database must be defined on the same system on which the database resides. If multiple Data Manager DSNs refer to the same database, they must all use exactly the same database path name, even if some other path name identifies the same location. For example, you cannot use a symbolic link to refer to the database in one DSN and the actual path name in another DSN.

  • Client DSN: A Client DSN specifies a remote database and uses the TimesTen client. A Client DSN refers to a TimesTen database indirectly by specifying a hostname, DSN pair, where the hostname represents the server system on which TimesTen Server is running and the DSN refers to a Server DSN that specifies the TimesTen database on the server host.

  • Server DSN: A Server DSN is always defined as a system DSN and is defined on the server system for each database on that server that can be accessed by client applications. The format and attributes of a Server DSN are very similar to those of a Data Manager DSN.

On Linux and UNIX, all user DSNs including both Client DSNs and Data Manager DSNs that are created by a specific user are defined in the same user odbc.ini file. Similarly, all system DSNs are defined in the same system odbc.ini file.

The following table indicates the types of DSN supported by TimesTen, whether to create a user or system DSN and the location of the DSN.

DSN type User or System DSN? Location of DSN
Data Manager DSN Can be a user or system DSN Located on the system where the database resides.
Client DSN Can be a user or system DSN Located on any local or remote system.
Server DSN Must be a system DSN Located on the system where the database resides.

For more information about Client DSNs and Server DSNs, see "Working with the TimesTen Client and Server".

Connection attributes for Data Manager DSNs or Server DSNs

On Linux and UNIX, you specify attributes in the odbc.ini file. Attributes that do not appear in the odbc.ini file assume their default value.

There are four types of TimesTen Data Manager DSN or Server DSN attributes:

Note:

For a complete description of all attributes, see "Connection Attributes" in the Oracle TimesTen In-Memory Database Reference.
  • Data Store attributes are associated with a database when it is created and cannot be modified by subsequent connections. They can only be changed by destroying and re-creating the database.

    The following are the most commonly used data store attributes:

    • DataStore: Directory name and file name prefix of the database.

    • LogDir: Directory name of the database transaction log files. Placing the transaction log files and checkpoint files on different disks can improve system performance.

    • DatabaseCharacterSet: Required character set specification that defines the storage encoding.

  • First connection attributes are used when the TimesTen database is loaded into memory. Only the instance administrator can load a database with first connection attribute settings. By default, TimesTen loads an idle database, which is a database with no connections, into memory when a first connection is made to it. These attributes persist for all subsequent connections until the last connection to the database is closed. First connection attributes can be modified only when the TimesTen database is unloaded and then the instance administrator reconnects with different values for the first connection attributes.

    The following are the most commonly used first connection attributes:

    • PermSize: Configures the allocated size of the database's permanent memory region. The permanent memory region contains persistent database objects. TimesTen only writes the permanent memory region to disk during a checkpoint operation.

    • TempSize: Configures the allocated size of the database's temporary memory region. The temporary memory region contains transient data generated when executing statements.

      Note:

      Your system must have sufficient main memory to accommodate the entire database. For more details on setting region sizes, see "Specifying the size of a database".
  • General connection attributes are set by each connection and persist for the duration of the connection. Each concurrent connection can have different values.

    The following are the most commonly used general connection attributes:

    Note:

    If you provide connection attributes in the connection string, this overrides the connection attributes set in the DSN. See "Connecting to a database using a connection string" for details.
    • UID: Specifies the user name to be used for the connection to the database, whether using a direct or client/server connection. To connect as the instance administrator or as an external user, you do not need to specify an user name. When you do not specify an user name, TimesTen assumes that the UID is the user name identified by the operating system.

    • PWD: Specifies the password that corresponds with the specified UID. For internal users, if you do not set the PWD attribute in the odbc.ini file for the specified DSN or in the connection string, TimesTen prompts for the password. For external users, you do not provide the password as it is verified by the operating system.

      When you initiate a client/server connection, the password sent for the connection is encrypted by the client/server protocol.

    • PWDCrypt: Specifies the encrypted password that corresponds with the specified UID.

      Note:

      For more information on the UID, PWD and PWDCrypt general connection attributes, see "UID and PWD" in the Oracle TimesTen In-Memory Database Reference. See the Oracle TimesTen In-Memory Database Security Guide for full details on access control.
  • TimesTen Cache attributes enable you to enter the Oracle Service Identifier for the Oracle database instance from which data is loaded into TimesTen.

Note:

See "Working with the TimesTen Client and Server" for a description of the connection attributes that can be used with the TimesTen Client ODBC driver.

Creating a Data Manager DSN on Linux and UNIX

This section includes the following topics:

Note:

For examples on defining a DSN, see "DSN examples".

Create a user or system odbc.ini file

On Linux and UNIX, user DSNs are defined in the file $HOME/.odbc.ini or in a file named by the ODBCINI environment variable. This file is referred to as the user odbc.ini file. System DSNs are defined in the system odbc.ini file, which is located in timesten_home/conf/sys.odbc.ini.

The syntax for user and system odbc.ini files are the same. The syntax is described in "odbc.ini file entry descriptions". The system odbc.ini file is created when TimesTen is installed on the system. Users must create their own user odbc.ini file.

Perform the following to create the DSN:

  1. Specify the DSN in the odbc.ini file. The DSN appears inside square brackets at the top of the DSN definition on a line by itself. For example:

    [AdminDS]
    
  2. Specify the TimesTen ODBC driver.

    Note:

    JDBC users need to specify the TimesTen ODBC driver to be used by the JDBC driver, as described in ""Connecting using the TimesTen JDBC driver and driver manager"".

    To set the TimesTen ODBC driver, specify the Driver attribute in the odbc.ini file. The following example provides the TimesTen ODBC driver that this DSN is configured to use, where /disk1/timesten is the timesten_home:

    [AdminDS]
    Driver=/disk1/timesten/lib/libtten.so
    

    Note:

    For a list of TimesTen ODBC drivers that you can use, see Table 1-1.
  3. Specify the database directory path and prefix in the odbc.ini file. The following example defines /disk1/databases as the database directory path and FixedDs as the prefix for the database files:

    DataStore=/disk1/databases/FixedDs
    

    The database directory path can use environment variables, as discussed in "Using environment variables in database path names".

  4. Choose a database character set. The following example defines the database character set in the odbc.ini file as AL32UTF8:

    DatabaseCharacterSet=AL32UTF8
    

    Note:

    For more information, see "Choosing a database character set".
  5. Set connection attributes in your odbc.ini file. Attributes that do not appear in the odbc.ini file assume their default value.

    Note:

    See "Connection Attributes" in Oracle TimesTen In-Memory Database Reference. For examples, see "DSN examples".

Using environment variables in database path names

You can use environment variables in the specification of the database path name and transaction log file path name. For example, you can specify $HOME/AdminDS for the location of the database.

Environment variables can be expressed either as $varname or $(varname). The parentheses are optional. A backslash character (\) in the database path name quotes the next character.

Note:

Environment variable expansion uses the environment of the process connecting to the database. Different processes may have different values for the same environment variables and may therefore expand the database path name differently. Environment variables can only be used in the user odbc.ini file. They cannot be specified in the system odbc.ini file.

Defining Client and Server DSNs

For directions on how to define Client or Server DSNs for each platform, see "Defining Server DSNs on a TimesTen Server Linux or UNIX system" and "Creating Client DSNs on a TimesTen Client system".

Resolution path for a DSN

When resolving a specific DSN, TimesTen performs the following:

Note:

  • If a user DSN and a system DSN with the same name exist, TimesTen retrieves the user DSN.

  • On Linux and UNIX, if there are multiple DSNs with the same name in the same odbc.ini file, TimesTen retrieves the first one specified in the file.

  1. Searches for a user DSN with the specified name in the following files:

    1. The file referenced by the ODBCINI environment variable, if it is set.

    2. The .odbc.ini file in the user's home directory, if the ODBCINI environment variable is not set.

  2. If no matching user DSN is found, TimesTen looks for a system DSN with the specified name.

    1. The file referenced by the SYSODBCINI environment variable, if it is set.

    2. The sys.odbc.ini file in the daemon home directory, if the SYSODBCINI environment variable is not set.

    3. On Linux and UNIX, for a non-root installation, the file is located in timesten_home/conf/sys.odbc.ini. Or for a root installation, the file is located at /var/TimesTen/InstanceName/sys.odbc.ini or /var/TimesTen/sys.odbc.ini.

DSN examples

This section provides additional examples of how to set up a database:

Setting up a default DSN

Optionally, you can add a default data source definition. At connect time, if an application specifies a DSN that is not in the odbc.ini file or if the application does not specify a DSN, the default DSN is used to configure the connection to the TimesTen database.

The default data source must be named default when defined. The default DSN can be defined with the same attributes as any other data source, which are described in "DSN specification".

When connecting, TimesTen uses the default DSN in any of the following scenarios:

  • When you specify the DSN=default keyword-value pair in the connection string.

  • When you specify an undefined value for the DSN connection attribute in the connection string.

  • When you do not specify any value for the DSN connection attribute in the connection string.

However, in general, it is best to connect with a specific data source.

When using a default DSN, provide default as the DSN name when performing TimesTen utility operations that require a DSN name, such as destroying the database with the ttDestroy utility.

The following example shows the user invoking ttIsql to connect using an undefined DSN. Since there is no definition for doesNotExist in the odbc.ini file, TimesTen uses the default DSN to create the database and initiate a connection to it. It also demonstrates the user invoking both the ttStatus and ttDestroy utilities with default specified as the DSN. In addition, it shows the error thrown if the user provides doesNotExist as the DSN, instead of default.

% ttIsql doesNotExist;
 
Copyright (c) 1996, 2019 Oracle.  All rights reserved.
Type ? or "help" for help, type "exit" to quit ttIsql.
 
connect "DSN=doesNotExist";
Connection successful:
Command> exit
Disconnecting...
Done.
% ttStatus default
TimesTen status report as of Mon Oct 22 12:27:52 2012
 
Daemon pid 13623 port 16138 instance myhost
TimesTen Server pid 13632 started on port 16140
------------------------------------------------------------------------
Data store /timesten/install/sample_db/default
There are no connections to the data store
Replication policy  : Manual
Cache Agent policy  : Manual
PL/SQL enabled.
------------------------------------------------------------------------
Accessible by group xyz
End of report
% ttDestroy doesNotExist;
Failed to destroy data store: Specified DSN is not found in user and system
odbc.ini files (or registry)
% ttDestroy default; 

The following example shows how to configure connection attributes for a default DSN. While not necessary, you can configure connection attributes for a default DSN as you would configure any other DSN. Notice that it is not specified in the ODBC Data Sources section. Note that /disk1/timesten is the timesten_home.

[ODBC Data Sources]
database1=TimesTen 18.1 Driver
...
 
[default]
Driver=/disk1/timesten/lib/libtten.so
DataStore=/disk1/timesten/sample_db/DemoDataStore/default
PermSize=128
TempSize=64
DatabaseCharacterSet=AL32UTF8

[database1]
Driver=/disk1/timesten/lib/libtten.so
DataStore=/disk1/timesten/sample_db/DemoDataStore/database1
PermSize=128
TempSize=64
DatabaseCharacterSet=AL32UTF8

Specifying PL/SQL connection attributes in a DSN

You can specify values for PL/SQL general connection attributes.

Note:

For a complete list of PL/SQL connection attributes, see "Connection Attributes" in the Oracle TimesTen In-Memory Database Reference.

The following are some PL/SQL connection attributes:

  • PLSCOPE_SETTINGS - Controls whether the PL/SQL compiler generates cross-reference information.

  • PLSQL_OPTIMIZE_LEVEL - Sets the optimization level that is used to compile PL/SQL library units.

  • PLSQL_MEMORY_ADDRESS - Specifies the virtual address, as a hexadecimal value, at which the PL/SQL shared memory segment is loaded into each process that uses the TimesTen direct drivers. This memory address must be identical in all connections to your database and in all processes that connect to your database.

  • PLSQL_MEMORY_SIZE - Determines the size, in megabytes, of the PL/SQL shared memory segment.

This example creates the PLdsn DSN and sets the PL/SQL shared memory segment size to 32 MB.

[PLdsn]
Datastore=/disk1/databases/PLdsn
PermSize=128
DatabaseCharacterSet=AL32UTF8
ConnectionCharacterSet=AL32UTF8
PLSQL_MEMORY_SIZE=32

For more examples, see "PL/SQL connection attributes" in Oracle TimesTen In-Memory Database PL/SQL Developer's Guide.

Creating multiple DSNs to a single database

You can create two or more DSNs that refer to the same database but have different connection attributes.

This example creates two DSNs, AdminDSN and GlobalDSN. The DSNs are identical except for their connection character sets. Applications that use the US7ASCII character set can connect to the TTDS database by using AdminDSN. Applications that use multibyte characters can connect to the TTDS database by using GlobalDSN.

The text in square brackets is the data source name.

AdminDSN is created with the AL32UTF8 database character set and US7ASCII as the connection character set. GlobalDSN is created with the AL32UTF8 database character and AL32UTF8 as the connection character set. Note that /disk1/timesten is the timesten_home.

[AdminDSN]
Driver=/disk1/timesten/lib/libtten.so
Datastore=/disk1/databases/TTDS
DatabaseCharacterSet=AL32UTF8
ConnectionCharacterSet=US7ASCII

[GlobalDSN]
Driver=/disk1/timesten/lib/libtten.so
DataStore=/disk1/databases/TTDS
DatabaseCharacterSet=AL32UTF8
ConnectionCharacterSet=AL32UTF8

odbc.ini file entry descriptions

The following sections describe the entries in the odbc.ini file:

ODBC Data Sources

Each entry in the optional ODBC Data Sources section lists a data source and a description of the driver it uses. The data source section has the following format:

[ODBC Data Sources]
DSN=driver-description
  • The DSN is required and it identifies the data source to which the driver connects. You choose this name.

  • The driver-description is required. It describes the driver that connects to the data source.

The optional Data Sources section, when present in the system DSN file on the TimesTen Server, is used during the setup of Client DSNs. All system DSNs are made available to the Client DSN setup for the ODBC Data Source Administrator on the client, which displays all available DSNs on the TimesTen Server. The user can always add a new system DSN in the ODBC Data Source Administrator. When adding DSNs to the system DSN file, you should only include those DSNs that can be advertised to clients. All system DSNs are potentially accessible through the client/server configuration, even if they are not advertised.

DSN specification

Each DSN listed in the ODBC Data Sources section has its own DSN specification. The DSN specification for Data Manager DSN has the format shown in Table 1-2.

Table 1-2 Data Source specification format

Component Description

[DSN]

The DSN is required. It is the name of the DSN, as specified in the ODBC Data Sources section of your .odbc.ini file.

Driver=driver-path-name

The TimesTen driver that is linked with the data source.

DataStore=data-store-path-prefix

The directory path and prefix of the database to access. This is required.

DatabaseCharacterSet=Database-character-set

The database character set determines the character set in which data is stored. The database character set is required and cannot be altered after the database has been created. For more information, see "Choosing a database character set".

Optional attributes

See "Connection Attributes" in Oracle TimesTen In-Memory Database Reference for information about attributes.


For example, the database1 DSN could have a specification that includes the following. Note that /disk1/timesten is the timesten_home.

[database1]
Driver=/disk1/timesten/lib/libtten.so
DataStore=/disk1/timesten/sample_db/DemoDataStore/database1
...

The database specification for TimesTen Client DSN has the format shown in Table 1-3.

Note:

While the syntax for the TimesTen Client DSN is listed here, full directions for setting the Client DSN and Server DSN are located in "Defining Server DSNs on a TimesTen Server Linux or UNIX system" and "Creating Client DSNs on a TimesTen Client system".

Table 1-3 Database specification for TimesTen Client configurations

Component Description

[DSN]

The DSN is required. It is the same DSN specified in the ODBC Data Sources section of the .odbc.ini file.

TTC_Server=server-name

The server-name is required. It is the DNS name, host name, IP address or logical server name for the TimesTen Server.

TTC_Server_DSN=server-DSN

The server-DSN is required. It is the name of the data source to access on the TimesTen Server.

TTC_Timeout=value

Client connection timeout value in seconds.


Note:

Most TimesTen driver attributes are ignored for TimesTen Client DSNs.

For example, the client/server data source database1CS that connects to database1 on the TimesTen Server ttserver could have a data source specification that includes the following:

[database1CS]
TTC_Server=ttserver
TTC_SERVER_DSN=database1
TTC_Timeout=30

odbc.ini file example

The following example shows portions of a Linux or UNIX .odbc.ini file. Note that /disk1/timesten is the timesten_home.

...
[ODBC Data Sources]
database1=TimesTen 18.1 Driver
...
 
[database1]
Driver=/disk1/timesten/lib/libtten.so
DataStore=/disk1/timesten/sample_db/DemoDataStore/database1
PermSize=128
TempSize=64
DatabaseCharacterSet=AL32UTF8
...
 
########################################################################
# This following sample definitions should be in the .odbc.ini file
# that is used for the TimesTen 18.1 Client.
# The Server Name is set in the TTC_SERVER attribute.
# The Server DSN is set in the TTC_SERVER_DSN attribute.
#########################################################################
 
[ODBC Data Sources]
database1CS=TimesTen 18.1 Client Driver
...
 
[database1CS]
TTC_SERVER=localhost
TTC_SERVER_DSN=database1
...

Connecting to a database using a connection string

TimesTen applications require a DSN or a connection string be specified to connect to a database. For modularity and maintainability, it is better to set attributes in a DSN rather than in a connection string within the application, unless a particular connection requires that specific attribute settings override the settings in the DSN or the default settings.

The syntax for a connection string contains connection attribute definitions, where each attribute is separated by a semicolon.

These precedence rules are used to determine the settings of DSN attributes:

  1. Attribute settings specified in a connection string have the highest precedence. If an attribute appears more than once in a connection string, the first specification is used.

  2. If an attribute is not specified in the connection string, the attribute settings that are specified in the DSN are used.

  3. Default attribute settings have the lowest precedence.

You can connect to a TimesTen database without a predefined DSN with any ODBC application or the ttIsql utility if the connection string contains the DataStore, Driver and DatabaseCharacterSet attributes. Define the connection string as follows:

  • The name or path name of the ODBC driver using the Driver attribute.

    • On Windows, the value of the Driver attribute should be the name of the TimesTen Client Driver.

    • On UNIX systems, the value of the Driver attribute should be the pathname of the TimesTen ODBC Driver shared library file (as described in Table 1-1). The file resides in the timesten_home/lib directory.

  • The database path and file name prefix using the DataStore attribute.

  • The character set for the database using the DatabaseCharacterSet attribute.

The following example shows how you can connect providing the Driver, DataStore and DatabaseCharacterSet attributes using a connection string in the ttIsql utility:

Providing the connection attributes on the connect string from a Linux/UNIX client. Note that /disk1/timesten is the timesten_home.

% ttIsql 

Command> connect "Driver=/disk1/timesten/lib/libtten.so;
DataStore=/disk1/databases/database1;DatabaseCharacterSet=AL32UTF8;

Providing the connection attributes on the connect string from a Windows client:

C:\ ttIsql
Copyright (c) 1996, 2016, Oracle and/or its affiliates. All rights reserved.
Type ? or "help" for help, type "exit" to quit ttIsql.
 
Command> connect "Driver=TimesTen Client 18.1;
DataStore=/disk1/databases/database1;DatabaseCharacterSet=AL32UTF8";

Opening and closing the database for user connections

For an application to be able to connect to a database, the database needs to be open. When a database is closed, any new user connection attempts fail.

  • By default in TimesTen Classic, the database is automatically opened and user connections can connect.

  • By default in TimesTen Scaleout, the database is closed until manually opened. See "Open the database for user connections" in the Oracle TimesTen In-Memory Database Scaleout User's Guide for details.

You can close the database to reject any new user connections to a database.

  • TimesTen Classic: Use the ttAdmin -close command to close the database to any new user connections.

    Since the database can be automatically loaded or unloaded as set by the RAM policy, the status of a database (open or closed) is not aligned with whether the database is currently loaded into memory. Thus, the database could be in an open state as well as unloaded or in a closed state when loaded. See "Loading a database into memory for TimesTen Classic" for an example of the RAM policy.

    You should close a database before manually unloading a database. When loading a closed database into memory, the database cannot be opened until the load operation completes. You can re-open the database with the ttAdmin -open command. See "Unloading a database from memory for TimesTen Classic" for an example.

  • TimesTen Scaleout: Before unloading a database from memory, you must manually close the database. See "Unloading a database from memory" in the Oracle TimesTen In-Memory Database Scaleout User's Guide for details.

Use the following to see the status of your database:

  • TimesTen Classic: Use the ttStatus utility to see the status of the database. See "ttStatus" in Oracle TimesTen In-Memory Database Reference for details.

  • TimesTen Scaleout: Use the ttGridAdmin dbStatus command to see the status of the database. See "Monitor the status of a database (dbStatus)" in Oracle TimesTen In-Memory Database Reference for details.

Loading and unloading the database from memory

TimesTen is an in-memory database. As such, a database must first be loaded into memory from disk to be available for connections. When a database is loaded into memory, the contents of the permanent memory region are read from checkpoint files stored on disk. The temporary memory region is created when a database is loaded into memory and is destroyed when it is unloaded. See "Specifying the size of a database" for more details on permanent and temporary memory.

  • In TimesTen Scaleout: The grid administrator controls how to load and unload the database using the ttGridAdmin utility. See "ttGridAdmin" in the Oracle TimesTen In-Memory Database Reference for details.

  • In TimesTen Classic: RAM policies specify how and when a database is loaded into memory, including whether to automatically reload the database into memory if the database is unloaded unexpectedly. See "Specifying a RAM policy" for full details on the different RAM policies.

    Only the instance administrator can load a database manually. By default, TimesTen automatically loads an idle database (which is a database with no connections) into memory when a first connection is made to it. See "Loading a database into memory for TimesTen Classic" for details.

    After a database loads into memory, you may need to explicitly start the cache and replication agents for the database, depending on the functionality you are using and on which cache and replication policies you set with the ttAdmin utility.

Loading and unloading the database from memory for TimesTen Classic is described in these sections:

Loading a database into memory for TimesTen Classic

  1. Before you try to load the database into memory for TimesTen Classic, confirm that the TimesTen daemon is running with the ttStatus utility. The following output shows that the TimesTen daemon is not running.

    % ttStatus
    ttStatus: Could not connect to the TimesTen daemon.
    If the TimesTen daemon is not running, please start it by running "ttDaemonAdmin -start".
    
  2. Start the TimesTen daemon, if necessary.

    % ttDaemonAdmin -start
    
  3. The RAM policy setting is important as it specifies if, how, and when the database is loaded or unloaded from memory. The default RAM policy for a TimesTen database is inUse.

    You can set the RAM policy before loading the database into memory. See "Specifying a RAM policy" for more information.

    The following example sets the RAM policy of a TimesTen database to manual:

    % ttAdmin -ramPolicy manual database1
    
    RAM Residence Policy            : manual
    Manually Loaded In RAM          : False
    Replication Agent Policy        : manual
    Replication Manually Started    : False
    Cache Agent Policy              : manual
    Cache Agent Manually Started    : False
    Database state                  : open
    
  4. Use the ttAdmin utility to load (or reload) the database into memory, or unload the database from memory.

    If the RAM policy is manual for the database database1, then load the TimesTen database into memory with the ttAdmin -ramload utility. The -ramLoad option of the ttAdmin utility can only be used with the manual RAM policy:

    % ttAdmin -ramLoad database1
    
    RAM Residence Policy            : manual
    Manually Loaded In RAM          : True
    Replication Agent Policy        : manual
    Replication Manually Started    : False
    Cache Agent Policy              : manual
    Cache Agent Manually Started    : False
    Database state                  : open
    

    If the RAM policy is manual, you can change it to always to specify that the database is always reloaded.

    ttAdmin -ramPolicy always database1
    

    If the RAM policy is inUse, then you want the grace period to be greater than 0, so that the database will be kept in memory for that time period when idle:

    % ttAdmin -ramPolicy inUse -ramGrace 200 database1
    
    RAM Residence Policy            : inUse plus grace period
    RAM Residence Grace (Secs)      : 200
    Replication Agent Policy        : manual
    Replication Manually Started    : False
    Cache Agent Policy              : manual
    Cache Agent Manually Started    : False
    Database state                  : open
    

    If the RAM policy is manual for the database database1 and the database was previously closed to incoming connections, then you can both load and open the TimesTen database into memory with the ttAdmin -ramload -open command.

    % ttAdmin -ramLoad -open database1
    
    RAM Residence Policy            : manual
    Manually Loaded In RAM          : True
    Replication Agent Policy        : manual
    Replication Manually Started    : False
    Cache Agent Policy              : manual
    Cache Agent Manually Started    : False
    Database state                  : open
    
  5. If your database is configured for replication or cache for your database, run the ttAdmin utility to start the replication and cache agents.

    To start replication:

    ttAdmin -repStart database1
    

    To start TimesTen Cache:

    ttAdmin -cacheStart database1
    

For more information on these utilities, see "ttAdmin" and "ttDaemonAdmin" in the Oracle TimesTen In-Memory Database Reference.

Unloading a database from memory for TimesTen Classic

In TimesTen Classic, a database remains loaded in shared memory if any applications or TimesTen agents, such as the cache agent or replication agent, are connected to it. In TimesTen Classic, a database may also be kept in shared memory for particular RAM policy setting, even when no applications or agents are connected.

Before unloading the database from memory for TimesTen Classic, you must first close the database, close all active connections to the database and then set the RAM policy of the database to manual or inUse.

Note:

The following steps use examples where database1 is the database that is to be unloaded. It is assumed that it is the active master in a replication scheme and has been configured with TimesTen Cache. Note that a database can have both replication and cache configured, and a RAM policy other than manual.
  1. Close the database to reject any new requests to connect to the database.

    ttAdmin -close database1
    
  2. Disconnect all applications from the database.

    To close all active connections to the database, run the ttAdmin -disconnect command. For more information, see "Disconnecting from a database" in this book and "ttAdmin" in the Oracle TimesTen In-Memory Database Reference.

  3. If the replication agent is running on the database, set the replication state to pause and stop the replication agent. The example sets the replication state from the active master database1 to the standby master standbydb to pause, then stops the replication agent on the active master database1.

    ttRepAdmin -receiver -name database1 -state pause standbydb
    ttAdmin -repStop database1
    
  4. If the cache agent is running on the database, stop the cache agent.

    ttAdmin -cacheStop database1
    
  5. Ensure that the RAM policy is set to either manual or inUse. Then unload the database from memory. See "Specifying a RAM policy" for more information.

    If the RAM policy is set to always, change it to manual and then unload the database from memory with the ttAdmin -ramPolicy -ramUnload utility options.

    ttAdmin -ramPolicy manual -ramUnload database1
    

    If the RAM policy is set to manual, unload the database with the ttAdmin -ramUnload utility:

    ttAdmin -ramUnload database1
    

    If the RAM policy is set to inUse and a grace period is set, set the grace period to 0 or wait for the grace period to elapse. This results in the database being unloaded. TimesTen unloads a database with an inUse RAM policy from memory once you close all active connections.

    ttAdmin -ramGrace 0 database1
    
  6. Run the ttStatus utility to verify that the database has been unloaded from memory and the database is closed. The database is unloaded if there are no processes. The database is closed when the output shows "Closed for user connections."

    See "ttStatus" in Oracle TimesTen In-Memory Database Reference for details.

  7. Optionally, stop the TimesTen daemon.

    ttDaemonAdmin -stop
    

For more information on the ttAdmin utility, see "ttAdmin" in the Oracle TimesTen In-Memory Database Reference.

Specifying a RAM policy

TimesTen Classic allows you to specify a RAM policy that determines when TimesTen Classic databases are loaded and unloaded from main memory. For each TimesTen Classic database, you can have a different RAM policy.

Note:

TimesTen Scaleout supports the manually loading and unloading of the database through the ttGridAdmin utility by system administrators.

The RAM policy options are as follows:

  • inUse: The database is loaded into memory when the first connection to the database is opened, and it remains in memory as long as it has at least one active connection. When the last connection to the database is closed, the database is unloaded from memory. This is the default policy.

  • inUse with RamGrace: The database is loaded into memory when the first connection to the database is opened, and it remains in memory as long as it has at least one active connection. When the last connection to the database is closed, the database remains in memory for a "grace period." The database is unloaded from memory only if no processes have connected to the database for the duration of the grace period. The grace period can be set or reset at any time. It stays in effect until the next time the grace period is changed.

  • always: The database always stays in memory. If the TimesTen daemon is restarted, it automatically reloads the database. The database is always automatically reloaded unless an unrecoverable error condition occurs. For more details on database error recovery, see "Changes to RAM policy after automatic recovery fails".

  • manual: The database is manually loaded and unloaded by system administrators. Once loaded, TimesTen ensures that the database stays loaded until the administrator unloads the database or unless an unrecoverable error condition occurs. For more details on database error recovery, see "Changes to RAM policy after automatic recovery fails".

A system administrator can set the RAM policy or manually load or unload a database in TimesTen Classic with either the ttAdmin utility or the C API RAM policy utilities. For more details, see "ttAdmin" in the Oracle TimesTen In-Memory Database Reference or the "TimesTen Utility API" chapter in the Oracle TimesTen In-Memory Database C Developer's Guide.

Note:

By default, if an automatic recovery of the database is unsuccessful after a fatal error, TimesTen Classic changes the always and manual RAM policies to InUse to prevent reoccurring failures. For more information on how to prevent the RAM policy from changing, see "Changes to RAM policy after automatic recovery fails".

The following example sets the RAM policy to always for the database identified by the ttdata DSN:

Note:

The first line shows the RAM residence policy set to always. The rest of the output details other policies you can set with the ttAdmin utility. See "ttAdmin" in the Oracle TimesTen In-Memory Database Reference for more information.
% ttAdmin –ramPolicy always ttdata
RAM Residence Policy            : always
Replication Agent Policy        : manual
Replication Manually Started    : False
Cache Agent Policy              : manual
Cache Agent Manually Started    : False
Database state                  : open

Changes to RAM policy after automatic recovery fails

If a fatal error invalidates the database and the automatic database recovery performed by TimesTen Classic is unsuccessful, the following occurs by default:

  • The RAM policies of manual and always remain unchanged.

  • The replication and cache agents are not restarted.

  • After several failed attempts to reload the database, TimesTen Classic sets the policyInactive mode, which prevents any more attempts at loading the database.

Note:

Reloading a large database into memory when an invalidated database still exists in memory can fill up available RAM. See "Preventing an automatic reload of the database after failure" on how to stop automatic reloading of the database.

Preventing an automatic reload of the database after failure

After a fatal error that causes the database to be invalidated, TimesTen attempts to reload and recover the database, as long as it is consistent with the settings for the RAM policy, cache agent policy, and replication agent policy. However, user processes could still be connected to the invalidated database if they do not know that the original database has been invalidated. In this case, the invalidated database exists in memory until all user processes close their connections. Thus, the invalidated database could coexist in memory with the newly reloaded database. This can be an issue if the database is large.

Note:

Not only does the RAM policy determines whether the database is reloaded and recovered, but the cache agent and replication agent policies also factor into whether the database is reloaded after invalidation. If the cache agent and replication agent policies are set so that the daemon automatically restarts the agent after a failure, the agent initiates a connection to the database. If this is the first connection, the daemon reloads the database and performs a recovery.

For more information on cache agent and replication agent policies, see "Starting and stopping the replication agents" in the Oracle TimesTen In-Memory Database Replication Guide, "Set a cache agent start policy" in the Oracle TimesTen Application-Tier Database Cache User's Guide, and "ttAdmin" in the Oracle TimesTen In-Memory Database Reference.

You can prevent the database from being automatically reloaded after an invalidation using the ttAdmin -noautoreload command. You can reset to the default automatic database reload behavior with the ttAdmin -autoreload command. See "ttAdmin" in the Oracle TimesTen In-Memory Database Reference for more details.

Note:

The ttRamPolicyAutoReloadSet built-in procedure performs the same actions as ttAdmin -noautoreload and ttAdmin -autoreload. See "ttRamPolicyAutoReloadSet" in the Oracle TimesTen In-Memory Database Reference for more details.

Any one of the following initiates a reload and recovery of the database so that normal behavior can resume:

  • The TimesTen daemon restarts.

  • A process connects successfully.

  • The administrator executes a ttAdmin command for the database that changes the RAM policy, performs a RAM load, or starts either the cache or replication agents.

If you set the behavior to prevent automatic reloads of the database, you may receive the following error when connecting to a database that was not reloaded.

Error 707, "Attempt to connect to a data store that has been manually unloaded from RAM"

Disconnecting from a database

You can shut down or unload the database by first disconnecting applications in an orderly fashion. The forced disconnect option asynchronously disconnects all connected applications from the database, including those that are idle or unresponsive.

  • Reliably disconnects and detaches from the shared memory segment for a database.

  • Successfully disconnects any idle or unresponsive connections.

The following sections describe how to disconnect connections from a TimesTen database:

Disconnecting from a database in TimesTen Scaleout

If you are unable to individually disconnect every application from the TimesTen Scaleout database, use the ttGridAdmin dbDisconnect command to disconnect all user connections from the database. See "Unloading a database from memory" in the Oracle TimesTen In-Memory Database Scaleout User's Guide for full details.

Disconnecting from a database in TimesTen Classic

You can disconnect all connections to a TimesTen Classic database with the ttAdmin -disconnect command. However, you must first enable the capability for forced disconnect by setting the ForceDisconnectEnabled connection attribute to 1 in the DSN definition within the sys.odbc.ini file. See "ForceDisconnectEnabled" in the Oracle TimesTen In-Memory Database Reference for more details.

While control returns to the command prompt, the force disconnect operation may take multiple seconds (or minutes) to complete. Verify the status of the force disconnect operation with the ttStatus utility.

While the forced disconnect operation is in process, any new connection request is rejected by the main daemon. Once the force disconnect operation completes, new connections are accepted.

You can specify how urgently you need connections to be forced to disconnect with the urgency level:

  • The -transactional option waits for any open transactions to be committed or rolled back before disconnecting. Does not affect idle connections.

  • The -immediate option rolls back any open transactions before immediately disconnecting. This option also disconnects idle connections.

  • The -abort option aborts all direct mode application processes and client/server processes (ttcserver) in order to disconnect.

Most of the time, you should use the transactional and immediate urgency levels. A recommended practice is to run the -disconnect command twice, as necessary. First use the transactional urgency level. Then, after allowing some time, use ttStatus to confirm whether connections have been closed. If not all connections have been closed yet, then use the immediate urgency level.

The abort urgency level should only be used on the rare occasion when both the transactional and immediate urgency levels fail to successfully disconnect all specified connections. The abort option could result in lost transactions, as the abort operation abruptly causes every user and ttcserver process connected to the database to exit.

You can specify which type of connections to disconnect with the granularity level.

  • The -users option (default) disconnects every user connection to the database. For example, use this granularity level when preparing to perform database maintenance.

  • The -unload option disconnects every connection to the database, including subdaemon connections. For example, use this granularity level when attempting to unload the database.

Note:

The always RAM policy conflicts with the unload granularity level. Using these simultaneously returns an error.

See "Force disconnect" in the Oracle TimesTen In-Memory Database Reference for more details on using the ttAdmin -disconnect command.

Example 1-1 Disconnecting all connections and unloading a TimesTen Classic database

The following script disconnects all connections and unloads the database by first executing ttAdmin -disconnect with the transactional urgency level. Then, the script waits a short time to evaluate if the connections disconnected before trying the immediate urgency level.

#!/bin/sh
 
# disconnect users and unload the database with the transactional urgency level
ttAdmin -disconnect -transactional -unload database1
 
# wait 10 seconds for the forced disconnect to finish
COUNT = 0
while [ ttStatus | grep "pending disconnection" ] || [ $COUNT -ne 10 ]
do
  sleep 1
  COUNT=$((COUNT+1))
done
 
# increase the urgency level to immediate
if [ ttStatus | grep "pending disconnection" ]; then
  ttAdmin -disconnect -immediate -unload database1
fi

Use the ttStatus utility to check progress. During a forced disconnect operation, the output indicates the pending disconnections:

TimesTen status report
 
Daemon pid 10457 port 6627 instance user1
TimesTen server pid 10464 started on port 6629
------------------------------------------------------------------------
------------------------------------------------------------------------
Data store /disk1/databases/database1
Daemon pid 10457 port 6627 instance user1
TimesTen server pid 10464 started on port 6629
There are 14 connections to the data store, ***14 pending disconnection***
Shared Memory KEY 0x0210679b ID 949092358
PL/SQL Memory KEY 0x0310679b ID 949125127 Address 0x5000000000
Type            PID     Context             Connection Name              ConnID
Process         10484   0x00007f3ddfeb4010  tt_181                            1
...

Specifying the size of a database

TimesTen manages database space using two separate memory regions within a single contiguous memory space. One region contains permanent data and the other contains temporary data.

  • Permanent data includes the tables and indexes that make up a TimesTen database. When a database is loaded into memory, the contents of the permanent memory region are read from files stored on disk. The permanent memory region is written to disk during checkpoint operations. TimesTen stores all data in RAM to achieve exceptional performance. The database throws an error if there is no space left for a new piece of data. PermSize can be increased with a database restart but it cannot be decreased.

  • Temporary data includes locks, cursors, compiled commands, and other structures needed for command execution and query evaluation. The temporary memory region is created when a database is loaded into memory and is destroyed when it is unloaded.

The connection attributes that control the size of the database when it is in memory are PermSize and TempSize. The PermSize attribute specifies the size of the permanent memory region and the TempSize attribute specifies the size of the temporary memory region.

Note:

See "PermSize" and "TempSize" in the Oracle TimesTen In-Memory Database Reference for further description of these attributes.

The sizes of the permanent and temporary memory regions are set when a database is loaded into memory and cannot be changed while the database is in memory. To change the size of either region, you must unload the database from memory and then reconnect using different values for the PermSize or TempSize attributes. See "Unloading a database from memory for TimesTen Classic" for more information on unloading the database from memory.

Managing the database size is described in these sections:

Estimating and modifying the memory region sizes for the database

Database operations cannot complete successfully without allocation of sufficient memory. First, determine appropriate sizes for the TimesTen permanent and temporary memory regions and the transaction log buffer.

Use the ttSize utility or run the application until you can make reasonable estimates, then set these TimesTen connection attributes:

  • PermSize: Size of the permanent memory region, in MB, for the database where the actual data is stored. Make sure PermSize is sufficient to hold all the data. You can increase this value, but not decrease it for this database. Decreasing the permanent memory region can only be done with by re-creating the database with a smaller size. See "Reducing database size" for how to decrease the database size.

  • TempSize: For TimesTen Classic, TempSize indicates the total amount of memory in MB allocated to the temporary region for the database. For TimesTen Scaleout, TempSize indicates the total amount of memory in MB allocated to the temporary region for an element. Related database operations may fail if TempSize is insufficient. You can only change the size with a database restart.

  • LogBufMB: Size of the internal transaction log buffer, in MB. By default LogBufMB is 64 MB. See "Configure log buffer and log file size parameters" for details.

See "PermSize", "TempSize", "LogBufMB" and "LogFileSize" in the Oracle TimesTen In-Memory Database Reference for further description of these attributes.

Next, ensure that the maximum shared memory segment size of your system is large enough to contain the database. Use the maximum number of connections that you expect your database to use. All of the values are in MB (megabytes). Make it larger than the following:

PermSize + TempSize + LogBufMB + 1 + (.043 * connections)

Note:

If the database is configured for replication, reconfigure the database sizes for all replicas of the database. Once you have made the change in database size, load the database into memory and restart the cache and replication agents.

If there are multiple TimesTen databases on your system, each using its own shared memory segment, the maximum shared memory segment size must be large enough to accommodate the largest database.

Next, determine the total shared memory allocation you will need (converted to appropriate units). If there are multiple TimesTen databases on your system, the total shared memory allocation must be large enough to accommodate all of them, using the above equation for each database. (Then, on Linux for example, divide this value by the page size, typically 4096 bytes, to get total memory allocation in pages.)

Note:

Additional shared segments may be created either for PL/SQL with the PLSQL_MEMORY_SIZE connection attribute or for Client/Server with the -server_shmsize configuration option (in timesten.conf). Refer to "PLSQL_MEMORY_SIZE" in Oracle TimesTen In-Memory Database Reference and for more information. If you use the default values or similarly small sizes, there should be enough unused space in shared memory to accommodate these segments.

Finally, if you want to allow for database invalidations, there must be at least twice as much physical memory as the size of the largest TimesTen database. If you do not allow for this, but an invalidation does occur, you cannot reload the database into memory until all processes and connections that used the database have been found and terminated.

Also see "Linux prerequisites" in Oracle TimesTen In-Memory Database Installation, Migration, and Upgrade Guide.

Reducing database size

Once a database has been defined with a particular size for the permanent region (indicated by the PermSize DSN attribute), it cannot be reduced to a smaller size, even if tables or rows are deleted.

To reduce the allocated size of the permanent region of a database, run the ttMigrate utility to save a copy of the database and then re-create the database with a smaller permanent region size and restore the data.

Perform these steps to reduce the permanent region size of a database:

  1. Disconnect applications from the database with the ttAdmin -disconnect command. For more information, see "Disconnecting from a database" in this book and "ttAdmin" in the Oracle TimesTen In-Memory Database Reference.

  2. Use the ttMigrate -c option to create a data file for the database.

    % ttMigrate -c database1 /tmp/database1
    
  3. Unload the database from memory. See "Unloading a database from memory for TimesTen Classic" in this book and "Unloading a database from memory" in the Oracle TimesTen In-Memory Database Scaleout User's Guide for full details for more information.

  4. Create a new DSN definition for the new copy of the database with a smaller PermSize value. To modify the original DSN rather than create a new one, you must destroy the original database using the ttDestroy utility before restoring from the backup.

  5. Recreate the database using AutoCreate=1.

    ttIsql -connstr "dsn=database1;AutoCreate=1" -e "quit"
    

    The database will be empty at this point.

  6. Restore the backup, using the ttMigrate -r and -relaxedUpgrade options.

    % ttMigrate -r -relaxedUpgrade database1 /tmp/database1
    

Notes:

  • The permanent region size of a database cannot be reduced below the size that is required by the data currently stored in the database. This value can be determined by querying the perm_in_use_size column of the v$monitor system view.

  • You can also use this procedure to compact the database in order to reduce fragmentation caused by partially full table pages or fragmentation of the heap buffers that store index nodes and out-of-line values.

Ensuring sufficient disk space

TimesTen saves a copy of the database in two checkpoint files, each of which is stored in the directory that is specified with the DataStore attribute. As each checkpoint file grows on disk, it never decreases in size. This can result in the size of each checkpoint file being equal to the maximum size that the database has ever reached in the permanent memory region. The maximum size for each checkpoint file is PermSize + the database header or overhead that is noted in the preceding section, "Estimating and modifying the memory region sizes for the database". For each permanent database, you must have enough disk space for both checkpoint files and all transaction log files. For more information about the DataStore attribute, see "DataStore" in the Oracle TimesTen In-Memory Database Reference.

You can set the Preallocate connection attribute to 1 to have TimesTen reserve disk space at connect time for checkpoint files. This is useful for big databases, to ensure that the disk always has room for the checkpoint files as data is added to the database. For more information about the Preallocate connection attribute, see "Preallocate" in the Oracle TimesTen In-Memory Database Reference.

Monitoring PermSize and TempSize attributes

The ttIsql dssize command and the TimesTen table SYS.MONITOR contains several columns that can be used to monitor usage of PermSize and TempSize. These columns include PERM_ALLOCATED_SIZE, TEMP_ALLOCATED_SIZE, PERM_IN_USE_SIZE, PERM_IN_USE_HIGH_WATER, TEMP_IN_USE_SIZE, and TEMP_IN_USE_HIGH_WATER. Each of these columns show in KB units the currently allocated size of the database and the in-use size of the database. The system updates this information each time a connection is made or released and each time a transaction is committed or rolled back.

For example, you could evaluate the temporary space usage by running a full workload and watching the high water mark (TEMP_IN_USE_HIGH_WATER) of the temporary space usage. The high water mark can be reset using the ttMonitorHighWaterReset built-in procedure. And if necessary, you can change TempSize to a value of the observed TEMP_IN_USE_HIGH_WATER value and add 10%. See "Using the ttIsql dssize command" and "ttIsql" in the Oracle TimesTen In-Memory Database Reference for more details.

You can monitor block-level fragmentation in the database by calling the ttBlockInfo built-in procedure. For more details, see "ttBlockInfo" in the Oracle TimesTen In-Memory Database Reference.

Receiving out-of-memory warnings

TimesTen provides two general connection attributes that determine when a low memory warning should be issued: PermWarnThreshold and TempWarnThreshold. Both attributes take a percentage value.

To receive out-of memory warnings, applications must call the built-in procedure ttWarnOnLowMemory.

Managing existing tables in the database

You can manage certain aspects of existing tables in the database with the ttBulkCp utility. With the ttBulkCp utility, you can add rows of data to an existing table, save data to an ASCII file, and load the data rows into a table in a TimesTen database.

The rows you are adding must contain the same number of columns as the table, and the data in each column must be of the type defined for that column.

Because the ttBulkCp utility works on data stored in ASCII files, you can also use this utility to import data from other applications, provided the number of columns and data types are compatible with those in the table in the TimesTen database and that the file found is compatible with ttBulkCp. See "Working with the ttBulkCp utility" for more information.

Working with the ttBulkCp utility

The ttBulkCp utility enables you to copy data between TimesTen tables and ASCII files:

Copying data from a TimesTen table to an ASCII file

Run the ttBulkCp utility with the -o option to copy data from a TimesTen table to an ASCII file.

Note:

Ensure that your TimesTen user has SELECT privilege on the tables it copies information from.

Example 1-2 ttBulkCp -o mode

This example copies the data from the hr.employees table of the database1 database to the employees.dmp file.

% ttBulkCp -o -connstr "DSN=database1;UID=HR;PWD=hr" hr.employees > employees.dmp

For more information about the ttBulkCp utility, see "ttBulkCp" in the Oracle TimesTen In-Memory Database Reference.

Copying data from an ASCII file into a TimesTen table

The ttBulkCp utility enables you to copy data from an ASCII file into a database table. Both the -i and -directLoad options load data with standard INSERT SQL statements. The ttBulkCp utility does not copy duplicate rows into a table.

Running ttBulkCp with the -i option

Run the ttBulkCp utility with the -i option to copy data from an ASCII file into a TimesTen table.

Note:

Ensure that your TimesTen user has INSERT privilege on the tables it copies information into.

Example 1-3 ttBulkCp -i mode

This example copies the data from the employees.dmp file into the hr.employees table of the database1 database.

% ttBulkCp -i -connstr "DSN=database1;UID=HR;PWD=hr" hr.employees employees.dmp

employees.dmp:
    107 rows inserted
    0 duplicate rows not inserted
    107 rows total

For more information about the ttBulkCp utility, see "ttBulkCp" in the Oracle TimesTen In-Memory Database Reference.

Running ttBulkCp with the -directLoad option

Run the ttBulkCp utility with the -directLoad option to copy data from an ASCII file into a TimesTen table. The ttBulkCp -directLoad option can only be used by applications using direct connections, which avoids some of the overhead required when using client/server connections resulting in better performance than the -i option. Can only be used with TimesTen Classic.

For improved performance, consider dropping indexes before loading data with the -directLoad option. Use the ttSchema utility to view the definition of all the indexes that are created on the tables of a TimesTen database. Once the load operation is complete, manually re-create the indexes on your TimesTen table. For more information about the ttSchema utility, see "ttSchema" in the Oracle TimesTen In-Memory Database Reference.

Note:

Ensure that your TimesTen user has INSERT privilege on the tables it copies information into.

Example 1-4 ttBulkCp -directLoad option

This example copies the data from the employees.dmp file into the hr.employees table of the database1 database.

% ttBulkCp -directLoad -connstr "DSN=database1;UID=HR;PWD=hr" hr.employees employees.dmp

employees.dmp:
    107 rows inserted
    0 duplicate rows not inserted
    107 rows total

For more information about the ttBulkCp utility, see "ttBulkCp" in the Oracle TimesTen In-Memory Database Reference.

Thread programming with TimesTen

TimesTen supports multithreaded application access to databases. When a connection is made to a database, any thread may issue operations on the connection.

Typically, a thread issues operations on its own connection and therefore in a separate transaction from all other threads. In environments where threads are created and destroyed rapidly, better performance may be obtained by maintaining a pool of connections. Threads can allocate connections from this pool on demand to avoid the connect and disconnect overhead.

TimesTen allows multiple threads to issue requests on the same connection and therefore the same transaction. These requests are serialized by TimesTen, although the application may require additional serialization of its own.

TimesTen also allows a thread to issue requests against multiple connections, managing activities in several separate and concurrent transactions on the same or different databases.

Defragmenting TimesTen databases

Under some circumstances, a TimesTen database may develop memory fragmentation such that significant amounts of free memory are allocated to partially filled pages of existing tables. This can result in an inability to allocate memory for other uses (such as new pages for other tables) due to a lack of free memory. In these circumstances, it is necessary to defragment the database in order to make this memory available for other uses.

A secondary table partition is created after a table has been altered with the ALTER TABLE ADD SQL statement. Defragmentation enables you to remove the secondary table partitions and create a single table partition that contains all of the table columns. When secondary table partitions have been created, it is recommended to periodically defragment the database in order to improve space utilization and performance.

The following procedures address both types of database fragmentation:

Offline defragmentation of TimesTen databases

To defragment a database, use the ttMigrate utility as follows:

  1. Stop all connections to the database.

  2. Save a copy of the database using ttMigrate.

    % ttMigrate -c ttdb ttdb.dat
    
  3. As the administration user, rebuild the ttdb database:

    % ttMigrate -r -relaxedUpgrade -connstr "dsn=ttdb" ttdb.dat
    

    Note:

    You can achieve maximum table defragmentation with the ttMigrate -r -relaxedUpgrade command. The -relaxedUpgrade option also condenses table partitions. If you do not want to condense table partitions, remove the -relaxedUpgrade option from the ttMigrate -r -relaxedUpgrade command.

At this time:

  • All the users, cache groups, and the active standby pair have been restored to ttdb.

  • The cache groups are in AUTOREFRESH STATE = OFF.

  • The cache agent and replication agent are not running.

Table partitions can be added when columns are added to tables with the ALTER TABLE ADD SQL statement. See the notes on "ALTER TABLE" in the Oracle TimesTen In-Memory Database SQL Reference for more information. Also see, "Avoid ALTER TABLE" for performance considerations.

For more information on ttMigrate, see "ttMigrate" in the Oracle TimesTen In-Memory Database Reference.

Online defragmentation of TimesTen databases

Use a combination of the ttMigrate -relaxedUpgrade and ttRepAdmin -duplicate utilities to defragment TimesTen databases (with minimal overall service downtime) that are involved in a replication scheme where TABLE DEFINITION CHECKING is set to RELAXED. In addition, the ttMigrate -relaxedUpgrade option condenses partitions.

Note:

You can only defragment TimesTen databases that are involved in an active standby pair replication scheme if the replication scheme either does not contain any cache groups or contains only READONLY cache groups.

The following sections describe how to defragment TimesTen databases that are involved in a replication scheme:

Note:

The examples provided in each section assume that you are familiar with the configuration and management of replication schemes. For more information, see "Getting Started" in the Oracle TimesTen In-Memory Database Replication Guide.

Online defragmentation of databases in an active standby pair replication scheme

The following sections describe how to defragment TimesTen databases that are involved in an active standby pair replication scheme:

The example in this section shows how to perform an online defragmentation with an active standby pair replication scheme where the active database is ttdb1 and the standby database is ttdb2.

Migrate and rebuild the standby database

The following shows how to stop replication to the standby TimesTen database, save a copy of the standby database, and then defragment the standby database.

Note:

While the standby database is defragmented, application processing can continue on the active database.

Perform the following to save a copy of the standby database:

  1. Stop the replication agent on the standby database (ttdb2):

    % ttAdmin –repStop ttdb2
    
  2. If there any subscribers, execute ttRepStateSave on the active database to set the status of the standby to failed. As long as the standby database is unavailable, updates to the active database are replicated directly to the subscriber databases.

    Coomand> call ttRepStateSave('FAILED', 'ttdb2', 'ttsrv2');
    
  3. Save a copy of the standby database using ttMigrate.

    % ttMigrate -c ttdb2 ttdb2.dat
    
  4. Stop the cache agent, drop any cache groups, and destroy the standby.

    % ttAdmin –cacheStop ttdb2
    

    While connected as cache manager user, drop all cache groups:

    Command> DROP CACHE GROUP t_cg;
    

    Destroy the standby database:

    % ttDestroy ttdb2
    
  5. Rebuild the standby database. Execute the following on the standby as the instance administrator:

    % ttIsql ttdb2
    
  6. Create the cache manager user and grant the user ADMIN privileges.

    Command> CREATE USER cacheadmin IDENTIFIED BY cadminpwd;
    Command> GRANT CREATE SESSION, CACHE_MANAGER, CREATE ANY TABLE,
     DROP ANY TABLE TO cacheadmin;
    Command> GRANT ADMIN TO cacheadmin;
    

    Note:

    The cache manager user requires ADMIN privileges in order to execute ttMigrate –r. Once migration is completed, you can revoke the ADMIN privilege from this user if desired.

    For more information on ttMigrate, see "ttMigrate" in the Oracle TimesTen In-Memory Database Reference.

  7. As the cache manager user, rebuild the ttdb2 database:

    % ttMigrate -r -relaxedUpgrade -cacheuid cacheadmin -cachepwd cadminpwd 
    -connstr "dsn=ttdb2;uid=cacheadmin;pwd=cadminpwd;oraclepwd=oraclepwd" ttdb2.dat
    

    At this time:

    • All the users, cache groups, and the active standby pair have been restored to ttdb2.

    • The cache groups are in AUTOREFRESH STATE = OFF.

    • The cache agent and replication agent are not running.

  8. As the cache manager user, start the cache agent on the standby:

    % ttAdmin –cacheStart ttdb2
    
  9. Load any cache groups.

    Command> ALTER CACHE GROUP t_cg SET AUTOREFRESH STATE PAUSED;
    Command> LOAD CACHE GROUP t_cg COMMIT EVERY 256 ROWS PARALLEL <nThreads>;
    

    Note:

    • Choose nThreads based on how many CPU cores you use to insert the data into TimesTen for this load operation.

    • If there are several read-only cache groups it is recommended that you run several LOAD operations in separate sessions in parallel, if the TimesTen and Oracle Database resources are available.

  10. After completion, verify the cache group state.

    Command> cacheGroups;
    Cache Group CACHEADMIN.T_CG:
      Cache Group Type: Read Only
      Autorefresh: Yes
      Autorefresh Mode: Incremental
      Autorefresh State: On
      Autorefresh Interval: 10 Seconds
      
      Autorefresh Status: ok
      Aging: No aging defined
     
      Root Table: ORATT.T
      Table Type: Read Only
     
    1 cache group found.
    
  11. Start the replication agent on the standby database:

    % ttAdmin -repStart ttdb2
    
  12. Check the replication state on the standby:

    % ttIsql ttdb2
    Command> call ttRepStateGet;
    < STANDBY >
    1 row found.
    

The standby database (ttdb2) has been defragmented and both the active and standby databases are functional.

Reverse the active and standby roles

In order to perform the database defragmentation on the active database, switch the roles of the active and standby database. The active (ttdb1) becomes the standby database. The original standby (ttdb2) becomes the active database.

  1. Stop all application processing and disconnect all application connections with the ttAdmin -disconnect command. Any query only processing can be moved to work at the ttdb2 TimesTen database. For more information, see "Disconnecting from a database" in this book and "ttAdmin" in the Oracle TimesTen In-Memory Database Reference.

  2. Call the ttRepSubscriberWait built-in procedure at the current active database (ttdb1), with the database name and host of the current standby database (ttdb2) as input parameters. This ensures that all queued updates have been transmitted to the current standby database.

    Note:

    If you set the waitTime to -1, the call waits until all transactions that committed before the call have been transmitted to the subscriber.

    However, if you set the waitTime to any value (this value cannot be NULL), ensure that the return timeOut parameter value is 0x00 before continuing. If the returned value 0x01, call the ttRepSubscriberWait built-in procedure until all transactions that committed before the call have been transmitted to the subscriber.

    For more information about the ttRepSubscriberWait built-in procedure, see "ttRepSubscriberWait" in the Oracle TimesTen In-Memory Database Reference.

    Command> call ttRepSubscriberWait(NULL,NULL,'ttdb2','ttsrv2', 100);
    
  3. Stop the replication agent on the current active database.

    Command> call ttRepStop;
    
  4. Call the ttRepDeactivate built-in procedure on the current active database. This puts the database in the IDLE state.

    Command> call ttRepDeactivate;
    Command> call ttRepStateGet;
    < IDLE >
    1 row found.
    
  5. Promote the standby to active by calling the ttRepStateSet('ACTIVE') built-in procedure on the old standby database. This database now becomes the active database in the active standby pair. Use the ttRepStateGet built-on to verify that the database has become active.

    Command> call ttRepStateSet('ACTIVE');
    Command> call ttRepStateGet;
    < ACTIVE >
    1 row found.
    
  6. Stop the replication agent on the database that used to be the active database.

    % ttAdmin -repStop ttdb1
    
  7. Execute ttRepStateSave on the new active database to set the status of the old active database to failed. As long as the standby database is unavailable, updates to the active database are replicated directly to the subscriber databases.

    Command> call ttRepStateSave('FAILED', 'ttdb1', 'ttsrv1');
    
  8. Restart the full application workload on the new active database (ttdb2).

This database now acts as the standby database in the active standby pair.

Destroy and re-create the new standby

Destroy and recreate the new standby using ttRepAdmin -duplicate from the new active. During these steps, application processing can continue at the active database.

  1. Stop the cache agent on the new standby database:

    % ttAdmin –cacheStop ttdb1
    
  2. As the cache manager user, drop all cache groups:

    Command> DROP CACHE GROUP t_cg;
    
  3. Destroy the database:

    % ttDestroy ttdb1
    
  4. Re-create the new standby database by duplicating the new active.

    % ttRepAdmin -duplicate -from ttdb2 -host ttsrv2 –setMasterRepStart -UID 
    ttadmin -PWD ttadminpwd -keepCG -cacheUID cacheadmin -cachePWD cadminpwd ttdb1
    
  5. Start cache and replication agents on the new standby database:

    % ttAdmin –cacheStart ttdb1
    % ttAdmin –repStart ttdb1
    

This process defragments both the active and standby databases with only a few seconds of service interruption.

Online defragmentation of databases in a non active standby pair replication scheme

The following sections describe how to defragment TimesTen databases that are involved in a non active standby pair replication scheme:

Note:

These sections discuss how to defragment databases that are involved in a bidirectional replication scheme. In bidirectional replication schemes, each database is both a master and subscriber.

The examples in this section show how to perform an online defragmentation with bidirectional and unidirectional replication schemes with two TimesTen databases named ttdb1 and ttdb2. For the unidirectional replication example, ttdb1 represents the master and ttdb2 represents the subscriber.

Migrate and rebuild a database

The first step in the procedure is to stop replication on one of the TimesTen databases and then defragment this database.

Note:

While one of the databases is defragmented, application processing can continue on the other database.

Perform the following to save a copy of the TimesTen database:

  1. Stop the replication agents on one of the databases.

    On the ttdb2 database:

    % ttAdmin –repStop ttdb2
    
  2. Save a copy of the ttdb1 database using ttMigrate.

    % ttMigrate -c ttdb2 ttdb2.dat
    
  3. Destroy the database:

    % ttDestroy ttdb2
    
  4. As a TimesTen user with ADMIN privileges, rebuild the ttdb2 database:

    % ttMigrate -r -relaxedUpgrade -connstr "dsn=ttdb2;uid=ttadmin;pwd=ttadminpwd" ttdb2.dat
    

    At this time:

    • All the users have been restored to ttdb2.

    • The replication agent is not running.

  5. Restart the replication agent on ttdb2:

    % ttAdmin -repStart ttdb2
    

The ttdb2 TimesTen database has been defragmented.

Alter the replication scheme

In order to perform the database defragmentation on the ttdb1 database, perform the following:

  1. Stop all application processing and disconnect all application connections with the ttAdmin -disconnect command. Any processing can be moved to work at the ttdb2 TimesTen database. For more information, see "Disconnecting from a database" in this book and "ttAdmin" in the Oracle TimesTen In-Memory Database Reference.

  2. Call the ttRepSubscriberWait built-in procedure at the TimesTen database that has not been defragmented (ttdb1), with the database name and host of the defragmented database (ttdb2) as input parameters. This ensures that all queued updates have been transmitted to both databases.

    Note:

    If you set the waitTime to -1, the call waits until all transactions that committed before the call have been transmitted to the subscriber.

    However, if you set the waitTime to any value (this value may not be NULL), ensure that the return timeOut parameter value is 0x00 before continuing. If the returned value 0x01, call the ttRepSubscriberWait built-in procedure until all transactions that committed before the call have been transmitted to the subscriber.

    For more information about the ttRepSubscriberWait built-in procedure, see "ttRepSubscriberWait" in the Oracle TimesTen In-Memory Database Reference.

    On ttdb1:

    % ttIsql ttdb1
    
    Command> call ttRepSubscriberWait(NULL,NULL,'ttdb2','ttsrv2', 100);
    

    If you are using a bidirectional replication scheme, skip steps 3-4 and move to step 5.

  3. For a unidirectional replication scheme, where ttdb1 is the master and ttdb2 is the subscriber, drop the replication scheme on both TimesTen databases:

    On ttdb1:

    % ttIsql ttdb1
    
    Command> DROP REPLICATION r1;
    

    On ttdb2:

    % ttIsql ttdb2
    
    Command> DROP REPLICATION r1;
    
  4. For a unidirectional replication scheme, drop the replication scheme on the master (ttdb1) and subscriber (ttdb2):

    On ttdb1:

    % ttIsql ttdb1
    
    Command> DROP REPLICATION r1;
    

    On ttdb2:

    % ttIsql ttdb2
    
    Command> DROP REPLICATION r1;
    
  5. Start the replication agent on ttdb2:

    % ttAdmin -repStart ttdb2
    
  6. Stop the replication agent on ttdb1.

    % ttAdmin -repStop ttdb1
    

If you modified a unidirectional replication scheme, the ttdb2 database now acts as the master database in the unidirectional scheme; the ttdb1 database acts as the subscriber database in the unidirectional replication scheme.

Destroy and re-create a database

Destroy and recreate the TimesTen database in the replication scheme that has not yet been defragmented using ttRepAdmin -duplicate. During these steps, application processing can continue on the defragmented database.

  1. Destroy the database:

    % ttDestroy ttdb1
    
  2. Recreate the new TimesTen database (ttdb1) by duplicating the previously defragmented TimesTen database (ttdb2) involved in the replication scheme.

    % ttRepAdmin -duplicate -from ttdb2 -host ttsrv2 –setMasterRepStart -UID ttadmin -PWD ttadminpwd ttdb1
    
  3. Start the replication agent on the new standby database:

    % ttAdmin –repStart ttdb1
    

This process defragments both the TimesTen databases involves in either a unidirectional or bidirectional replication scheme with only a few seconds of service interruption.

Verifying if your database is a single-instance or distributed database

If you want to verify if you are connected to a single-instance (TimesTen Classic) database or a distributed (TimesTen Scaleout) database, call for the value of the ttGridEnable attribute with the ttConfiguration built-in procedure. The built-in procedure returns ttGridEnable=1 for distributed databases and returns ttGridEnable=0 for single instance databases.

Command> CALL ttConfiguration('ttGridEnable');
< TTGridEnable, 1 >
1 row found.
Command>

For more information on the ttConfiguration built-in procedure, see "ttConfiguration" in the Oracle TimesTen In-Memory Database Reference.