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