From Postfix Database Readme, it states
All Postfix lookup tables store information as (key, value) pairs. This interface may seem simplistic at first, but it turns out to be very powerful. The (key, value) query interface completely hides the complexities of LDAP or SQL from Postfix. This is a good example of connecting complex systems with simple interfaces.
Postfix only provide you a lookup key, then "your table" must return the appropriate value. Regarding multiple databases, postfix also support it. But it only has one single operation mode: check the database one by one sequentially until the "key" was found. When you added some custom logic like set Postfix's database access credentials based on the incoming email's destination domain, then postfix doesn't have such option.
So, the answer of your question:
Is it possible to shard postfix virtual mailboxes database?
Yes, it is possible. But you can't do that with postfix alone. You need additional "tools" to help postfix lookup information from your DB. Postfix
Some idea:
Using MySQL stored procedure to populate all databases and then run query accross the databases, for example: https://stackoverflow.com/questions/2132654/querying-multiple-databases-at-once . You you need single master credential to connect to mysql.
Put multiple postfix-mysql-maps files in one folder and set the cron to periodically to re-populate all the files in postfix main.cf
. The command like below should be sufficient.
postconf -e virtual_mailbox_maps=$(for maps in /etc/postfix/mymaps/*; do printf "mysql:$maps "; done)
- Use tcp/socketmap table maps to add additional script and do your logic. You can use postfix spawn so your script doesn't have to listen in tcp/unix socket. Your postfix must will get the key via stdin and you must return the value via stdout. Here is one implementation of tcp table and spawn in
transport_maps
.