# Db.upgrade

`

###

    import com.sleepycat.db.*;

    public void upgrade(String file, int flags)
    	throws DbException;

# Description

The Db.upgrade method upgrades all of the databases included in the file file, if necessary. If no upgrade is necessary, Db.upgrade always returns success.

Database upgrades are done in place and are destructive, e.g., if pages need to be allocated and no disk space is available, the database may be left corrupted. Backups should be made before databases are upgraded. See Upgrading databases for more information.

Unlike all other database operations, Db.upgrade may only be done on a system with the same byte-order as the database.

The flags parameter must be set to 0 or one of the following values:

Db.DB_DUPSORT
  This flag is only meaningful when upgrading databases from releases before the Berkeley DB 3.1 release.

  As part of the upgrade from the Berkeley DB 3.0 release to the 3.1 release, the on-disk format of duplicate data items changed. To correctly upgrade the format requires applications specify if duplicate data items in the database are sorted or not. Specifying the Db.DB_DUPSORT flag informs Db.upgrade that the duplicates are sorted, otherwise they are assumed to be unsorted. Incorrectly specifying the value of this flag may lead to database corruption.

  Further, because the Db.upgrade method upgrades a physical file (including all of the databases it contains), it is not possible to use Db.upgrade to upgrade files where some of the databases it includes have sorted duplicate data items and some of the databases it includes have unsorted duplicate data items. If the file does not have more than a single database, or the databases do not support duplicate data items, or all of the databases that support duplicate data items support the same style of duplicates (either sorted or unsorted), Db.upgrade will work correctly as long as the Db.DB_DUPSORT flag is correctly specified. Otherwise, the file cannot be upgraded using Db.upgrade, and must be upgraded manually by dumping and re-loading the databases.

The Db.upgrade method throws an exception that encapsulates a non-zero error value on failure.

# Environment Variables

DB_HOME
  If the dbenv argument to db_create was initialized using DbEnv.open the environment variable DB_HOME may be used as the path of the database environment home. Specifically, Db.upgrade is affected by the configuration value DB_DATA_DIR.

# Errors

The Db.upgrade method may fail and throw an exception encapsulating a non-zero error for the following conditions:

EINVAL
  An invalid flag value or parameter was specified.

  The database is not in the same byte-order as the system.

Db.DB_OLD_VERSION
  The database cannot be upgraded by this version of the Berkeley DB software.

The Db.upgrade method may fail and throw an exception for errors specified for other Berkeley DB and C library or system methods. If a catastrophic error has occurred, the Db.upgrade method may fail and throw a DbRunRecoveryException, in which case all subsequent Berkeley DB calls will fail in the same way.

### Class

Db

# See Also

Db.close, Db.cursor, Db.del, Db.fd, Db.get, Db.get_byteswapped, Db.get_type, Db.join, Db.key_range, Db.open, Db.put, Db.remove, Db.set_bt_minkey, Db.set_cachesize, Db.set_errcall, Db.set_errpfx, Db.set_flags, Db.set_h_ffactor, Db.set_h_nelem, Db.set_lorder, Db.set_pagesize, Db.set_q_extentsize, Db.set_re_delim, Db.set_re_len, Db.set_re_pad, Db.set_re_source, Db.stat, Db.sync, Db.upgrade and Db.verify.`

Copyright Sleepycat Software