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