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