6.5. Stopping and Restarting a VoltDB Database

Documentation

VoltDB Home » Documentation » Using VoltDB

6.5. Stopping and Restarting a VoltDB Database

Because VoltDB is an in-memory database, once the database server process stops, the data itself is removed from memory. If you restart the database without taking any other action, the database starts fresh without any data. However, in many cases you want to retain the data across sessions. There are two ways to do this:

  • Save and restore database snapshots

  • Use command logging and recovery to reload the database automatically

6.5.1. Save and Restore

A database snapshot is exactly what it sounds like — a point-in-time copy the database contents written to disk. You can later use the snapshot to restore the data.

To save and restore data across sessions, you can perform a snapshot before shutting down the database and then restore the snapshot after the database restarts. You can perform a manual snapshot using the voltadmin command or using the @SnapshotSave system procedure. For example, the following commands pause the database, perform a manual snapshot, then do a shutdown on the current system:

$ voltadmin pause
$ voltadmin save 'voltdbroot/snapshots' 'MySnapshot'
$ voltdbadmin shutdown

You can also have the database automatically create periodic snapshots using the snapshot feature in the deployment file. See Chapter 9, Saving & Restoring a VoltDB Database for more information about using snapshots to save and restore the database.

6.5.2. Command Logging and Recovery

Another option for saving data across sessions is to use command logging and recovery. When command logging is enabled (which it is by default in VoltDB Enterprise Edition), the database not only performs periodic snapshots, it also keeps a log of all stored procedures that are initiated at each partition. If the database stops for any reason — either intentionally or due to system failure — when the server process restarts, the database restores the last snapshot and then "replays" the command log to recover all of the data committed prior to the cluster shutting down.

To support command logging, an alternative startup action is available on the command line when starting the server process. The valid startup actions are:

  • create — explicitly creates a new, empty database and ignores any command log information, if it exists.

  • recover — starts a new database process and recovers the command log from the last database session. The recover action is explicit; if the command log content is not found or is incomplete, the server initialization process stops and reports an error.

Even if you are not using command logging, you can still use the create and recover actions with automated snapshots. During the recover action, VoltDB attempts to restore the last snapshot found in the snapshot paths. Therefore, using automated snapshots and the recover action, it is possible to automatically recover all of the data from the previous database session up until the last snapshot.

The following example illustrates how to recover a database from a previous session.

$ voltdb recover --host=voltsvr1 \
     --deployment=deployment.xml \
     --license=/opt/voltdb/voltdb/license.xml

The advantages of command logging and recovery are that:

  • The command log ensures that all data is recovered, including transactions between snapshots.

  • The recovery is automated, ensuring no client activity occurs until the recovery is complete.

See Chapter 10, Command Logging and Recovery for more information about configuring command logging.