TIP: Make Postfix use less SQL connections

When you manage Postfix mail servers using SQL connections to find informations about usernames, mailbox/maildir locations on the disk you probably have in your main.cf something like :

virtual_alias_maps = mysql:/etc/postfix/mysql_virtual_alias_maps.cf
virtual_mailbox_domains = mysql:/etc/postfix/mysql_virtual_domains_maps.cf
virtual_mailbox_maps = mysql:/etc/postfix/mysql_virtual_mailbox_maps.cf
relay_domains = mysql:/etc/postfix/mysql_relay_domains_maps.cf

But, this way, each process(postfix process) uses one MySQL connection. Each mail that relays thru your server will open and close a MySQL connection. This is probably working on a simple mail server that handles 3 domain names and around 15 normal mailboxes, but when you have thousands of mail per hour that pass thru your mail server this could mean lots and lots of useless load to your server.

A simple way to make Postfix use less connections is to just put “proxy:”  in front of all “mysql:” statements in main.cf. You will have:

virtual_alias_maps = proxy:mysql:/etc/postfix/mysql_virtual_alias_maps.cf
virtual_mailbox_domains = proxy:mysql:/etc/postfix/mysql_virtual_domains_maps.cf
virtual_mailbox_maps = proxy:mysql:/etc/postfix/mysql_virtual_mailbox_maps.cf
relay_domains = proxy:mysql:/etc/postfix/mysql_relay_domains_maps.cf

This way, Postfix routes all SQL queries thru one of the two of it’s daemons called proxymap(used to fetch informations from the database) and proxywrite(used to write informations in the database).

Leave a Reply

Please type the characters of this captcha image in the input box

Please type the characters of this captcha image in the input box
Name *
Email *
Website