How to Fix Postfix Error: “open database /etc/postfix/generic.db: No such file or directory”


2 views

When working with Postfix mail servers, encountering database-related errors is common during service startup. The specific error:

error: open database /etc/postfix/generic.db: No such file or directory

indicates that Postfix is trying to access a lookup table that either doesn't exist or hasn't been properly compiled from its text source.

The error occurs because:

smtp_generic_maps = hash:/etc/postfix/generic

is configured in postfix, but the compiled database file (/etc/postfix/generic.db) is missing. Postfix requires certain map files to be compiled into Berkeley DB format for efficient lookup.

First check your current Postfix configuration with:

postconf -n | grep generic

This should return the smtp_generic_maps parameter showing the path to your generic map file.

To resolve this issue, you need to compile the text map file into the required database format:

postmap /etc/postfix/generic

This command creates the required generic.db file. After running this, restart Postfix:

systemctl restart postfix

If your generic file doesn't exist, create it with your address mappings:

# Example /etc/postfix/generic file
user@example.com    actualuser@realdomain.com
@olddomain.com      @newdomain.com

Then compile it with postmap as shown above.

If you still encounter problems, check these logs:

tail -f /var/log/maillog
journalctl -u postfix -f

Common related issues include incorrect file permissions. Ensure:

chmod 640 /etc/postfix/generic*
chown root:postfix /etc/postfix/generic*

For production systems, consider adding a post-install script to handle map compilation automatically:

#!/bin/bash
for map in generic virtual aliases; do
    if [ -f "/etc/postfix/${map}" ]; then
        postmap "/etc/postfix/${map}"
    fi
done
systemctl reload postfix

When working with Postfix mail servers on Linux systems, you might encounter database-related errors during startup or in mail logs. A common one looks like this:

postfix: error: open database /etc/postfix/generic.db: No such file or directory

Accompanied by other warning messages in /var/log/maillog:

Jan 13 22:43:46 CentOS-72-64-minimal postfix/master[1651]: warning: process /usr/libexec/postfix/smtp pid 1297 exit status 1
Jan 13 22:43:46 CentOS-72-64-minimal postfix/master[1651]: warning: /usr/libexec/postfix/smtp: bad command startup -- throttling
Jan 13 22:43:47 CentOS-72-64-minimal postfix/qmgr[1653]: warning: private/smtp socket: malformed response
Jan 13 22:43:47 CentOS-72-64-minimal postfix/qmgr[1653]: warning: transport smtp failure

The root cause is typically one of these scenarios:

  • The Postfix configuration references a database file (.db) that hasn't been created yet
  • The database file exists but Postfix can't read it due to permissions
  • The source file (text file) for the database is missing

In our case, the postconf -n output shows:

smtp_generic_maps = hash:/etc/postfix/generic

This means Postfix is configured to use /etc/postfix/generic.db but the file doesn't exist.

The solution is to create the database file from its text source. For most Postfix map types (hash, btree, etc.), you use the postmap command:

sudo postmap /etc/postfix/generic

This creates generic.db from generic. If the source file doesn't exist yet, create it first with your mappings.

Here's how to properly set up a generic map:

# Create or edit the source file
sudo nano /etc/postfix/generic

# Add your mappings (example)
user@example.com        noreply@example.com
@olddomain.com          @newdomain.com

# Generate the database
sudo postmap /etc/postfix/generic

# Set proper permissions
sudo chmod 640 /etc/postfix/generic*
sudo chown root:postfix /etc/postfix/generic*

# Reload Postfix
sudo systemctl reload postfix

After implementing the solution, check your mail logs for errors:

sudo tail -f /var/log/maillog

And verify Postfix can access the database:

postmap -q user@example.com hash:/etc/postfix/generic

When making Postfix configuration changes:

  • Always run postmap after editing map source files
  • Check permissions (root:postfix, 640)
  • Consider adding a post-install script if you package your config
  • Test changes with postfix check before reloading