1#++ 2# NAME 3# pgsql_table 5 4# SUMMARY 5# Postfix PostgreSQL client configuration 6# SYNOPSIS 7# \fBpostmap -q "\fIstring\fB" pgsql:/etc/postfix/\fIfilename\fR 8# 9# \fBpostmap -q - pgsql:/etc/postfix/\fIfilename\fB <\fIinputfile\fR 10# DESCRIPTION 11# The Postfix mail system uses optional tables for address 12# rewriting or mail routing. These tables are usually in 13# \fBdbm\fR or \fBdb\fR format. 14# 15# Alternatively, lookup tables can be specified as PostgreSQL 16# databases. In order to use PostgreSQL lookups, define a 17# PostgreSQL source as a lookup table in main.cf, for example: 18# .nf 19# alias_maps = pgsql:/etc/pgsql-aliases.cf 20# .fi 21# 22# The file /etc/postfix/pgsql-aliases.cf has the same format as 23# the Postfix main.cf file, and can specify the parameters 24# described below. 25# BACKWARDS COMPATIBILITY 26# .ad 27# .fi 28# For compatibility with other Postfix lookup tables, PostgreSQL 29# parameters can also be defined in main.cf. In order to do 30# that, specify as PostgreSQL source a name that doesn't begin 31# with a slash or a dot. The PostgreSQL parameters will then 32# be accessible as the name you've given the source in its 33# definition, an underscore, and the name of the parameter. For 34# example, if the map is specified as "pgsql:\fIpgsqlname\fR", 35# the parameter "hosts" below would be defined in main.cf as 36# "\fIpgsqlname\fR_hosts". 37# 38# Note: with this form, the passwords for the PostgreSQL sources 39# are written in main.cf, which is normally world-readable. 40# Support for this form will be removed in a future Postfix 41# version. 42# 43# Normally, the SQL query is specified via a single \fBquery\fR 44# parameter (described in more detail below). When this 45# parameter is not specified in the map definition, Postfix 46# reverts to an older interface, with the SQL query 47# constructed from the \fBselect_function\fR, \fBselect_field\fR, 48# \fBtable\fR, \fBwhere_field\fR and \fBadditional_conditions\fR 49# parameters. The old interface will be gradually phased 50# out. To migrate to the new interface set: 51# 52# .nf 53# \fBquery\fR = SELECT \fIselect_function\fR('%s') 54# .fi 55# 56# or in the absence of \fBselect_function\fR, the lower precedence: 57# 58# .nf 59# \fBquery\fR = SELECT \fIselect_field\fR 60# FROM \fItable\fR 61# WHERE \fIwhere_field\fR = '%s' 62# \fIadditional_conditions\fR 63# .fi 64# 65# Use the value, not the name, of each legacy parameter. Note 66# that the \fBadditional_conditions\fR parameter is optional 67# and if not empty, will always start with \fBAND\fR. 68# LIST MEMBERSHIP 69# .ad 70# .fi 71# When using SQL to store lists such as $mynetworks, 72# $mydestination, $relay_domains, $local_recipient_maps, 73# etc., it is important to understand that the table must 74# store each list member as a separate key. The table lookup 75# verifies the *existence* of the key. See "Postfix lists 76# versus tables" in the DATABASE_README document for a 77# discussion. 78# 79# Do NOT create tables that return the full list of domains 80# in $mydestination or $relay_domains etc., or IP addresses 81# in $mynetworks. 82# 83# DO create tables with each matching item as a key and with 84# an arbitrary value. With SQL databases it is not uncommon to 85# return the key itself or a constant value. 86# PGSQL PARAMETERS 87# .ad 88# .fi 89# .IP "\fBhosts\fR" 90# The hosts that Postfix will try to connect to and query from. 91# Specify \fIunix:\fR for UNIX-domain sockets, \fIinet:\fR for TCP 92# connections (default). Example: 93# .nf 94# hosts = host1.some.domain host2.some.domain:port 95# hosts = unix:/file/name 96# .fi 97# 98# The hosts are tried in random order, with all connections over 99# UNIX domain sockets being tried before those over TCP. The 100# connections are automatically closed after being idle for about 101# 1 minute, and are re-opened as necessary. 102# 103# NOTE: the \fIunix:\fR and \fIinet:\fR prefixes are accepted for 104# backwards compatibility reasons, but are actually ignored. 105# The PostgreSQL client library will always try to connect to an 106# UNIX socket if the name starts with a slash, and will try a TCP 107# connection otherwise. 108# .IP "\fBuser, password\fR" 109# The user name and password to log into the pgsql server. 110# Example: 111# .nf 112# user = someone 113# password = some_password 114# .fi 115# .IP "\fBdbname\fR" 116# The database name on the servers. Example: 117# .nf 118# dbname = customer_database 119# .fi 120# .IP "\fBquery\fR" 121# The SQL query template used to search the database, where \fB%s\fR 122# is a substitute for the address Postfix is trying to resolve, 123# e.g. 124# .nf 125# query = SELECT replacement FROM aliases WHERE mailbox = '%s' 126# .fi 127# 128# This parameter supports the following '%' expansions: 129# .RS 130# .IP "\fB%%\fR" 131# This is replaced by a literal '%' character. (Postfix 2.2 and later) 132# .IP "\fB%s\fR" 133# This is replaced by the input key. 134# SQL quoting is used to make sure that the input key does not 135# add unexpected metacharacters. 136# .IP "\fB%u\fR" 137# When the input key is an address of the form user@domain, \fB%u\fR 138# is replaced by the SQL quoted local part of the address. 139# Otherwise, \fB%u\fR is replaced by the entire search string. 140# If the localpart is empty, the query is suppressed and returns 141# no results. 142# .IP "\fB%d\fR" 143# When the input key is an address of the form user@domain, \fB%d\fR 144# is replaced by the SQL quoted domain part of the address. 145# Otherwise, the query is suppressed and returns no results. 146# .IP "\fB%[SUD]\fR" 147# The upper-case equivalents of the above expansions behave in the 148# \fBquery\fR parameter identically to their lower-case counter-parts. 149# With the \fBresult_format\fR parameter (see below), they expand the 150# input key rather than the result value. 151# .IP 152# The above %S, %U and %D expansions are available with Postfix 2.2 153# and later 154# .IP "\fB%[1-9]\fR" 155# The patterns %1, %2, ... %9 are replaced by the corresponding 156# most significant component of the input key's domain. If the 157# input key is \fIuser@mail.example.com\fR, then %1 is \fBcom\fR, 158# %2 is \fBexample\fR and %3 is \fBmail\fR. If the input key is 159# unqualified or does not have enough domain components to satisfy 160# all the specified patterns, the query is suppressed and returns 161# no results. 162# .IP 163# The above %1, ... %9 expansions are available with Postfix 2.2 164# and later 165# .RE 166# .IP 167# The \fBdomain\fR parameter described below limits the input 168# keys to addresses in matching domains. When the \fBdomain\fR 169# parameter is non-empty, SQL queries for unqualified addresses 170# or addresses in non-matching domains are suppressed 171# and return no results. 172# 173# The precedence of this parameter has changed with Postfix 2.2, 174# in prior releases the precedence was, from highest to lowest, 175# \fBselect_function\fR, \fBquery\fR, \fBselect_field\fR, ... 176# 177# With Postfix 2.2 the \fBquery\fR parameter has highest precedence, 178# see COMPATIBILITY above. 179# 180# NOTE: DO NOT put quotes around the \fBquery\fR parameter. 181# .IP "\fBresult_format (default: \fB%s\fR)\fR" 182# Format template applied to result attributes. Most commonly used 183# to append (or prepend) text to the result. This parameter supports 184# the following '%' expansions: 185# .RS 186# .IP "\fB%%\fR" 187# This is replaced by a literal '%' character. 188# .IP "\fB%s\fR" 189# This is replaced by the value of the result attribute. When 190# result is empty it is skipped. 191# .IP "\fB%u\fR 192# When the result attribute value is an address of the form 193# user@domain, \fB%u\fR is replaced by the local part of the 194# address. When the result has an empty localpart it is skipped. 195# .IP "\fB%d\fR" 196# When a result attribute value is an address of the form 197# user@domain, \fB%d\fR is replaced by the domain part of 198# the attribute value. When the result is unqualified it 199# is skipped. 200# .IP "\fB%[SUD1-9]\fR" 201# The upper-case and decimal digit expansions interpolate 202# the parts of the input key rather than the result. Their 203# behavior is identical to that described with \fBquery\fR, 204# and in fact because the input key is known in advance, queries 205# whose key does not contain all the information specified in 206# the result template are suppressed and return no results. 207# .RE 208# .IP 209# For example, using "result_format = smtp:[%s]" allows one 210# to use a mailHost attribute as the basis of a transport(5) 211# table. After applying the result format, multiple values 212# are concatenated as comma separated strings. The expansion_limit 213# and parameter explained below allows one to restrict the number 214# of values in the result, which is especially useful for maps that 215# must return at most one value. 216# 217# The default value \fB%s\fR specifies that each result value should 218# be used as is. 219# 220# This parameter is available with Postfix 2.2 and later. 221# 222# NOTE: DO NOT put quotes around the result format! 223# .IP "\fBdomain (default: no domain list)\fR" 224# This is a list of domain names, paths to files, or 225# dictionaries. When specified, only fully qualified search 226# keys with a *non-empty* localpart and a matching domain 227# are eligible for lookup: 'user' lookups, bare domain lookups 228# and "@domain" lookups are not performed. This can significantly 229# reduce the query load on the PostgreSQL server. 230# .nf 231# domain = postfix.org, hash:/etc/postfix/searchdomains 232# .fi 233# 234# It is best not to use SQL to store the domains eligible 235# for SQL lookups. 236# 237# This parameter is available with Postfix 2.2 and later. 238# 239# NOTE: DO NOT define this parameter for local(8) aliases, 240# because the input keys are always unqualified. 241# .IP "\fBexpansion_limit (default: 0)\fR" 242# A limit on the total number of result elements returned 243# (as a comma separated list) by a lookup against the map. 244# A setting of zero disables the limit. Lookups fail with a 245# temporary error if the limit is exceeded. Setting the 246# limit to 1 ensures that lookups do not return multiple 247# values. 248# OBSOLETE QUERY INTERFACES 249# .ad 250# .fi 251# This section describes query interfaces that are deprecated 252# as of Postfix 2.2. Please migrate to the new \fBquery\fR 253# interface as the old interfaces are slated to be phased 254# out. 255# .IP "\fBselect_function\fR" 256# This parameter specifies a database function name. Example: 257# .nf 258# select_function = my_lookup_user_alias 259# .fi 260# 261# This is equivalent to: 262# .nf 263# query = SELECT my_lookup_user_alias('%s') 264# .fi 265# 266# This parameter overrides the legacy table-related fields (described 267# below). With Postfix versions prior to 2.2, it also overrides the 268# \fBquery\fR parameter. Starting with Postfix 2.2, the \fBquery\fR 269# parameter has highest precedence, and the \fBselect_function\fR 270# parameter is deprecated. 271# .PP 272# The following parameters (with lower precedence than the 273# \fBselect_function\fR interface described above) can be used to 274# build the SQL select statement as follows: 275# 276# .nf 277# SELECT [\fBselect_field\fR] 278# FROM [\fBtable\fR] 279# WHERE [\fBwhere_field\fR] = '%s' 280# [\fBadditional_conditions\fR] 281# .fi 282# 283# The specifier %s is replaced with each lookup by the lookup key 284# and is escaped so if it contains single quotes or other odd 285# characters, it will not cause a parse error, or worse, a security 286# problem. 287# 288# Starting with Postfix 2.2, this interface is obsoleted by the more 289# general \fBquery\fR interface described above. If higher precedence 290# the \fBquery\fR or \fBselect_function\fR parameters described above 291# are defined, the parameters described here are ignored. 292# .IP "\fBselect_field\fR" 293# The SQL "select" parameter. Example: 294# .nf 295# \fBselect_field\fR = forw_addr 296# .fi 297# .IP "\fBtable\fR" 298# The SQL "select .. from" table name. Example: 299# .nf 300# \fBtable\fR = mxaliases 301# .fi 302# .IP "\fBwhere_field\fR 303# The SQL "select .. where" parameter. Example: 304# .nf 305# \fBwhere_field\fR = alias 306# .fi 307# .IP "\fBadditional_conditions\fR 308# Additional conditions to the SQL query. Example: 309# .nf 310# \fBadditional_conditions\fR = AND status = 'paid' 311# .fi 312# SEE ALSO 313# postmap(1), Postfix lookup table manager 314# postconf(5), configuration parameters 315# ldap_table(5), LDAP lookup tables 316# mysql_table(5), MySQL lookup tables 317# sqlite_table(5), SQLite lookup tables 318# README FILES 319# .ad 320# .fi 321# Use "\fBpostconf readme_directory\fR" or 322# "\fBpostconf html_directory\fR" to locate this information. 323# .na 324# .nf 325# DATABASE_README, Postfix lookup table overview 326# PGSQL_README, Postfix PostgreSQL client guide 327# LICENSE 328# .ad 329# .fi 330# The Secure Mailer license must be distributed with this software. 331# HISTORY 332# PgSQL support was introduced with Postfix version 2.1. 333# AUTHOR(S) 334# Based on the MySQL client by: 335# Scott Cotton, Joshua Marcus 336# IC Group, Inc. 337# 338# Ported to PostgreSQL by: 339# Aaron Sethman 340# 341# Further enhanced by: 342# Liviu Daia 343# Institute of Mathematics of the Romanian Academy 344# P.O. BOX 1-764 345# RO-014700 Bucharest, ROMANIA 346#-- 347