1. Knowledge Base
  2. SecurityGateway™ for Email Servers

How to use the gfix utility in SecurityGateway to validate data and fix database corruption

SecurityGateway uses a database management system called Firebird to store configuration settings and server data. Under certain circumstances, you may be advised by support to check your SecurityGateway database file for corruption.

This may occur if you have problems backing up the database, if SecurityGateway is experiencing crashing issues, or if errors are being written to the logs that indicate corruption. In order to check for and possibly fix corruption in your SecurityGateway database, you can use a Firebird utility called gfix, which is included in the SecurityGateway installation. 

It's important to note that there are multiple instances of gfix included with SecurityGateway that reflect the number of Firebird database instances available.  SecurityGateway versions 7.0 and below operate using version 2 of the Firebird database and are available in both 32-bit and 64-bit options.  Default SecurityGateway 8.5.0 and above installations use version 3 of the Firebird database and is only available in the 64-bit architecture.  

Future upgrades to SecurityGateway may include updated versions to Firebird.

In the directory where SecurityGateway is installed, you'll notice the 4 following folders.

  • Firebird_x64 (Firebird 2, 64-bit)
  • Firebird_x86 (Firebird 2, 32-bit)
  • Firebird3_x64 (Firebird 3, 64-bit)
  • Firebird3_x86 (Firebird 3, 32-bit)

Each folder has its own instance of gfix that must be used with the Firebird database version and bit version of SecurityGateway.

  • New installations of Security Gateway versions 7.0 and above run Firebird 3.
  • New installations of Security Gateway versions 8.5 and above are 64-bit only.
  • Security Gateway versions prior to 7.0 are not upgraded to Firebird 3.0 and must be upgraded manually.  See the article below to perform the upgrade.
    How to upgrade the SecurityGateway Firebird database to version 3
  • If the gfix utility for Firebird 2.0 is ran against a Firebird 3 database version, the following will be printed.
    • unsupported on-disk structure for file C:\PROGRAM FILES/MDAEMON TECHNOLOGIES\SECURITYGATEWAY\APP\SECURITYGATEWAY.FBD; found 12.0, support 11

In this article, the Firebird 3, 64-bit version is used.

If you have a good backup of the SecurityGateway database, we would recommend restoring the database from that backup, as the process below can result in losing data that is corrupted. If restoring from a backup is not possible however, attempting to fix the database using gfix is an option.

Follow the steps below to determine if corruption has occurred:

  1. Stop the SecurityGateway service
  2. Make a manual backup of the SecurityGateway database file - securitygateway.fbd
    1. Navigate to the \SecurityGateway\App directory.
      • The default path is C:\Program Files\MDaemon Technologies\SecurityGateway\App
    2. Copy the securitygateway.fbd file to another location through Windows Explorer.
  3. Open a command prompt
    1. Click Start
    2. Click Run
    3. Type cmd
    4. Press Enter
  4. Change to the SecurityGateway directory
    1. Type cd C:\Program Files\MDaemon Technologies\SecurityGateway\Firebird3_x64
      • or the correct path for your environment, if you've installed to a different location
    2. Press Enter
  5. Type gfix -user SYSDBA -password masterkey -validate -full -no_update "C:\Program Files\MDaemon Technologies\SecurityGateway\App\securitygateway.fbd"
    • If you've installed to a different location, modify the path above to the securitygateway.fbd file.
  6. Press Enter

If the command returns no output, then the database structures are good. If you receive errors, however, you will need to repair the database.

Follow the steps below to repair the database:

  1. If you have not yet done so, make a backup of the securitygateway.fbd database file.
  2. Return to the command prompt window and the C:\Program Files\MDaemon Technologies\SecurityGateway\Firebird3_x64 directory.
  3. Type gfix -user SYSDBA -password masterkey -mend -full -ignore "C:\Program Files\MDaemon Technologies\SecurityGateway\App\securitygateway.fbd"
  4. Press Enter
At this point, corrupted data records will be flagged. Performing a full database backup will backup the entire database with the flagged records excluded from the backup.