Complete Virtual Mail Server/Postfix to Database

Installing Postfix
Postfix installation is quite straight forward. A basic installation instruction can be found here on the wiki for Postfix.

Linking Postfix
Once basic postfix is working on its most basic level its time to link it to the database.

PostgreSQL
When using postfix on the same host, the local unix socket connection is recommended. For this postfix needs rights on the socket.

Also a database-user to query the database is required.

Also the postfix user needs some permissions on the tables.

PostgreSQL
Linking postfix to a database isn't that special, postfix just executes predefined SQL routines. These SQL queries will be stored in a file per query in a directory.

Be aware that any errors in the configuration information in these files can be pretty tricky to track down. Be meticulous with both the contents of the files and their names. Many errors in these files will be announced in the mail log such as "user example@example.com doesn't exist" without much further explanations.

It's best to test the query on the database (using copy paste) to ensure no typo's exist in the query.