1PGSQL_TABLE(5)                File Formats Manual               PGSQL_TABLE(5)
2
3
4

NAME

6       pgsql_table - Postfix PostgreSQL client configuration
7

SYNOPSIS

9       postmap -q "string" pgsql:/etc/postfix/filename
10
11       postmap -q - pgsql:/etc/postfix/filename <inputfile
12

DESCRIPTION

14       The  Postfix  mail system uses optional tables for address rewriting or
15       mail routing. These tables are usually in dbm or db format.
16
17       Alternatively, lookup tables can be specified as PostgreSQL  databases.
18       In  order  to  use  PostgreSQL lookups, define a PostgreSQL source as a
19       lookup table in main.cf, for example:
20           alias_maps = pgsql:/etc/postfix/pgsql-aliases.cf
21
22       The file /etc/postfix/pgsql-aliases.cf has the same format as the Post‐
23       fix main.cf file, and can specify the parameters described below.
24

LIST MEMBERSHIP

26       When using SQL to store lists such as $mynetworks, $mydestination, $re‐
27       lay_domains, $local_recipient_maps, etc., it is important to understand
28       that the table must store each list member as a separate key. The table
29       lookup verifies the *existence* of the key. See "Postfix  lists  versus
30       tables" in the DATABASE_README document for a discussion.
31
32       Do  NOT create tables that return the full list of domains in $mydesti‐
33       nation or $relay_domains etc., or IP addresses in $mynetworks.
34
35       DO create tables with each matching item as a key and with an arbitrary
36       value.  With  SQL databases it is not uncommon to return the key itself
37       or a constant value.
38

PGSQL PARAMETERS

40       hosts  The hosts that Postfix will try to connect to  and  query  from.
41              Besides  a  postgresql://  connection URI, this setting supports
42              the historical forms unix:/pathname for UNIX-domain sockets  and
43              inet:host:port  for  TCP  connections, where the unix: and inet:
44              prefixes are accepted and ignored for  backwards  compatibility.
45              Examples:
46                  hosts = postgresql://username@example.com/tablename?sslmode=require
47                  hosts = inet:host1.some.domain inet:host2.some.domain:port
48                  hosts = host1.some.domain host2.some.domain:port
49                  hosts = unix:/file/name
50
51              The  hosts  are tried in random order. The connections are auto‐
52              matically closed after being idle for about 1  minute,  and  are
53              re-opened as necessary.
54
55       user, password
56              The  user name and password to log into the pgsql server.  Exam‐
57              ple:
58                  user = someone
59                  password = some_password
60
61       dbname The database name on the servers. Example:
62                  dbname = customer_database
63
64       query  The SQL query template used to search the database, where %s  is
65              a substitute for the address Postfix is trying to resolve, e.g.
66                  query = SELECT replacement FROM aliases WHERE mailbox = '%s'
67
68              This parameter supports the following '%' expansions:
69
70              %%     This is replaced by a literal '%' character. (Postfix 2.2
71                     and later)
72
73              %s     This is replaced by the input key.  SQL quoting  is  used
74                     to  make  sure that the input key does not add unexpected
75                     metacharacters.
76
77              %u     When the input key is an address of the form user@domain,
78                     %u  is  replaced  by the SQL quoted local part of the ad‐
79                     dress.  Otherwise, %u is replaced by  the  entire  search
80                     string.   If  the  localpart  is empty, the query is sup‐
81                     pressed and returns no results.
82
83              %d     When the input key is an address of the form user@domain,
84                     %d  is  replaced by the SQL quoted domain part of the ad‐
85                     dress.  Otherwise, the query is suppressed and returns no
86                     results.
87
88              %[SUD] The upper-case equivalents of the above expansions behave
89                     in the query parameter identically  to  their  lower-case
90                     counter-parts.  With the result_format parameter (see be‐
91                     low), they expand the input key rather  than  the  result
92                     value.
93
94                     The  above  %S,  %U  and %D expansions are available with
95                     Postfix 2.2 and later
96
97              %[1-9] The patterns %1, %2, ... %9 are replaced  by  the  corre‐
98                     sponding  most  significant  component of the input key's
99                     domain. If the input key is  user@mail.example.com,  then
100                     %1 is com, %2 is example and %3 is mail. If the input key
101                     is unqualified or does not have enough domain  components
102                     to  satisfy all the specified patterns, the query is sup‐
103                     pressed and returns no results.
104
105                     The above %1, ... %9 expansions are available with  Post‐
106                     fix 2.2 and later
107
108              The  domain  parameter  described below limits the input keys to
109              addresses in matching domains.  When  the  domain  parameter  is
110              non-empty, SQL queries for unqualified addresses or addresses in
111              non-matching domains are suppressed and return no results.
112
113              The precedence of this parameter has changed with  Postfix  2.2,
114              in  prior  releases  the precedence was, from highest to lowest,
115              select_function, query, select_field, ...
116
117              With Postfix 2.2 the query parameter has highest precedence, see
118              OBSOLETE QUERY INTERFACES below.
119
120              NOTE: DO NOT put quotes around the query parameter.
121
122       result_format (default: %s)
123              Format template applied to result attributes. Most commonly used
124              to append (or prepend) text to the result. This  parameter  sup‐
125              ports the following '%' expansions:
126
127              %%     This is replaced by a literal '%' character.
128
129              %s     This  is  replaced  by the value of the result attribute.
130                     When result is empty it is skipped.
131
132              %u     When the result attribute value is an address of the form
133                     user@domain,  %u is replaced by the local part of the ad‐
134                     dress. When the result  has  an  empty  localpart  it  is
135                     skipped.
136
137              %d     When  a  result attribute value is an address of the form
138                     user@domain, %d is replaced by the domain part of the at‐
139                     tribute  value.  When  the  result  is  unqualified it is
140                     skipped.
141
142              %[SUD1-9]
143                     The upper-case and decimal digit  expansions  interpolate
144                     the  parts of the input key rather than the result. Their
145                     behavior is identical to that described with  query,  and
146                     in  fact  because  the  input  key  is  known in advance,
147                     queries whose key does not contain  all  the  information
148                     specified  in  the result template are suppressed and re‐
149                     turn no results.
150
151              For example, using "result_format = smtp:[%s]" allows one to use
152              a mailHost attribute as the basis of a transport(5) table. After
153              applying the result format, multiple values are concatenated  as
154              comma  separated  strings. The expansion_limit and parameter ex‐
155              plained below allows one to restrict the number of values in the
156              result,  which is especially useful for maps that must return at
157              most one value.
158
159              The default value %s specifies that each result value should  be
160              used as is.
161
162              This parameter is available with Postfix 2.2 and later.
163
164              NOTE: DO NOT put quotes around the result format!
165
166       domain (default: no domain list)
167              This  is a list of domain names, paths to files, or "type:table"
168              databases. When specified, only fully qualified search keys with
169              a  *non-empty*  localpart and a matching domain are eligible for
170              lookup:  'user'  lookups,  bare  domain  lookups  and  "@domain"
171              lookups  are  not  performed.  This can significantly reduce the
172              query load on the PostgreSQL server.
173                  domain = postfix.org, hash:/etc/postfix/searchdomains
174
175              It is best not to use SQL to store the domains eligible for  SQL
176              lookups.
177
178              This parameter is available with Postfix 2.2 and later.
179
180              NOTE: DO NOT define this parameter for local(8) aliases, because
181              the input keys are always unqualified.
182
183       expansion_limit (default: 0)
184              A limit on the total number of result elements  returned  (as  a
185              comma separated list) by a lookup against the map.  A setting of
186              zero disables the limit. Lookups fail with a temporary error  if
187              the  limit  is  exceeded.   Setting  the limit to 1 ensures that
188              lookups do not return multiple values.
189

OBSOLETE MAIN.CF PARAMETERS

191       For compatibility with other Postfix lookup tables, PostgreSQL  parame‐
192       ters  can  also be defined in main.cf.  In order to do that, specify as
193       PostgreSQL source a name that doesn't begin with a slash or a dot.  The
194       PostgreSQL  parameters will then be accessible as the name you've given
195       the source in its definition, an underscore, and the name of the param‐
196       eter.   For  example, if the map is specified as "pgsql:pgsqlname", the
197       parameter "hosts" would be defined in main.cf as "pgsqlname_hosts".
198
199       Note: with this form, the passwords  for  the  PostgreSQL  sources  are
200       written in main.cf, which is normally world-readable.  Support for this
201       form will be removed in a future Postfix version.
202

OBSOLETE QUERY INTERFACES

204       This section describes query interfaces that are deprecated as of Post‐
205       fix  2.2.   Please migrate to the new query interface as the old inter‐
206       faces are slated to be phased out.
207
208       select_function
209              This parameter specifies a database function name. Example:
210                  select_function = my_lookup_user_alias
211
212              This is equivalent to:
213                  query = SELECT my_lookup_user_alias('%s')
214
215              This parameter overrides the legacy  table-related  fields  (de‐
216              scribed  below).  With  Postfix  versions  prior to 2.2, it also
217              overrides the query parameter. Starting with  Postfix  2.2,  the
218              query  parameter has highest precedence, and the select_function
219              parameter is deprecated.
220
221       The following parameters (with lower precedence than  the  select_func‐
222       tion  interface  described  above)  can be used to build the SQL select
223       statement as follows:
224
225           SELECT [select_field]
226           FROM [table]
227           WHERE [where_field] = '%s'
228                 [additional_conditions]
229
230       The specifier %s is replaced with each lookup by the lookup key and  is
231       escaped  so  if  it  contains single quotes or other odd characters, it
232       will not cause a parse error, or worse, a security problem.
233
234       Starting with Postfix 2.2, this interface is obsoleted by the more gen‐
235       eral query interface described above. If higher precedence the query or
236       select_function parameters described above are defined, the  parameters
237       described here are ignored.
238
239       select_field
240              The SQL "select" parameter. Example:
241                  select_field = forw_addr
242
243       table  The SQL "select .. from" table name. Example:
244                  table = mxaliases
245
246       where_field
247              The SQL "select .. where" parameter. Example:
248                  where_field = alias
249
250       additional_conditions
251              Additional conditions to the SQL query. Example:
252                  additional_conditions = AND status = 'paid'
253

SEE ALSO

255       postmap(1), Postfix lookup table manager
256       postconf(5), configuration parameters
257       ldap_table(5), LDAP lookup tables
258       mysql_table(5), MySQL lookup tables
259       sqlite_table(5), SQLite lookup tables
260

README FILES

262       Use  "postconf readme_directory" or "postconf html_directory" to locate
263       this information.
264       DATABASE_README, Postfix lookup table overview
265       PGSQL_README, Postfix PostgreSQL client guide
266

LICENSE

268       The Secure Mailer license must be distributed with this software.
269

HISTORY

271       PgSQL support was introduced with Postfix version 2.1.
272

AUTHOR(S)

274       Based on the MySQL client by:
275       Scott Cotton, Joshua Marcus
276       IC Group, Inc.
277
278       Ported to PostgreSQL by:
279       Aaron Sethman
280
281       Further enhanced by:
282       Liviu Daia
283       Institute of Mathematics of the Romanian Academy
284       P.O. BOX 1-764
285       RO-014700 Bucharest, ROMANIA
286
287
288
289                                                                PGSQL_TABLE(5)
Impressum