Loading and Unloading the Database from Memory

TimesTen is an in-memory database. As such, a database must first be loaded into memory from the file system 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 the file system. The temporary memory region is created when a database is loaded into memory and is destroyed when it is unloaded. See Specifying the Memory Region Sizes 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.

    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.

Note:

Instead of loading and unloading the database, you can detach or attach the shared memory segment leaving the shared memory segment in memory. This is significantly faster than loading and unloading a database. See Detaching, Attaching, and Freeing the Shared Memory Segment.

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

Loading a Database into Memory for TimesTen Classic

Loading the database into memory for TimesTen Classic can be done automatically when a certain ram policy is set or manually with the ttAdmin utility.

  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.

    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 or enduring RAM policies:

    % 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 the replication agent:

    ttAdmin -repStart database1

    To start the cache agent:

    ttAdmin -cacheStart database1

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 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. 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.

    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.

  7. Optionally, stop the TimesTen daemon.
    ttDaemonAdmin -stop

See ttAdmin in the Oracle TimesTen In-Memory Database Reference.