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 Oracle TimesTen In-Memory Database Scaleout User's Guide.

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.

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 terminates 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 options. 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 option 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 this operation abruptly causes every user and ttcserver process connected to the database to terminate.

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.

For example, the following script disconnects all connections and unloads the TimesTen Classic database by first running 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
...