[Code contributed by Mathieu Arnold]

We've written code to add a pgsql map type.  It utilizes the pgsql 
client library, which can be obtained from:

		   http://www.postgresql.org/

In order to build postfix with pgsql map support, you will need to add 
-DHAS_PGSQL and -I for the directory containing the postgres headers, and 
the libpq library (and libcrypt) to AUXLIBS, for example:

make -f Makefile.init makefiles \
	'CCARGS=-DHAS_PGSQL -I/some/where/include/postgresql' \
	'AUXLIBS=/some/where/lib/postgres/libpq.a -lcrypt'

then, just run 'make'.

Postfix installations which may benefit from using pgsql map types
include sites that have a need for instantaneous updates of
forwarding, and sites that may benefit from having mail exchangers
reference a networked database, possibly working in conjunction with a
customer database of sorts.

Once postfix is built with pgsql support, you can specify a map type
in main.cf like this:

alias_maps = pgsql:/etc/postfix/pgsql-aliases.cf

The file /etc/postfix/pgsql-aliases.cf specifies lots of information
telling postfix how to reference the postgresql database.  An example
postgresql map config file follows:

#
# postgresql config file for alias lookups on postfix
# comments are ok.
#

# the user name and password to log into the pgsql server
user = someone
password = some_passwordd 

# the database name on the servers
dbname = customer_database

# the table name
table = mxaliases

#
select_field = forw_addr
where_field = alias

# you may specify additional_conditions here
additional_conditions = and status = 'paid'

# the above variables will result in a query of
# the form: 
# select forw_addr from mxaliases where alias = '$lookup' and status = 'paid'
# ($lookup is escaped so if it contains single quotes or other odd
# characters, it will not cause a parse error in the sql).
#
# the hosts that postfix will try to connect to
# and query from (in the order listed)
hosts = host1.some.domain host2.some.domain

# end postgresql config file

Some notes:

This configuration interface setup allows for multiple postgresql
databases: you can use one for a virtual table, one for an access
table, and one for an aliases table if you want.

Since sites that have a need for multiple mail exchangers may enjoy
the convenience of using a networked mailer database, but do not want 
to introduce a single point of failure to their system, we've included 
the ability to have postfix reference multiple hosts for access to a
single pgsql map.  This will work if sites set up mirrored pgsql
databases on two or more hosts.  Whenever queries fail with an error
at one host, the rest of the hosts will be tried in order.  Each host
that is in an error state will undergo a reconnection attempt every so 
often, and if no pgsql server hosts are reachable, then mail will be
deferred until atleast one of those hosts is reachable.

Performance of postfix with pgsql has not been thoroughly tested,
however, we have found it to be stable.  Busy mail servers using pgsql
maps will generate lots of concurrent pgsql clients, so the pgsql
server(s) should be run with this fact in mind.  Any further
performance information, in addition to any feedback is most welcome.
