Administering Log Files
Prev | Chapter 3. Configuring the Berkeley DB SQL interface | Next

## Administering Log Files

Your environment directory contains log files. Berkeley DB log files are used to record all the transactional activity performed against the Berkeley DB database files. This information is used after an application or system failure to automatically restore the database to an up-to-date consistent point.

Your log files are maintained by Berkeley DB's logging subsystem. There are some aspects of the Berkeley DB logging subsystem that you can configure using `DB_CONFIG` parameters, and (sometimes) by using PRAGMAs.

### Note

For most users of the BDB SQL interface, there should not normally be any reason to manage your log files or otherwise worry about them. However, it is important to realize that they can not simply be deleted. Note that when using the Berkeley DB SQL interface, your log files will be automatically deleted by Berkeley DB when they are no longer needed.

The things you can manage for your logging subsystem are:

- Size of the log files. See Setting the Log File Size.

- Size of the logging subsystem's region. See Configuring the Logging Region Size.

- Size of the log buffer in memory. Setting the In-Memory Log Buffer Size.

### Setting the Log File Size

Whenever a pre-defined amount of data is written to a log file (10 MB by default), the BDB SQL interface stops using the current log file and starts writing to a new file. You can change the maximum amount of data contained in each log file by using either `PRAGMA journal_size_limit` or the `set_lg_max` DB_CONFIG file parameter.

If you use `PRAGMA journal_size_limit`, then using this PRAGMA with no value simply returns the current journal size limit. Using:

    PRAGMA journal_size_limit=N

sets the log size to N bytes. If the PRAGMA is successful, N is returned. If it fails, the previous log file size is returned. Failures can occur if you specify a log file size that is less than 4K bytes, or if you specify a log file size larger than the permitted file size on the system.

If you use the DB_CONFIG file to manage this value, `set_lg_max` may be changed without re-creating the environment. You will, however, have to restart your application in order for the DB_CONFIG file to be re-read.

The DB_CONFIG file is described in The DB_CONFIG File. The `set_lg_max` parameter is described in the Berkeley DB C API .

For a description of how, when and why you should change the size of your log files, see the Selecting a page size section in the Berkeley DB Programmer's Reference Guide.

### Configuring the Logging Region Size

The logging subsystem's default region size is 512 KB. The logging region is used to store database and table names, and so you may need to increase its size if you will be using a large number of tables.

You can set the size of your logging region by using the `set_lg_regionmax` DB_CONFIG parameter. Note that to manage this value you must set it before you create your environment, or you must re-create your environment. See The DB_CONFIG File for more information.

The `set_lg_regionmax` parameter is described in the Berkeley DB C API .

### Setting the In-Memory Log Buffer Size

When using named (persistent) databases, log information is stored in-memory until the storage space fills up, or a transaction commit forces the log information to be flushed to disk.

It is possible to increase the amount of memory available to your file log buffer. Doing so improves throughput for long-running transactions, or for transactions that produce a large amount of data. Note that for named (persistent) databases, the default log buffer space is 32 KB.

You can increase your log buffer space by using the `set_lg_bsize` DB_CONFIG parameter. For the BDB SQL interface, when the logging subsystem is configured for on-disk logging, the default size of the in-memory log buffer is approximately 64KB. Note that this method can only be called before the environment is first opened, so you will have to set this by creating your `-journal` directory, and then creating your database. See The DB_CONFIG File for more information.

The `set_lg_bsize` parameter is described in the Berkeley DB C API .

### Note

When working with in-memory databases, the environment is configured to perform logging in-memory. The log buffer is set to 64 * 1024, and the maximum log size is set to 32 * 1024.

Prev | Up | Next
Configuring the In-Memory Cache | Home | Managing the Locking Subsystem