almost human fully human



Compiling Postfix with PostgreSQL support on Centos 7

I finally decided to move my server to Centos 7. One of the most important services that I hosted was my mail server based on Postfix and Dovecot. I also decided to migrate from MySQL to PostgreSQL, which finally proved to be not so easy. This is because Postfix in Centos 7 repositories is being provided without Postgres support. So I needed to compile one on my own. This tutorial is based on Centos 7 that is being installed on Digital Ocean droplets.

I recorded terminal session on fresh CentOS install (on Digital Ocean):

Before we start, check if our version already has PostgreSQL:

postconf -c /etc/postfix -m | grep sql

If there’s pgsql, it means that someone recompiled Postfix (maybe for Centos Plus repository) and you don’t need to compile it on your own. If there’s only mysql, you need to follow next steps.

First, install Postfix from official repository:

yum install postfix

It will help with gathering dependancies. Now, download Postfix source from: Once downloading is completed, unarchivize it:

tar xvf postfix-2.11.1.tar.gz

Enter its directory and create file (copy whole line to your terminal):

echo "make makefiles CCARGS='-DHAS_PGSQL -I/usr/local/include/pgsql -fPIC -DUSE_TLS -DUSE_SSL -DUSE_SASL_AUTH -DUSE_CYRUS_SASL -DPREFIX=\\"/usr\\" -DHAS_LDAP -DLDAP_DEPRECATED=1 -DHAS_PCRE -I/usr/include/openssl -I/usr/include/sasl  -I/usr/include' AUXLIBS='-L/usr/local/lib -lpq -L/usr/lib64 -L/usr/lib64/openssl -lssl -lcrypto -L/usr/lib64/sasl2 -lsasl2 -lpcre -lz -lm -lldap -llber -Wl,-rpath,/usr/lib64/openssl -pie -Wl,-z,relro' OPT='-O' DEBUG='-g'" > && chmod a+x

Let’s install all dependancies now, but first we need to enable CentOS Plus repository.

yum install libdb libdb-devel gcc openssl openssl-devel pcre pcre-devel openldap-devel cyrus-sasl cyrus-sasl-devel openldap postgresql postgresql-devel

Now, we are ready to run


It creates new Makefile. It’s time to do some compiling:

make tidy

Now we are ready to upgrade existing Postfix installation. But first regenerate our Makefile.


Upgrading time:

make upgrade

Ok, let’s test it:

postconf -c /etc/postfix -m | grep sql

It should contain pgsql now. Just remember to exclude postfix package in yum, so it won’t mess with your version.

If you’re looking for some configuration example, I recommend checking out my tutorial: