Detaching, Attaching, and Freeing the Shared Memory Segment
With the enduring RAM policy, you can detach from the shared memory segment leaving the shared memory segment in memory. And when you are ready to open the database, you can attach to this same shared memory segment.
Note:
This should only be used when performing a fast upgrade. See About Performing a Fast Patch Upgrade in the Oracle TimesTen In-Memory Database Installation, Migration, and Upgrade Guide.
Attaching and detaching a shared memory segment is significantly faster than loading and unloading a database. When you unload the database, it destroys the shared memory segment. When you load the database, it creates a new shared memory segment and loads from the checkpoint files. If you specify the RAM policy of enduring, you can attach, detach, and free the shared memory segment. When you detach, the shared memory segment still exists and can be reused when you attach to it.
Use the following ttAdmin commands to attach to, detach from, and free the shared memory segment. You can only use these features if the RAM policy is set to enduring.
-
ttAdmin –shmDetach [-ckpt | -noCkpt]
: Detaches the shared memory segment and stops the managing subdaemon. The shared memory segment remains in memory after the subdaemon exits.Prior to disconnecting from the shared memory segment, you can specify whether the subdaemon performs a static checkpoint or not. By default, a final checkpoint is performed with the
–ckpt
option. This final checkpoint ensures that a database start will not need to go through a recovery process. If you specify the–noCkpt
option, then you avoid the final checkpoint and increase the performance of the detach and attach processes. However, if the database cannot attach to the previously detached shared memory segment and needs to be loaded from the checkpoint files, then not performing this checkpoint necessitates going through the recovery process during the load to avoid data loss. -
ttAdmin –shmAttach
: Attaches to an existing shared memory segment that was successfully detached with attAdmin –shmDetach
operation. Creates a subdaemon to manage this shared memory segment for the database. -
ttAdmin –shmFree
: Explicitly destroys a shared memory segment that remains in memory. You can free a shared memory segment after a successful detach, after an unsuccessful detach, or after a database crash. If an unsuccessful detach operation or a database crash occurs, the shared memory segment needs to be freed before you can recover the database. To reload and recover the database, run thettAdmin –ramLoad
command, which uses the checkpoint files to recover.
The following examples demonstrates how to use ttAdmin
-shmDetach
to detach a shared memory segment so that it can remain in
memory. Then, uses the ttAdmin –shmAttach
command to attach to the
existing shared memory segment.
-
Close database1 before detaching the shared memory segment with the
ttAdmin -shmDetach
command:$ ttAdmin -close database1 RAM Residence Policy : enduring Manually Loaded In RAM : True Replication Agent Policy : manual Replication Manually Started : False Cache Agent Policy : manual Cache Agent Manually Started : False Database State : Closed
-
Detach the shared memory segment and shutdown the managing subdaemon for database1. You can see that the shared memory segment is detached as the "Manually loaded in RAM" output displays as False. The
ttStatus
utility states that the subdaemon is detached from the database.$ ttAdmin -shmDetach database1 RAM Residence Policy : enduring Manually Loaded In RAM : False Replication Agent Policy : manual Replication Manually Started : False Cache Agent Policy : manual Cache Agent Manually Started : False Database State : Closed $ ttStatus TimesTen status report as of Wed Aug 18 01:45:55 2021 Daemon pid 27561 port 6626 instance instance1 TimesTen server pid 27568 started on port 6628 ------------------------------------------------------------------------ ------------------------------------------------------------------------ Data store /tmp/databases/database1 Daemon pid 27561 port 6626 instance instance1 TimesTen server pid 27568 started on port 6628 There are no connections to the data store … Closed to user connections RAM residence policy: Enduring Subdaemon is manually detached from data store (Shared Memory Key 0x07108a02 ID 745504801) Replication policy : Manual Cache Agent policy : Manual PL/SQL enabled. ------------------------------------------------------------------------ Accessible by group g900 End of report
-
When ready, run the
ttAdmin –shmAttach
command to create the managing subdaemon, start the managing subdaemon for the database1 database and attach to the shared memory segment. TheManually loaded in RAM
output displays as True to denote that the shared segment is reattached. ThettStatus
utility shows that the database is loaded into RAM.$ ttAdmin -shmAttach database1 RAM Residence Policy : enduring Manually Loaded In RAM : True Replication Agent Policy : manual Replication Manually Started : False Cache Agent Policy : manual Cache Agent Manually Started : False Database State : Closed $ ttStatus TimesTen status report as of Wed Aug 18 01:46:08 2021 Daemon pid 27561 port 6626 instance instance1 TimesTen server pid 27568 started on port 6628 ------------------------------------------------------------------------ ------------------------------------------------------------------------ Data store /tmp/databases/ database1 Daemon pid 27561 port 6626 instance instance1 TimesTen server pid 27568 started on port 6628 There are 12 connections to the data store … Closed to user connections RAM residence policy: Enduring Data store is manually loaded into RAM Replication policy : Manual Cache Agent policy : Manual PL/SQL enabled. ------------------------------------------------------------------------ Accessible by group g900 End of report
-
Open the database.
$ ttAdmin -open sampledb RAM Residence Policy : enduring 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
Note:
Being able to detach and attach to the shared memory segment provides a method for a faster upgrade. See Upgrades in TimesTen Classic in the Oracle TimesTen In-Memory Database Installation, Migration, and Upgrade Guide.
If there is a failure (such as a subdaemon crash or an assertion failure) that causes an abrupt shutdown of the database, then the shared memory segment may not be transactionally consistent and needs to be destroyed before you can reload the database and create a new shared memory segment.
The following example frees the shared memory segment with the
ttAdmin –shmFree
command. After which, the example executes the
ttAdmin –ramLoad
to recover the database from the checkpoint files
and creates a new shared memory segment.
-
Free the shared memory segment after a database crash.
$ ttAdmin -shmFree database1 RAM Residence Policy : enduring Manually Loaded In RAM : False Replication Agent Policy : manual Replication Manually Started : False Cache Agent Policy : manual Cache Agent Manually Started : False Database State : Closed $ ttStatus TimesTen status report as of Wed Aug 18 02:12:27 2021 Daemon pid 6168 port 6626 instance instance1 TimesTen server pid 6175 started on port 6628 ------------------------------------------------------------------------ ------------------------------------------------------------------------ Data store /tmp/databases/database1 Daemon pid 27561 port 6626 instance instance1 TimesTen server pid 27568 started on port 6628 There are no connections to the data store Closed to user connections RAM residence policy: Enduring Data store is manually unloaded from RAM Replication policy : Manual Cache Agent policy : Manual PL/SQL enabled. ------------------------------------------------------------------------ Accessible by group g900 End of report
-
Load and open the
database1
database with a new shared memory segment that recovers from the checkpoint files:$ ttAdmin -ramLoad -open database1 RAM Residence Policy : enduring 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