external files can only be stored using the data portion of a key/data pair. They are supported only for Btree, Hash, and Heap databases, and only so long as the database is not configured for duplicate records, or duplicate sorted records. In addition, the DBT that you use to access the external file data cannot be configured as a partial DBT if you want to access the data using the external file’s streaming interface (introduced below).

    Note that if the environment is transactionally-protected, then all access to the external file is also transactionally protected.

    The external file threshold is a positive integer, in bytes, which indicates how large an object must be before it is considered an external file. By default, the external file threshold for any given database is , which means that no object will ever be considered an external file. This means that the external file feature is not used by default for Berkeley DB databases.

    In order to use the external file feature, you must set the external file threshold to a non-zero, positive integer value. You do this for a given database using the method. Note that this value must be set before you create the database. At any point after database creation time, this method is ignored.

    You can retrieve the external file threshold set for a database using the DB->get_blob_threshold(). You can retrieve the default external file threshold set for your environment using the .

    There are two ways to create an external file. Before you can use either mechanism, you must set the external file threshold to a non-zero positive integer value (see the previous section for details). Once the external file threshold has been set, you create an external file using one of the two following mechanisms:

    • Alternatively, creating a data item with a size greater than the external file threshold will cause that data item to be automatically stored as an external file.

    The following example code fragment can be found in your DB distribution at .

    external files are not stored in the normal database files on disk in the same way as is other data managed by DB. Instead, they are stored as binary files in a special directory set aside for the purpose.

    If you are not using environments, this special external file directory is created relative to the current working directory from which your application is running. You can modify this default location using the DB->set_blob_dir() method, and retrieve the current external file directory using .

    If you are using an environment, then by default the external file directory is created within the environment’s home directory. You can change this default location using DB_ENV->set_blob_dir() and retrieve the current default location using . (Note that DB_ENV->get_blob_dir() can successfully retrieve the external file directory only if was previously called.)

    Replication supports external files without any special requirements. However, enabling external files in a replicated environment can result in long synchronization times between the client and master sites. To avoid this, execute a transaction checkpoint after updating or deleting one or more external file records.