Friday, October 4, 2013

howto rebuild Postfix with pgsql(PostgreSQL) support in Centos from rpm

I have found, that in Centos postfix package comes only with mysql support. But if you gonna use pgsql backend, you'll need to rebuild it. Here some clues:

To find your postfix configuration, execute
posctconf -m

first, you'll need to find and install with yum posgresql-devel and postgresql libs
I have Centos 6.4 x64 here. These packages have to be installed:

#  rpm -qa | grep postgre
postgresql93-9.3.0-1PGDG.rhel6.x86_64
postgresql93-devel-9.3.0-1PGDG.rhel6.x86_64
postgresql93-contrib-9.3.0-1PGDG.rhel6.x86_64
postgrey-1.34-1.el6.rf.noarch
postgresql93-libs-9.3.0-1PGDG.rhel6.x86_64
postgresql93-server-9.3.0-1PGDG.rhel6.x86_64


To install, type
# yum install <PACKAGE> -y (ex: yum install postgresql93-libs -y)


Then download source
wget http://vault.centos.org/6.4/os/Source/SPackages/postfix-2.6.6-2.2.el6_1.src.rpm
rpm -i postfix-2.6.6-2.2.el6_1.src.rpm

You have sources installed to your home folder

cd ~/rpmbuild/SPECS/
vim postfix.spec

Find these strings: ... %{?!MYSQL: %define MYSQL 1} ...
change them to
....
%{?!MYSQL: %define MYSQL 0}
%{?!PGSQL: %define PGSQL 1}

Save changes and try to build:

 rpmbuild -ba postfix.spec

Might be you'll need to install following developer's packages:
yum install  openssl-devel  mysql-devel pcre-devel cyrus-sasl-devel openldap-devel db4-devel zlib-devel


Im assure, you have rpm-build, make,gcc and etc installed. If not - look in google how to do yum groupinstall "Development tools" or something like that.

NOW, if you are lucky, the package will be stored in RPM of your home dir, but i had some problems during the compilation..

/usr/bin/ld: cannot find -lpq

And this was my fix:
Open postfix.spec again and edit (but you have to figure out, where are your psql includes are stored -
 rpm -qil postgresql93-devel-9.3.0-1PGDG.rhel6.x86_64 )
 Look at example below, you will need to find these strings and correct them with right paths:

%if %{PGSQL}
  CCARGS="${CCARGS} -DHAS_PGSQL -I/usr/pgsql-9.3/include"
  #AUXLIBS="${AUXLIBS} -lpq"
  AUXLIBS="${AUXLIBS} /usr/pgsql-9.3/lib/libpq.so"
%endif
So the trick was to replace "AUXLIBS="${AUXLIBS} -lpq" to AUXLIBS="${AUXLIBS} /usr/pgsql-9.3/lib/libpq.so" but it might be as well AUXLIBS="/usr/pgsql-9.3/lib/libpq.so". Try both ways. Then again

 rpmbuild -ba postfix.spec

Hope this helped -)



3 comments:

  1. as well, you will need to prevent its upgrading through yum. http://www.cyberciti.biz/faq/redhat-centos-linux-yum-update-exclude-packages/

    ReplyDelete
  2. this is the better way to upgrade

    https://solusipse.net/blog/posts/compiling-postfix-with-postgresql-support-on-centos-7/

    ReplyDelete