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