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