Fixing “postfix aliases db: No such file or directory” Error in Ubuntu Mail Server Setup


14 views

When setting up Postfix on Ubuntu 12.04 with ZoneMinder integration, many administrators encounter this specific error in mail logs:

warning: hash:/etc/aliases is unavailable. open database /etc/aliases.db: No such file or directory

This occurs when Postfix attempts to access the aliases database but finds either:

  • The compiled aliases database (/etc/aliases.db) is missing
  • Or the system hasn't properly initialized the alias mappings

The solution involves rebuilding the aliases database. Execute these commands:

sudo nano /etc/aliases  # Verify your alias mappings
sudo newaliases        # Rebuild the database
sudo service postfix restart

Ensure your /etc/aliases contains at minimum these critical entries:

# Basic system aliases
mailer-daemon: postmaster
postmaster: root
root: your-real-email@domain.com

# ZoneMinder specific
zmpkg: root
zmfilter: root
zmaudit: root

For persistent issues, check these configuration elements:

# Verify Postfix alias configuration
postconf alias_maps
postconf alias_database

# Expected output should include:
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases

If permissions are suspect, run:

sudo chmod 644 /etc/aliases
sudo chmod 644 /etc/aliases.db
sudo chown root:root /etc/aliases*
sudo postfix check

In /etc/zm/zm.conf, ensure email settings are properly configured:

ZM_EMAIL_ADDRESS=your-email@domain.com
ZM_EMAIL_SUBJECT="ZoneMinder Alarm Notification"
ZM_EMAIL_BODY="Motion detected in zone %zonename%"

Verify the fix works by sending a test email through ZoneMinder's notification system and checking mail logs:

tail -f /var/log/mail.log

You should see successful delivery messages instead of database errors.


When working with Postfix on Ubuntu, you might encounter the frustrating error:

warning: hash:/etc/aliases is unavailable. open database /etc/aliases.db: No such file or directory

This occurs because Postfix can't find the compiled alias database, even though your main.cf configuration looks correct.

Postfix uses two key files for mail aliases:

  • /etc/aliases - The human-readable text file containing alias definitions
  • /etc/aliases.db - The compiled database version that Postfix actually uses

The error suggests the second file is missing or inaccessible.

Here's how to properly create the database:

sudo newaliases

Or alternatively:

sudo postalias /etc/aliases

After creating the database, check permissions:

ls -l /etc/aliases*

You should see something like:

-rw-r--r-- 1 root root 123 Apr 16 12:34 /etc/aliases
-rw-r--r-- 1 root root 4096 Apr 16 12:35 /etc/aliases.db

Ensure your main.cf contains these critical lines:

alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases

If the issue persists, try these diagnostic commands:

sudo postfix check
sudo postfix set-permissions
sudo postconf alias_maps alias_database

For production systems, consider adding this to your Postfix installation script:

# Ensure alias database exists
if [ ! -f /etc/aliases.db ]; then
    sudo newaliases
fi
# Verify permissions
sudo chmod 644 /etc/aliases.db
sudo chown root:root /etc/aliases.db

After applying changes, test with:

echo "Test message" | mail -s "Test" root
postqueue -p

You should no longer see the "alias database unavailable" error in your mail logs.