Home | History | Annotate | Line # | Download | only in html
pgsql_table.5.html revision 1.1.1.9
      1 <!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN"
      2         "https://www.w3.org/TR/html4/loose.dtd">
      3 <html> <head>
      4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
      5 <link rel='stylesheet' type='text/css' href='postfix-doc.css'>
      6 <title> Postfix manual - pgsql_table(5) </title>
      7 </head> <body> <pre>
      8 PGSQL_TABLE(5)                                                  PGSQL_TABLE(5)
      9 
     10 <b><a name="name">NAME</a></b>
     11        pgsql_table - Postfix PostgreSQL client configuration
     12 
     13 <b><a name="synopsis">SYNOPSIS</a></b>
     14        <b>postmap -q "</b><i>string</i><b>" <a href="pgsql_table.5.html">pgsql</a>:/etc/postfix/</b><i>filename</i>
     15 
     16        <b>postmap -q - <a href="pgsql_table.5.html">pgsql</a>:/etc/postfix/</b><i>filename</i> &lt;<i>inputfile</i>
     17 
     18 <b><a name="description">DESCRIPTION</a></b>
     19        The  Postfix  mail system uses optional tables for address rewriting or
     20        mail routing. These tables are usually in <b>dbm</b> or <b>db</b> format.
     21 
     22        Alternatively, lookup tables can be specified as PostgreSQL  databases.
     23        In  order  to  use  PostgreSQL lookups, define a PostgreSQL source as a
     24        lookup table in <a href="postconf.5.html">main.cf</a>, for example:
     25            <a href="postconf.5.html#alias_maps">alias_maps</a> = <a href="pgsql_table.5.html">pgsql</a>:/etc/postfix/pgsql-aliases.cf
     26 
     27        The file /etc/postfix/pgsql-aliases.cf has the same format as the Post-
     28        fix <a href="postconf.5.html">main.cf</a> file, and can specify the parameters described below.
     29 
     30 <b><a name="list_membership">LIST MEMBERSHIP</a></b>
     31        When  using  SQL  to  store  lists such as $<a href="postconf.5.html#mynetworks">mynetworks</a>, $<a href="postconf.5.html#mydestination">mydestination</a>,
     32        $<a href="postconf.5.html#relay_domains">relay_domains</a>, $<a href="postconf.5.html#local_recipient_maps">local_recipient_maps</a>, etc., it is important to  under-
     33        stand that the table must store each list member as a separate key. The
     34        table lookup verifies the *existence* of the key.  See  "Postfix  lists
     35        versus tables" in the <a href="DATABASE_README.html">DATABASE_README</a> document for a discussion.
     36 
     37        Do  NOT create tables that return the full list of domains in $<a href="postconf.5.html#mydestination">mydesti</a>-
     38        <a href="postconf.5.html#mydestination">nation</a> or $<a href="postconf.5.html#relay_domains">relay_domains</a> etc., or IP addresses in $<a href="postconf.5.html#mynetworks">mynetworks</a>.
     39 
     40        DO create tables with each matching item as a key and with an arbitrary
     41        value.  With  SQL databases it is not uncommon to return the key itself
     42        or a constant value.
     43 
     44 <b><a name="pgsql_parameters">PGSQL PARAMETERS</a></b>
     45        <b>hosts</b>  The hosts that Postfix will try to connect to  and  query  from.
     46               Besides  a  PostgreSQL connection URI, this setting supports the
     47               historical forms  <b>unix:/</b><i>pathname</i>  for  UNIX-domain  sockets  and
     48               <b>inet:</b><i>host:port</i>  for  TCP  connections, where the <b>unix:</b> and <b>inet:</b>
     49               prefixes are accepted and ignored for  backwards  compatibility.
     50               Examples:
     51                   hosts = postgresql://username (a] example.com/<i>databasename</i>?sslmode=require
     52                   hosts = postgres://user:secret@localhost
     53                   hosts = inet:host1.some.domain inet:host2.some.domain:port
     54                   hosts = host1.some.domain host2.some.domain:port
     55                   hosts = unix:/file/name
     56 
     57               See   <a href="https://www.postgresql.org/docs/current/libpq-connect.html">https://www.postgresql.org/docs/current/libpq-connect.html</a>
     58               for the supported connection URI syntax.
     59 
     60               The hosts are tried in random order. The connections  are  auto-
     61               matically  closed  after  being idle for about 1 minute, and are
     62               re-opened as necessary. See <b>idle_interval</b> for details.
     63 
     64               NOTE: if the <b>hosts</b> setting  specifies  a  PostgreSQL  connection
     65               URI, the Postfix PostgreSQL client will ignore the <b>dbname</b>, <b>user</b>,
     66               and <b>password</b> settings for that connection.
     67 
     68               NOTE: if the <b>hosts</b> setting specifies  one  server,  this  client
     69               assumes  that  the  target is a load balancer and will reconnect
     70               immediately after a  single  failure,  instead  of  failing  all
     71               requests  temporarily. With older versions of this client, spec-
     72               ify the same server twice.
     73 
     74        <b>user</b>
     75 
     76        <b>password</b>
     77               The user name and password to log into the pgsql server.   Exam-
     78               ple:
     79                   user = someone
     80                   password = some_password
     81 
     82               The <b>user</b> and <b>password</b> settings are ignored for <b>hosts</b> connections
     83               that are specified as an URI.
     84 
     85        <b>dbname</b> The database name on the servers. Example:
     86                   dbname = customer_database
     87 
     88               The <b>dbname</b> setting is ignored for  <b>hosts</b>  connections  that  are
     89               specified as an URI.
     90 
     91               The <b>dbname</b> setting is required with Postfix 3.10 and later, when
     92               <b>hosts</b> specifies any non-URI connection; it  is  always  required
     93               with earlier Postfix versions.
     94 
     95        <b>encoding</b>
     96               The  encoding  used  by the database client. The default setting
     97               is:
     98                   encoding = UTF8
     99 
    100               Historically, the database client was hard coded to  use  LATIN1
    101               in an attempt to disable multibyte character support.
    102 
    103               This feature is available in Postfix 3.8 and later.
    104 
    105        <b>idle_interval (default: 60)</b>
    106               The  number  of  seconds after which an idle database connection
    107               will be closed.
    108 
    109               This feature is available in Postfix 3.9 and later.
    110 
    111        <b>retry_interval (default: 60)</b>
    112               The number of seconds that a database connection will be skipped
    113               after an error.
    114 
    115               NOTE:  if  the  <b>hosts</b>  setting specifies one server, this client
    116               assumes that the target is a load balancer  and  will  reconnect
    117               immediately  after  a  single  failure,  instead  of failing all
    118               requests temporarily. With older versions of this client,  spec-
    119               ify the same server twice.
    120 
    121               This feature is available in Postfix 3.9 and later.
    122 
    123        <b>query</b>  The  SQL query template used to search the database, where <b>%s</b> is
    124               a substitute for the address Postfix is trying to resolve,  e.g.
    125                   query = SELECT replacement FROM aliases WHERE mailbox = '%s'
    126 
    127               This parameter supports the following '%' expansions:
    128 
    129               <b>%%</b>     This is replaced by a literal '%' character. (Postfix 2.2
    130                      and later)
    131 
    132               <b>%s</b>     This is replaced by the input key.  SQL quoting  is  used
    133                      to  make  sure that the input key does not add unexpected
    134                      metacharacters.
    135 
    136               <b>%u</b>     When the input key is an address of the form user@domain,
    137                      <b>%u</b>  is  replaced  by  the  SQL  quoted  local part of the
    138                      address.  Otherwise, <b>%u</b> is replaced by the entire  search
    139                      string.   If  the  localpart  is empty, the query is sup-
    140                      pressed and returns no results.
    141 
    142               <b>%d</b>     When the input key is an address of the form user@domain,
    143                      <b>%d</b>  is  replaced  by  the  SQL  quoted domain part of the
    144                      address.  Otherwise, the query is suppressed and  returns
    145                      no results.
    146 
    147               <b>%[SUD]</b> The upper-case equivalents of the above expansions behave
    148                      in the <b>query</b> parameter identically  to  their  lower-case
    149                      counter-parts.   With  the  <b>result_format</b>  parameter (see
    150                      below), they expand the input key rather than the  result
    151                      value.
    152 
    153                      The  above  %S,  %U  and %D expansions are available with
    154                      Postfix 2.2 and later
    155 
    156               <b>%[1-9]</b> The patterns %1, %2, ... %9 are replaced  by  the  corre-
    157                      sponding  most  significant  component of the input key's
    158                      domain. If the input key is  <i>user (a] mail.example.com</i>,  then
    159                      %1 is <b>com</b>, %2 is <b>example</b> and %3 is <b>mail</b>. If the input key
    160                      is unqualified or does not have enough domain  components
    161                      to  satisfy all the specified patterns, the query is sup-
    162                      pressed and returns no results.
    163 
    164                      The above %1, ... %9 expansions are available with  Post-
    165                      fix 2.2 and later
    166 
    167               The  <b>domain</b>  parameter  described below limits the input keys to
    168               addresses in matching domains.  When  the  <b>domain</b>  parameter  is
    169               non-empty, SQL queries for unqualified addresses or addresses in
    170               non-matching domains are suppressed and return no results.
    171 
    172               The precedence of this parameter has changed with  Postfix  2.2,
    173               in  prior  releases  the precedence was, from highest to lowest,
    174               <b>select_function</b>, <b>query</b>, <b>select_field</b>, ...
    175 
    176               With Postfix 2.2 the <b>query</b> parameter has highest precedence, see
    177               OBSOLETE QUERY INTERFACES below.
    178 
    179               NOTE: DO NOT put quotes around the <b>query</b> parameter.
    180 
    181        <b>result_format (default: %s</b>)
    182               Format template applied to result attributes. Most commonly used
    183               to append (or prepend) text to the result. This  parameter  sup-
    184               ports the following '%' expansions:
    185 
    186               <b>%%</b>     This is replaced by a literal '%' character.
    187 
    188               <b>%s</b>     This  is  replaced  by the value of the result attribute.
    189                      When result is empty it is skipped.
    190 
    191               <b>%u</b>     When the result attribute value is an address of the form
    192                      user@domain,  <b>%u</b>  is  replaced  by  the local part of the
    193                      address. When the result has an  empty  localpart  it  is
    194                      skipped.
    195 
    196               <b>%d</b>     When  a  result attribute value is an address of the form
    197                      user@domain, <b>%d</b> is replaced by the  domain  part  of  the
    198                      attribute  value.  When  the  result is unqualified it is
    199                      skipped.
    200 
    201               <b>%[SUD1-9]</b>
    202                      The upper-case and decimal digit  expansions  interpolate
    203                      the  parts of the input key rather than the result. Their
    204                      behavior is identical to that described with  <b>query</b>,  and
    205                      in  fact  because  the  input  key  is  known in advance,
    206                      queries whose key does not contain  all  the  information
    207                      specified  in  the  result  template  are  suppressed and
    208                      return no results.
    209 
    210               For example, using "result_format = <a href="smtp.8.html">smtp</a>:[%s]" allows one to use
    211               a mailHost attribute as the basis of a <a href="transport.5.html">transport(5)</a> table. After
    212               applying the result format, multiple values are concatenated  as
    213               comma  separated  strings.  The  expansion_limit  and  parameter
    214               explained below allows one to restrict the number of  values  in
    215               the result, which is especially useful for maps that must return
    216               at most one value.
    217 
    218               The default value <b>%s</b> specifies that each result value should  be
    219               used as is.
    220 
    221               This parameter is available with Postfix 2.2 and later.
    222 
    223               NOTE: DO NOT put quotes around the result format!
    224 
    225        <b>domain (default: no domain list)</b>
    226               This  is a list of domain names, paths to files, or "<a href="DATABASE_README.html">type:table</a>"
    227               databases. When specified, only fully qualified search keys with
    228               a  *non-empty*  localpart and a matching domain are eligible for
    229               lookup:  'user'  lookups,  bare  domain  lookups  and  "@domain"
    230               lookups  are  not  performed.  This can significantly reduce the
    231               query load on the PostgreSQL server.
    232                   domain = postfix.org, <a href="DATABASE_README.html#types">hash</a>:/etc/postfix/searchdomains
    233 
    234               It is best not to use SQL to store the domains eligible for  SQL
    235               lookups.
    236 
    237               This parameter is available with Postfix 2.2 and later.
    238 
    239               NOTE: DO NOT define this parameter for <a href="local.8.html">local(8)</a> aliases, because
    240               the input keys are always unqualified.
    241 
    242        <b>expansion_limit (default: 0)</b>
    243               A limit on the total number of result elements  returned  (as  a
    244               comma separated list) by a lookup against the map.  A setting of
    245               zero disables the limit. Lookups fail with a temporary error  if
    246               the  limit  is  exceeded.   Setting  the limit to 1 ensures that
    247               lookups do not return multiple values.
    248 
    249 <b>OBSOLETE MAIN.CF PARAMETERS</b>
    250        For compatibility with other Postfix lookup tables, PostgreSQL  parame-
    251        ters  can  also be defined in <a href="postconf.5.html">main.cf</a>.  In order to do that, specify as
    252        PostgreSQL source a name that doesn't begin with a slash or a dot.  The
    253        PostgreSQL  parameters will then be accessible as the name you've given
    254        the source in its definition, an underscore, and the name of the param-
    255        eter.   For  example, if the map is specified as "<a href="pgsql_table.5.html">pgsql</a>:<i>pgsqlname</i>", the
    256        parameter "hosts" would be defined in <a href="postconf.5.html">main.cf</a> as "<i>pgsqlname</i>_hosts".
    257 
    258        Note: with this form, the passwords  for  the  PostgreSQL  sources  are
    259        written in <a href="postconf.5.html">main.cf</a>, which is normally world-readable.  Support for this
    260        form will be removed in a future Postfix version.
    261 
    262 <b><a name="obsolete_query_interfaces">OBSOLETE QUERY INTERFACES</a></b>
    263        This section describes query interfaces that are deprecated as of Post-
    264        fix  2.2.   Please migrate to the new <b>query</b> interface as the old inter-
    265        faces are slated to be phased out.
    266 
    267        <b>select_function</b>
    268               This parameter specifies a database function name. Example:
    269                   select_function = my_lookup_user_alias
    270 
    271               This is equivalent to:
    272                   query = SELECT my_lookup_user_alias('%s')
    273 
    274               This  parameter  overrides  the  legacy   table-related   fields
    275               (described  below).  With Postfix versions prior to 2.2, it also
    276               overrides the <b>query</b> parameter. Starting with  Postfix  2.2,  the
    277               <b>query</b>  parameter has highest precedence, and the <b>select_function</b>
    278               parameter is deprecated.
    279 
    280        The following parameters (with lower precedence than  the  <b>select_func-</b>
    281        <b>tion</b>  interface  described  above)  can be used to build the SQL select
    282        statement as follows:
    283 
    284            SELECT [<b>select_field</b>]
    285            FROM [<b>table</b>]
    286            WHERE [<b>where_field</b>] = '%s'
    287                  [<b>additional_conditions</b>]
    288 
    289        The specifier %s is replaced with each lookup by the lookup key and  is
    290        escaped  so  if  it  contains single quotes or other odd characters, it
    291        will not cause a parse error, or worse, a security problem.
    292 
    293        Starting with Postfix 2.2, this interface is obsoleted by the more gen-
    294        eral <b>query</b> interface described above. If higher precedence the <b>query</b> or
    295        <b>select_function</b> parameters described above are defined, the  parameters
    296        described here are ignored.
    297 
    298        <b>select_field</b>
    299               The SQL "select" parameter. Example:
    300                   <b>select_field</b> = forw_addr
    301 
    302        <b>table</b>  The SQL "select .. from" table name. Example:
    303                   <b>table</b> = mxaliases
    304 
    305        <b>where_field</b>
    306               The SQL "select .. where" parameter. Example:
    307                   <b>where_field</b> = alias
    308 
    309        <b>additional_conditions</b>
    310               Additional conditions to the SQL query. Example:
    311                   <b>additional_conditions</b> = AND status = 'paid'
    312 
    313 <b><a name="see_also">SEE ALSO</a></b>
    314        <a href="postmap.1.html">postmap(1)</a>, Postfix lookup table manager
    315        <a href="postconf.5.html">postconf(5)</a>, configuration parameters
    316        <a href="ldap_table.5.html">ldap_table(5)</a>, LDAP lookup tables
    317        <a href="mysql_table.5.html">mysql_table(5)</a>, MySQL lookup tables
    318        <a href="sqlite_table.5.html">sqlite_table(5)</a>, SQLite lookup tables
    319 
    320 <b><a name="readme_files">README FILES</a></b>
    321        <a href="DATABASE_README.html">DATABASE_README</a>, Postfix lookup table overview
    322        <a href="PGSQL_README.html">PGSQL_README</a>, Postfix PostgreSQL client guide
    323 
    324 <b><a name="license">LICENSE</a></b>
    325        The Secure Mailer license must be distributed with this software.
    326 
    327 <b><a name="history">HISTORY</a></b>
    328        PgSQL support was introduced with Postfix version 2.1.
    329 
    330 <b>AUTHOR(S)</b>
    331        Based on the MySQL client by:
    332        Scott Cotton, Joshua Marcus
    333        IC Group, Inc.
    334 
    335        Ported to PostgreSQL by:
    336        Aaron Sethman
    337 
    338        Further enhanced by:
    339        Liviu Daia
    340        Institute of Mathematics of the Romanian Academy
    341        P.O. BOX 1-764
    342        RO-014700 Bucharest, ROMANIA
    343 
    344                                                                 PGSQL_TABLE(5)
    345 </pre> </body> </html>
    346