Home | History | Annotate | Line # | Download | only in proto
PGSQL_README.html revision 1.1.1.1.32.1
      1 <!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN"
      2         "http://www.w3.org/TR/html4/loose.dtd">
      3 
      4 <html>
      5 
      6 <head>
      7 
      8 <title>Postfix PostgreSQL Howto</title>
      9 
     10 <meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
     11 
     12 </head>
     13 
     14 <body>
     15 
     16 <h1><img src="postfix-logo.jpg" width="203" height="98" ALT="">Postfix PostgreSQL Howto</h1>
     17 
     18 <hr>
     19 
     20 <h2>Introduction</h2>
     21 
     22 <p> The Postfix pgsql map type allows you to hook up Postfix to a
     23 PostgreSQL database.  This implementation allows for multiple pgsql
     24 databases: you can use one for a virtual(5) table, one for an
     25 access(5) table, and one for an aliases(5) table if you want.  You
     26 can specify multiple servers for the same database, so that Postfix
     27 can switch to a good database server if one goes bad.  </p>
     28 
     29 <p> Busy mail servers using pgsql maps will generate lots of
     30 concurrent pgsql clients, so the pgsql server(s) should be run with
     31 this fact in mind. You can reduce the number of concurrent pgsql
     32 clients by using the Postfix proxymap(8) service. </p>
     33 
     34 <h2>Building Postfix with PostgreSQL support</h2>
     35 
     36 <p> These instructions assume that you build Postfix from source
     37 code as described in the INSTALL document. Some modification may
     38 be required if you build Postfix from a vendor-specific source
     39 package.  </p>
     40 
     41 <p> Note: to use pgsql with Debian GNU/Linux's Postfix, all you
     42 need to do is to install the postfix-pgsql package and you're done.
     43 There is no need to recompile Postfix. </p>
     44 
     45 <p> In order to build Postfix with pgsql map support, you specify
     46 -DHAS_PGSQL, the directory with the PostgreSQL header files, and
     47 the location of the libpq library file. </p>
     48 
     49 <p> For example: </p>
     50 
     51 <blockquote>
     52 <pre>
     53 % make tidy
     54 % make -f Makefile.init makefiles \
     55         'CCARGS=-DHAS_PGSQL -I/usr/local/include/pgsql' \
     56         'AUXLIBS_PGSQL=-L/usr/local/lib -lpq'
     57 </pre>
     58 </blockquote>
     59 
     60 <p> Postfix versions before 3.0 use AUXLIBS instead of AUXLIBS_PGSQL.
     61 With Postfix 3.0 and later, the old AUXLIBS variable still supports
     62 building a statically-loaded PostgreSQL database client, but only
     63 the new AUXLIBS_PGSQL variable supports building a dynamically-loaded
     64 or statically-loaded PostgreSQL database client.  </p>
     65 
     66 <blockquote>
     67  
     68 <p> Failure to use the AUXLIBS_PGSQL variable will defeat the purpose
     69 of dynamic database client loading. Every Postfix executable file
     70 will have PGSQL database library dependencies. And that was exactly
     71 what dynamic database client loading was meant to avoid. </p>
     72  
     73 </blockquote>
     74 
     75 <p> Then just run 'make'.  </p>
     76 
     77 <h2>Configuring PostgreSQL lookup tables</h2>
     78 
     79 <p> Once Postfix is built with pgsql support, you can specify a
     80 map type in main.cf like this: </p>
     81 
     82 <blockquote>
     83 <pre>
     84 /etc/postfix/main.cf:
     85     alias_maps = pgsql:/etc/postfix/pgsql-aliases.cf
     86 </pre>
     87 </blockquote>
     88 
     89 <p> The file /etc/postfix/pgsql-aliases.cf specifies lots of
     90 information telling postfix how to reference the pgsql database.
     91 For a complete description, see the pgsql_table(5) manual page. </p>
     92 
     93 <h2>Example: local aliases </h2>
     94 
     95 <pre>
     96 #
     97 # pgsql config file for local(8) aliases(5) lookups
     98 #
     99 
    100 #
    101 # The hosts that Postfix will try to connect to
    102 hosts = host1.some.domain host2.some.domain
    103 
    104 # The user name and password to log into the pgsql server.
    105 user = someone
    106 password = some_password
    107 
    108 # The database name on the servers.
    109 dbname = customer_database
    110 
    111 # Postfix 2.2 and later The SQL query template. See pgsql_table(5).
    112 query = SELECT forw_addr FROM mxaliases WHERE alias='%s' AND status='paid'
    113 
    114 # For Postfix releases prior to 2.2. See pgsql_table(5) for details.
    115 select_field = forw_addr
    116 table = mxaliases
    117 where_field = alias
    118 # Don't forget the leading "AND"!
    119 additional_conditions = AND status = 'paid'
    120 </pre>
    121 
    122 <h2>Using mirrored databases</h2>
    123 
    124 <p> Sites that have a need for multiple mail exchangers may enjoy
    125 the convenience of using a networked mailer database, but do not
    126 want to introduce a single point of failure to their system.   </p>
    127 
    128 <p> For this reason we've included the ability to have Postfix
    129 reference multiple hosts for access to a single pgsql map.  This
    130 will work if sites set up mirrored pgsql databases on two or more
    131 hosts. </p>
    132 
    133 <p> Whenever queries fail with an error at one host, the rest of
    134 the hosts will be tried in random order.  If no pgsql server hosts
    135 are reachable, then mail will be deferred until at least one of
    136 those hosts is reachable. </p>
    137 
    138 <h2>Credits</h2>
    139 
    140 <ul>
    141 
    142 <li> This code is based upon the Postfix mysql map by Scott Cotton
    143 and Joshua Marcus, IC Group, Inc.</li>
    144 
    145 <li> The PostgreSQL changes were done by Aaron Sethman.</li>
    146 
    147 <li> Updates for Postfix 1.1.x and PostgreSQL 7.1+ and support for
    148 calling stored procedures were added by Philip Warner.</li>
    149 
    150 <li> LaMont Jones was the initial Postfix pgsql maintainer.</li>
    151 
    152 <li> Liviu Daia revised the configuration interface and added the
    153 main.cf configuration feature.</li>
    154 
    155 <li> Liviu Daia revised the configuration interface and added the main.cf
    156 configuration feature.</li>
    157 
    158 <li> Liviu Daia with further refinements from Jose Luis Tallon and
    159 Victor Duchovni developed the common query, result_format, domain and
    160 expansion_limit interface for LDAP, MySQL and PosgreSQL.</li>
    161 
    162 <li> Leandro Santi updated the PostgreSQL client after the PostgreSQL
    163 developers made major database API changes in response to SQL
    164 injection problems, and made PQexec() handling more robust. </li>
    165 
    166 </ul>
    167 
    168 </body>
    169 
    170 </html>
    171