Postfix MySQL Configuration – Troubleshooting Postfix Configuration for MySQL

postfix

I've had this server in use for something like a week. Fresh Ubuntu 20.04 install, packages all installed through apt. I could receive and send mail outside of my IP just fine. Suddenly, receiving e-mail was not longer possible.

I checked the logs and soon noticed the error: unsupported dictionary type: mysql message, which meant that postfix was unable to check the recipient against my database. I checked my apt list --installed output, but postfix-mysql was installed, so that wasn't the problem. I soon discovered I needed to add the line:
mysql /usr/lib/postfix/postfix-mysql.so.1.0.1 dict_mysql_open
to /etc/postfix/dynamicmaps.cf and do a postfix reload.

My question is: how could this happen? I do have an apt update && apt upgrade cron running that auto-updates the server.

Update

The last update I saw was this one:

2021-09-28 23:01:31 upgrade postfix:amd64 3.4.13-0ubuntu1.1 3.4.13-0ubuntu1.2
The problems started right after that. dynamicmaps.cf was empty except for the commented instruction-line at the top. I added the mysql-line, and now that is the only functional line in the file.

Update 2

After killing all the processes found with ps -Af | grep -E 'dpkg|debconf|apt|unatt' I ran:

sudo apt update
sudo apt-get install --fix-broken
sudo dpkg --configure -a -D223

Which gave me the following error when trying to configure postfix:

D000001: process queue pkg postfix-mysql:amd64 queue.len 54 progress 1, try 1
dpkg: dependency problems prevent configuration of postfix-mysql:
 postfix-mysql depends on postfix (= 3.4.13-0ubuntu1.2); however:
  Package postfix is not installed.

dpkg: error processing package postfix-mysql (--configure):
 dependency problems - leaving unconfigured

I don't know enough about dpkg to understand this. What's happening here?

Update 3

dpkg-query --show --showformat='${package} ${status}\n' 'postfix*'
yields:

postfix install ok installed                                                                                            postfix-cdb unknown ok not-installed
postfix-doc unknown ok not-installed
postfix-ldap unknown ok not-installed
postfix-lmdb unknown ok not-installed
postfix-mysql install ok installed
postfix-pcre unknown ok not-installed
postfix-pgsql unknown ok not-installed
postfix-sqlite unknown ok not-installed

So both requested packages are in an OK and installed status. The apt command did not suggest a fix as far as I saw (and I read the output carefully). It seems your suggestions worked.

What I don't like is not knowing what I'm doing, but that is due to my own apt and dpkg lack of knowledge.

Best Answer

Every time you upgrade a postfix map package, it will first remove its respective map type from /etc/postfix/dynamicmaps.cf and only in a later add it (back). You can manually see that this works by forcing a reconfiguration via dpkg-reconfigure postfix-mysql. If the file was left empty after the upgrade, that likely means the upgrade was interrupted - or is even still hanging, waiting for user input that never came.

If you are applying all SRU, then you will have upgraded Postfix to 3.4.13-0ubuntu1.2 for Ubuntu 20.04. I recommend you confirm that no upgrades are currently being applied:

ps -Af | grep -E 'dpkg|debconf|apt|unatt'
dpkg-query --show --showformat='${package} ${status}\n' 'postfix*'

Your cron job has is flawed in that it fails to tell apt that this is a non-interactive invocation, this may be the reason it is hanging.

If necessary, ensure all packages are properly installed. During this steps, you will likely see warnings or questions that help determine why your cron job failed.

sudo apt update
sudo apt-get install --fix-broken
sudo dpkg --configure -a -D223

Don't forget to remove the offending cron job as setup something reliable. The program unattended-upgrade is usually the preferred method of applying upgrades on Ubuntu systems when no admin is standing by. It will skip over or use defaults for things apt would otherwise ask for interactively.

Related Topic