141fbaed0Stron#++ 241fbaed0Stron# NAME 341fbaed0Stron# pgsql_table 5 441fbaed0Stron# SUMMARY 541fbaed0Stron# Postfix PostgreSQL client configuration 641fbaed0Stron# SYNOPSIS 716d67a18Stron# \fBpostmap -q "\fIstring\fB" pgsql:/etc/postfix/\fIfilename\fR 841fbaed0Stron# 916d67a18Stron# \fBpostmap -q - pgsql:/etc/postfix/\fIfilename\fB <\fIinputfile\fR 1041fbaed0Stron# DESCRIPTION 1141fbaed0Stron# The Postfix mail system uses optional tables for address 1241fbaed0Stron# rewriting or mail routing. These tables are usually in 1341fbaed0Stron# \fBdbm\fR or \fBdb\fR format. 1441fbaed0Stron# 1541fbaed0Stron# Alternatively, lookup tables can be specified as PostgreSQL 1641fbaed0Stron# databases. In order to use PostgreSQL lookups, define a 1741fbaed0Stron# PostgreSQL source as a lookup table in main.cf, for example: 1841fbaed0Stron# .nf 194a672054Schristos# alias_maps = pgsql:/etc/postfix/pgsql-aliases.cf 2041fbaed0Stron# .fi 2141fbaed0Stron# 2241fbaed0Stron# The file /etc/postfix/pgsql-aliases.cf has the same format as 2341fbaed0Stron# the Postfix main.cf file, and can specify the parameters 2441fbaed0Stron# described below. 2541fbaed0Stron# LIST MEMBERSHIP 2641fbaed0Stron# .ad 2741fbaed0Stron# .fi 2841fbaed0Stron# When using SQL to store lists such as $mynetworks, 2941fbaed0Stron# $mydestination, $relay_domains, $local_recipient_maps, 3041fbaed0Stron# etc., it is important to understand that the table must 3141fbaed0Stron# store each list member as a separate key. The table lookup 3241fbaed0Stron# verifies the *existence* of the key. See "Postfix lists 3341fbaed0Stron# versus tables" in the DATABASE_README document for a 3441fbaed0Stron# discussion. 3541fbaed0Stron# 3641fbaed0Stron# Do NOT create tables that return the full list of domains 3741fbaed0Stron# in $mydestination or $relay_domains etc., or IP addresses 3841fbaed0Stron# in $mynetworks. 3941fbaed0Stron# 4041fbaed0Stron# DO create tables with each matching item as a key and with 4141fbaed0Stron# an arbitrary value. With SQL databases it is not uncommon to 4241fbaed0Stron# return the key itself or a constant value. 4341fbaed0Stron# PGSQL PARAMETERS 4441fbaed0Stron# .ad 4541fbaed0Stron# .fi 4641fbaed0Stron# .IP "\fBhosts\fR" 47f3bc92a4Schristos# The hosts that Postfix will try to connect to and query 48f3bc92a4Schristos# from. Besides a \fBpostgresql://\fR connection URI, this 49f3bc92a4Schristos# setting supports the historical forms \fBunix:/\fIpathname\fR 50f3bc92a4Schristos# for UNIX-domain sockets and \fBinet:\fIhost:port\fR for TCP 51f3bc92a4Schristos# connections, where the \fBunix:\fR and \fBinet:\fR prefixes 52f3bc92a4Schristos# are accepted and ignored for backwards compatibility. 53f3bc92a4Schristos# Examples: 5441fbaed0Stron# .nf 55f3bc92a4Schristos# hosts = postgresql://username@example.com/tablename?sslmode=require 564a672054Schristos# hosts = inet:host1.some.domain inet:host2.some.domain:port 57a30b880eStron# hosts = host1.some.domain host2.some.domain:port 5841fbaed0Stron# hosts = unix:/file/name 5941fbaed0Stron# .fi 6041fbaed0Stron# 61f3bc92a4Schristos# The hosts are tried in random order. The connections are 62f3bc92a4Schristos# automatically closed after being idle for about 1 minute, 63f3bc92a4Schristos# and are re-opened as necessary. 64*059c16a8Schristos# .IP "\fBuser\fR" 65*059c16a8Schristos# .IP "\fBpassword\fR" 6641fbaed0Stron# The user name and password to log into the pgsql server. 6741fbaed0Stron# Example: 6841fbaed0Stron# .nf 6941fbaed0Stron# user = someone 7041fbaed0Stron# password = some_password 7141fbaed0Stron# .fi 7241fbaed0Stron# .IP "\fBdbname\fR" 7341fbaed0Stron# The database name on the servers. Example: 7441fbaed0Stron# .nf 7541fbaed0Stron# dbname = customer_database 7641fbaed0Stron# .fi 77*059c16a8Schristos# .IP "\fBencoding\fR" 78*059c16a8Schristos# The encoding used by the database client. The default setting 79*059c16a8Schristos# is: 80*059c16a8Schristos# .nf 81*059c16a8Schristos# encoding = UTF8 82*059c16a8Schristos# .fi 83*059c16a8Schristos# Historically, the database client was hard coded to use 84*059c16a8Schristos# LATIN1 in an attempt to disable multibyte character support. 85*059c16a8Schristos# 86*059c16a8Schristos# This feature is available in Postfix 3.8 and later. 8741fbaed0Stron# .IP "\fBquery\fR" 8841fbaed0Stron# The SQL query template used to search the database, where \fB%s\fR 8941fbaed0Stron# is a substitute for the address Postfix is trying to resolve, 9041fbaed0Stron# e.g. 9141fbaed0Stron# .nf 9241fbaed0Stron# query = SELECT replacement FROM aliases WHERE mailbox = '%s' 9341fbaed0Stron# .fi 9441fbaed0Stron# 9541fbaed0Stron# This parameter supports the following '%' expansions: 9641fbaed0Stron# .RS 97e262b48eSchristos# .IP "\fB%%\fR" 9841fbaed0Stron# This is replaced by a literal '%' character. (Postfix 2.2 and later) 99e262b48eSchristos# .IP "\fB%s\fR" 10041fbaed0Stron# This is replaced by the input key. 10141fbaed0Stron# SQL quoting is used to make sure that the input key does not 10241fbaed0Stron# add unexpected metacharacters. 103e262b48eSchristos# .IP "\fB%u\fR" 10441fbaed0Stron# When the input key is an address of the form user@domain, \fB%u\fR 10541fbaed0Stron# is replaced by the SQL quoted local part of the address. 10641fbaed0Stron# Otherwise, \fB%u\fR is replaced by the entire search string. 10741fbaed0Stron# If the localpart is empty, the query is suppressed and returns 10841fbaed0Stron# no results. 109e262b48eSchristos# .IP "\fB%d\fR" 11041fbaed0Stron# When the input key is an address of the form user@domain, \fB%d\fR 11141fbaed0Stron# is replaced by the SQL quoted domain part of the address. 11241fbaed0Stron# Otherwise, the query is suppressed and returns no results. 113e262b48eSchristos# .IP "\fB%[SUD]\fR" 11441fbaed0Stron# The upper-case equivalents of the above expansions behave in the 11541fbaed0Stron# \fBquery\fR parameter identically to their lower-case counter-parts. 11641fbaed0Stron# With the \fBresult_format\fR parameter (see below), they expand the 11741fbaed0Stron# input key rather than the result value. 11841fbaed0Stron# .IP 11941fbaed0Stron# The above %S, %U and %D expansions are available with Postfix 2.2 12041fbaed0Stron# and later 121e262b48eSchristos# .IP "\fB%[1-9]\fR" 12241fbaed0Stron# The patterns %1, %2, ... %9 are replaced by the corresponding 12341fbaed0Stron# most significant component of the input key's domain. If the 12441fbaed0Stron# input key is \fIuser@mail.example.com\fR, then %1 is \fBcom\fR, 12541fbaed0Stron# %2 is \fBexample\fR and %3 is \fBmail\fR. If the input key is 12641fbaed0Stron# unqualified or does not have enough domain components to satisfy 12741fbaed0Stron# all the specified patterns, the query is suppressed and returns 12841fbaed0Stron# no results. 12941fbaed0Stron# .IP 13041fbaed0Stron# The above %1, ... %9 expansions are available with Postfix 2.2 13141fbaed0Stron# and later 13241fbaed0Stron# .RE 13341fbaed0Stron# .IP 13441fbaed0Stron# The \fBdomain\fR parameter described below limits the input 13541fbaed0Stron# keys to addresses in matching domains. When the \fBdomain\fR 13641fbaed0Stron# parameter is non-empty, SQL queries for unqualified addresses 13741fbaed0Stron# or addresses in non-matching domains are suppressed 13841fbaed0Stron# and return no results. 13941fbaed0Stron# 14041fbaed0Stron# The precedence of this parameter has changed with Postfix 2.2, 14141fbaed0Stron# in prior releases the precedence was, from highest to lowest, 14241fbaed0Stron# \fBselect_function\fR, \fBquery\fR, \fBselect_field\fR, ... 14341fbaed0Stron# 14441fbaed0Stron# With Postfix 2.2 the \fBquery\fR parameter has highest precedence, 1454a672054Schristos# see OBSOLETE QUERY INTERFACES below. 14641fbaed0Stron# 14741fbaed0Stron# NOTE: DO NOT put quotes around the \fBquery\fR parameter. 14841fbaed0Stron# .IP "\fBresult_format (default: \fB%s\fR)\fR" 14941fbaed0Stron# Format template applied to result attributes. Most commonly used 15041fbaed0Stron# to append (or prepend) text to the result. This parameter supports 15141fbaed0Stron# the following '%' expansions: 15241fbaed0Stron# .RS 153e262b48eSchristos# .IP "\fB%%\fR" 15441fbaed0Stron# This is replaced by a literal '%' character. 155e262b48eSchristos# .IP "\fB%s\fR" 15641fbaed0Stron# This is replaced by the value of the result attribute. When 15741fbaed0Stron# result is empty it is skipped. 15841fbaed0Stron# .IP "\fB%u\fR 15941fbaed0Stron# When the result attribute value is an address of the form 16041fbaed0Stron# user@domain, \fB%u\fR is replaced by the local part of the 16141fbaed0Stron# address. When the result has an empty localpart it is skipped. 162e262b48eSchristos# .IP "\fB%d\fR" 16341fbaed0Stron# When a result attribute value is an address of the form 16441fbaed0Stron# user@domain, \fB%d\fR is replaced by the domain part of 16541fbaed0Stron# the attribute value. When the result is unqualified it 16641fbaed0Stron# is skipped. 167e262b48eSchristos# .IP "\fB%[SUD1-9]\fR" 16841fbaed0Stron# The upper-case and decimal digit expansions interpolate 16941fbaed0Stron# the parts of the input key rather than the result. Their 17041fbaed0Stron# behavior is identical to that described with \fBquery\fR, 17141fbaed0Stron# and in fact because the input key is known in advance, queries 17241fbaed0Stron# whose key does not contain all the information specified in 17341fbaed0Stron# the result template are suppressed and return no results. 17441fbaed0Stron# .RE 17541fbaed0Stron# .IP 17641fbaed0Stron# For example, using "result_format = smtp:[%s]" allows one 17741fbaed0Stron# to use a mailHost attribute as the basis of a transport(5) 17841fbaed0Stron# table. After applying the result format, multiple values 17941fbaed0Stron# are concatenated as comma separated strings. The expansion_limit 18041fbaed0Stron# and parameter explained below allows one to restrict the number 18141fbaed0Stron# of values in the result, which is especially useful for maps that 18241fbaed0Stron# must return at most one value. 18341fbaed0Stron# 18441fbaed0Stron# The default value \fB%s\fR specifies that each result value should 18541fbaed0Stron# be used as is. 18641fbaed0Stron# 18741fbaed0Stron# This parameter is available with Postfix 2.2 and later. 18841fbaed0Stron# 18941fbaed0Stron# NOTE: DO NOT put quotes around the result format! 19041fbaed0Stron# .IP "\fBdomain (default: no domain list)\fR" 1914a672054Schristos# This is a list of domain names, paths to files, or "type:table" 1924a672054Schristos# databases. When specified, only fully qualified search 19341fbaed0Stron# keys with a *non-empty* localpart and a matching domain 19441fbaed0Stron# are eligible for lookup: 'user' lookups, bare domain lookups 19541fbaed0Stron# and "@domain" lookups are not performed. This can significantly 19641fbaed0Stron# reduce the query load on the PostgreSQL server. 19741fbaed0Stron# .nf 19841fbaed0Stron# domain = postfix.org, hash:/etc/postfix/searchdomains 19941fbaed0Stron# .fi 20041fbaed0Stron# 20141fbaed0Stron# It is best not to use SQL to store the domains eligible 20241fbaed0Stron# for SQL lookups. 20341fbaed0Stron# 20441fbaed0Stron# This parameter is available with Postfix 2.2 and later. 20541fbaed0Stron# 20641fbaed0Stron# NOTE: DO NOT define this parameter for local(8) aliases, 20741fbaed0Stron# because the input keys are always unqualified. 20841fbaed0Stron# .IP "\fBexpansion_limit (default: 0)\fR" 20941fbaed0Stron# A limit on the total number of result elements returned 21041fbaed0Stron# (as a comma separated list) by a lookup against the map. 21141fbaed0Stron# A setting of zero disables the limit. Lookups fail with a 21241fbaed0Stron# temporary error if the limit is exceeded. Setting the 21341fbaed0Stron# limit to 1 ensures that lookups do not return multiple 21441fbaed0Stron# values. 215f3bc92a4Schristos# OBSOLETE MAIN.CF PARAMETERS 216f3bc92a4Schristos# .ad 217f3bc92a4Schristos# .fi 218f3bc92a4Schristos# For compatibility with other Postfix lookup tables, PostgreSQL 219f3bc92a4Schristos# parameters can also be defined in main.cf. In order to do 220f3bc92a4Schristos# that, specify as PostgreSQL source a name that doesn't begin 221f3bc92a4Schristos# with a slash or a dot. The PostgreSQL parameters will then 222f3bc92a4Schristos# be accessible as the name you've given the source in its 223f3bc92a4Schristos# definition, an underscore, and the name of the parameter. For 224f3bc92a4Schristos# example, if the map is specified as "pgsql:\fIpgsqlname\fR", 225f3bc92a4Schristos# the parameter "hosts" would be defined in main.cf as 226f3bc92a4Schristos# "\fIpgsqlname\fR_hosts". 227f3bc92a4Schristos# 228f3bc92a4Schristos# Note: with this form, the passwords for the PostgreSQL sources 229f3bc92a4Schristos# are written in main.cf, which is normally world-readable. 230f3bc92a4Schristos# Support for this form will be removed in a future Postfix 231f3bc92a4Schristos# version. 23241fbaed0Stron# OBSOLETE QUERY INTERFACES 23341fbaed0Stron# .ad 23441fbaed0Stron# .fi 23541fbaed0Stron# This section describes query interfaces that are deprecated 23641fbaed0Stron# as of Postfix 2.2. Please migrate to the new \fBquery\fR 23741fbaed0Stron# interface as the old interfaces are slated to be phased 23841fbaed0Stron# out. 23941fbaed0Stron# .IP "\fBselect_function\fR" 24041fbaed0Stron# This parameter specifies a database function name. Example: 24141fbaed0Stron# .nf 24241fbaed0Stron# select_function = my_lookup_user_alias 24341fbaed0Stron# .fi 24441fbaed0Stron# 24541fbaed0Stron# This is equivalent to: 24641fbaed0Stron# .nf 24741fbaed0Stron# query = SELECT my_lookup_user_alias('%s') 24841fbaed0Stron# .fi 24941fbaed0Stron# 25041fbaed0Stron# This parameter overrides the legacy table-related fields (described 25141fbaed0Stron# below). With Postfix versions prior to 2.2, it also overrides the 25241fbaed0Stron# \fBquery\fR parameter. Starting with Postfix 2.2, the \fBquery\fR 25341fbaed0Stron# parameter has highest precedence, and the \fBselect_function\fR 25441fbaed0Stron# parameter is deprecated. 25541fbaed0Stron# .PP 25641fbaed0Stron# The following parameters (with lower precedence than the 25741fbaed0Stron# \fBselect_function\fR interface described above) can be used to 25841fbaed0Stron# build the SQL select statement as follows: 25941fbaed0Stron# 26041fbaed0Stron# .nf 26141fbaed0Stron# SELECT [\fBselect_field\fR] 26241fbaed0Stron# FROM [\fBtable\fR] 26341fbaed0Stron# WHERE [\fBwhere_field\fR] = '%s' 26441fbaed0Stron# [\fBadditional_conditions\fR] 26541fbaed0Stron# .fi 26641fbaed0Stron# 26741fbaed0Stron# The specifier %s is replaced with each lookup by the lookup key 26841fbaed0Stron# and is escaped so if it contains single quotes or other odd 26941fbaed0Stron# characters, it will not cause a parse error, or worse, a security 27041fbaed0Stron# problem. 27141fbaed0Stron# 27241fbaed0Stron# Starting with Postfix 2.2, this interface is obsoleted by the more 27341fbaed0Stron# general \fBquery\fR interface described above. If higher precedence 27441fbaed0Stron# the \fBquery\fR or \fBselect_function\fR parameters described above 27541fbaed0Stron# are defined, the parameters described here are ignored. 27641fbaed0Stron# .IP "\fBselect_field\fR" 27741fbaed0Stron# The SQL "select" parameter. Example: 27841fbaed0Stron# .nf 27941fbaed0Stron# \fBselect_field\fR = forw_addr 28041fbaed0Stron# .fi 28141fbaed0Stron# .IP "\fBtable\fR" 28241fbaed0Stron# The SQL "select .. from" table name. Example: 28341fbaed0Stron# .nf 28441fbaed0Stron# \fBtable\fR = mxaliases 28541fbaed0Stron# .fi 28641fbaed0Stron# .IP "\fBwhere_field\fR 28741fbaed0Stron# The SQL "select .. where" parameter. Example: 28841fbaed0Stron# .nf 28941fbaed0Stron# \fBwhere_field\fR = alias 29041fbaed0Stron# .fi 29141fbaed0Stron# .IP "\fBadditional_conditions\fR 29241fbaed0Stron# Additional conditions to the SQL query. Example: 29341fbaed0Stron# .nf 29441fbaed0Stron# \fBadditional_conditions\fR = AND status = 'paid' 29541fbaed0Stron# .fi 29641fbaed0Stron# SEE ALSO 29741fbaed0Stron# postmap(1), Postfix lookup table manager 29841fbaed0Stron# postconf(5), configuration parameters 29941fbaed0Stron# ldap_table(5), LDAP lookup tables 30041fbaed0Stron# mysql_table(5), MySQL lookup tables 301ff6d749dStron# sqlite_table(5), SQLite lookup tables 30241fbaed0Stron# README FILES 30341fbaed0Stron# .ad 30441fbaed0Stron# .fi 30541fbaed0Stron# Use "\fBpostconf readme_directory\fR" or 30641fbaed0Stron# "\fBpostconf html_directory\fR" to locate this information. 30741fbaed0Stron# .na 30841fbaed0Stron# .nf 30941fbaed0Stron# DATABASE_README, Postfix lookup table overview 31041fbaed0Stron# PGSQL_README, Postfix PostgreSQL client guide 31141fbaed0Stron# LICENSE 31241fbaed0Stron# .ad 31341fbaed0Stron# .fi 31441fbaed0Stron# The Secure Mailer license must be distributed with this software. 31541fbaed0Stron# HISTORY 31641fbaed0Stron# PgSQL support was introduced with Postfix version 2.1. 31741fbaed0Stron# AUTHOR(S) 31841fbaed0Stron# Based on the MySQL client by: 31941fbaed0Stron# Scott Cotton, Joshua Marcus 32041fbaed0Stron# IC Group, Inc. 32141fbaed0Stron# 32241fbaed0Stron# Ported to PostgreSQL by: 32341fbaed0Stron# Aaron Sethman 32441fbaed0Stron# 32541fbaed0Stron# Further enhanced by: 32641fbaed0Stron# Liviu Daia 32741fbaed0Stron# Institute of Mathematics of the Romanian Academy 32841fbaed0Stron# P.O. BOX 1-764 32941fbaed0Stron# RO-014700 Bucharest, ROMANIA 33041fbaed0Stron#-- 331