Why is MetaDefender ICAP Server unable to connect to the database?
Issue
MetaDefender ICAP Server fails to connect to the database. The following is displayed when connecting to the MetaDefender ICAP Server web console:

The following error is displayed in the mdicapsrv.log:
“[ERROR] <timestamp>:(icap.postgres) Postgres issue, error=’Could not load postgres’s information from file', param-'config file is invalid, ....”
Cause
The mdicapsrv_postgres.dat and mdicapsrv_postgres.cat files have become corrupted.
Remediation Steps
- Stop the MetaDefender ICAP Server Service
- Backup the corrupted Files
Backup the corrupted mdicapsrv_postgres.dat and mdicapsrv_postgres.cat files to a different location for future reference.
- Windows: The files are located in the ICAP Server’s installation folder.
- Linux: The files are located at:
- /usr/lib/mdicapsrv/mdicapsrv_postgres.cat /usr/lib/mdicapsrv/mdicapsrv_postgres.dat
- Remove the corrupted files "mdicapsrv_postgres.dat" and "mdicapsrv_postgres.cat" files
- Windows: Navigate to the ICAP Server’s installation folder and delete the files.
- Linux: Run the following commands:
sudo rm /usr/lib/mdicapsrv/mdicapsrv_postgres.cat
sudo rm /usr/lib/mdicapsrv/mdicapsrv_postgres.dat
- Create the Ignition File
Create an ignition file with the specified content.
- Windows: Create C:\opswat\mdicapsrv.conf
- Linux: Create /etc/opswat/mdicapsrv.conf
If you are restoring an existing database, you will need to provide the username and password credentials used previously. Please consult your internal change management documentation to get these credentials.
Add the following to the file:
[dbserver]
type=your db type, 'local' for bundle postgres, 'remote' for remote postgres.
host=ip address of remote postgres. For bundle postgres, it has to be localhost.
port=port of postgres.
user=postgres's user.
password=postgres's password.
Example of an ignition file using bundled postgres:
[dbserver]
type=local
host=localhost
port=5432
user=mypostgresuser
password=mypostgrespassword
Customers who specified an instance name during ICAP Server installation need to enter the correct value instance_name in the ignition file. If not, ICAP Server will initiate a new database with the default instance name.
Example:
[dbserver]
type=local
host=localhost
port=5432
user=mypostgresuser
password=mypostgrespassword
instance_name=myinstancename
If customers have configured a private user for their database and want to reuse this private user, they need to ensure that correct private_username and private_password are set in the ignition file.
Example
[dbserver]
type=local
host=localhost
port=5432
user=mypostgresuser
password=mypostgrespassword
private_username=myprivateusername
private_password=myprivatepassword
- Re-generate mdicapsrv_postgres.cat and mdicapsrv_postgres.dat
Windows
- Open Command Prompt as Administrator
- Navigate to the MetaDefender ICAP Server’s installation folder.
- Run the following command:
mdicapsrv-upgrade-db.exe
Linux
Export:
LD_LIBRARY_PATH=/usr/lib/mdicapsrv:$LD_LIBRARY_PATH
Run the upgrade database tool using:
sudo /usr/sbin/mdicapsrv-upgrade-db
Change the owner and set permissions for the newly generated mdicapsrv_postgres.cat and mdicapsrv_postgres.dat files:
sudo chown metascan:metascan /usr/lib/mdicapsrv/mdicapsrv_postgres.cat
sudo chown metascan:metascan /usr/lib/mdicapsrv/mdicapsrv_postgres.dat
sudo chmod 777 /usr/lib/mdicapsrv/mdicapsrv_postgres.cat
sudo chmod 777 /usr/lib/mdicapsrv/mdicapsrv_postgres.dat
- Start MetaDefender ICAP Server Service
Conclusion
Following these steps should resolve the issue of MetaDefender ICAP Server failing to connect to the database due to configuration files corruption. If the problems persist, please contact OPSWAT support for further assistance.