# Maintaining database integrity

One of the most important responsibilities of a database administrator is to maintain the integrity of the database and prevent it from becoming corrupted.

Derby must be able to sync to disk. Some machine, disk, or operating system settings can prevent a proper sync and cause unrecoverable database corruption in the event of a power failure, system crash, or software crash. To avoid database corruption, you can do the following:

- Do not touch any files or directories in the database directory, including the `log` and `seg0` directories and the `service.properties` file. Editing, adding, or deleting files in this directory may cause data corruption and leave the database in a non-recoverable state.
- Do not enable disk write caching on the hard drive that holds the database. Disable write caching if it is turned on (it is enabled by default on many Windows systems). Disk write caching can increase operating system performance. However, it can also result in the loss of information if a power failure, equipment failure, or software failure occurs. Consult your operating system support documentation for information on how to disable disk write caching.
- Run Derby on a local drive rather than on an NFS mounted, SMB mounted, or other network mounted disk.
- Disable any other settings or options that might prevent a proper sync to disk when Derby is writing its transaction logs or other data.

Many corruption issues can arise from improper backups or restores. Back up your database in a way that prevents it from becoming corrupted:

- Always make sure the database is shut down or frozen before using operating system commands to back it up.
- Always back up the database to a fresh location rather than overwriting any existing data.

After you perform a backup, check the consistency of the database. See Checking database consistency for details.

See Backing up and restoring databases for more information.

Parent topic: Part Two: Derby Administration Guide
Related concepts
Checking database consistency
Backing up and restoring databases
Importing and exporting data
Replicating databases
Logging on a separate device
Obtaining locking information
Reclaiming unused space