SQLITE_TABLE(5)
π SQLITE_TABLE(5) π
okay bestie, we're doing this. this is the sqlite_table page β it's a File Formats Manual situation, and it's literally all about Postfix SQLite configuration. grab a snack, we're going in π
β¨ NAME β¨
sqlite_table β Postfix SQLite configuration. that's it, that's the name, short and iconic π
πΈ SYNOPSIS πΈ
postmap -q "string" sqlite:/etc/postfix/filename
postmap -q - sqlite:/etc/postfix/filename <inputfile
π¦ DESCRIPTION π¦
so the Postfix mail system uses optional tables for address rewriting or mail routing, right? and those tables are usually hanging out in lmdb:, cdb:, hash:, or dbm: format.
but β and this is the fun part β alternatively, lookup tables can be specified as SQLite databases. π
to find out what types of lookup tables your Postfix system actually supports, run postconf -m. like, go check, it's free.
in order to use SQLite lookups, you define an SQLite source as a lookup table in main.cf, for example:
alias_maps = sqlite:/etc/postfix/sqlite-aliases.cf
and the file /etc/postfix/sqlite-aliases.cf has the same format as the Postfix main.cf file, and can specify the parameters described below. so cozy, so consistent π
π«Ά LIST MEMBERSHIP π«Ά
this section is important, don't scroll past it, i'm serious π
when using SQL to store lists such as $mynetworks, $mydestination, $relay_domains, $local_recipient_maps, etc., it is important to understand that the table must store each list member as a separate key. the table lookup verifies the existence of the key. (see "Postfix lists versus tables" in the DATABASE_README document for a whole discussion, if you want the deep lore.)
Do NOT create tables that return the full list of domains in$mydestinationor$relay_domainsetc., or IP addresses in$mynetworks. like genuinely don't, that's the trap.
DO create tables with each matching item as a key and with an arbitrary value. with SQL databases it is not uncommon to return the key itself or a constant value β that's totally fine and lowkey the move.
π SQLITE PARAMETERS π
dbpathβ the SQLite database file location. example:
dbpath = customer_database
queryβ the SQL query template used to search the database, where%sis a substitute for the address Postfix is trying to resolve, e.g.
query = SELECT replacement FROM aliases WHERE mailbox = '%s'
this parameter supports the following '%' expansions:
%%β replaced by a literal'%'character.%sβ replaced by the input key. SQL quoting is used to make sure that the input key does not add unexpected metacharacters. (safety first, always π)%uβ when the input key is an address of the form user@domain,%uis replaced by the SQL quoted local part of the address. otherwise,%uis replaced by the entire search string. if the localpart is empty, the query is suppressed and returns no results.%dβ when the input key is an address of the form user@domain,%dis replaced by the SQL quoted domain part of the address. otherwise, the query is suppressed and returns no results.%[SUD]β the upper-case equivalents of the above expansions behave in thequeryparameter identically to their lower-case counter-parts. with theresult_formatparameter (see below), they expand the input key rather than the result value. cute, right?%[1-9]β the patterns%1,%2, ...%9are replaced by the corresponding most significant component of the input key's domain. if the input key isuser@mail.example.com, then%1iscom,%2isexampleand%3ismail. if the input key is unqualified or does not have enough domain components to satisfy all the specified patterns, the query is suppressed and returns no results.
the domain parameter described below limits the input keys to addresses in matching domains. when the domain parameter is non-empty, SQL queries for unqualified addresses or addresses in non-matching domains are suppressed and return no results.
this parameter is available with Postfix 2.2. in prior releases the SQL query was built from the separate parameters: select_field, table, where_field and additional_conditions. the mapping from the old parameters to the equivalent query is:
SELECT [select_field]
FROM [table]
WHERE [where_field] = '%s'
[additional_conditions]
the '%s' in the WHERE clause expands to the escaped search string. with Postfix 2.2 these legacy parameters are used if the query parameter is not specified.
NOTE: DO NOT put quotes around the query parameter. i'm not kidding, don't do it π
result_format(default:%s) β format template applied to result attributes. most commonly used to append (or prepend) text to the result. this parameter supports the following'%'expansions:%%β replaced by a literal'%'character.%sβ replaced by the value of the result attribute. when result is empty it is skipped.%uβ when the result attribute value is an address of the form user@domain,%uis replaced by the local part of the address. when the result has an empty localpart it is skipped.%dβ when a result attribute value is an address of the form user@domain,%dis replaced by the domain part of the attribute value. when the result is unqualified it is skipped.%[SUD1-9]β the upper-case and decimal digit expansions interpolate the parts of the input key rather than the result. their behavior is identical to that described withquery, and in fact because the input key is known in advance, queries whose key does not contain all the information specified in the result template are suppressed and return no results.
for example, using result_format = smtp:[%s] allows one to use a mailHost attribute as the basis of a transport(5) table. after applying the result format, multiple values are concatenated as comma separated strings. the expansion_limit and parameter explained below allows one to restrict the number of values in the result, which is especially useful for maps that must return at most one value.
the default value %s specifies that each result value should be used as is.
this parameter is available with Postfix 2.2 and later.
NOTE: DO NOT put quotes around the result format! seriously. bestie. no quotes.
domain(default: no domain list) β this is a list of domain names, paths to files, or"type:table"databases. when specified, only fully qualified search keys with a non-empty localpart and a matching domain are eligible for lookup:'user'lookups, bare domain lookups and"@domain"lookups are not performed. this can significantly reduce the query load on the SQLite server. slay for performance β¨
domain = postfix.org, hash:/etc/postfix/searchdomains
it is best not to use SQL to store the domains eligible for SQL lookups. (iykyk)
this parameter is available with Postfix 2.2 and later.
NOTE: DO NOT define this parameter for local(8) aliases, because the input keys are always unqualified.
expansion_limit(default:0) β a limit on the total number of result elements returned (as a comma separated list) by a lookup against the map. a setting of zero disables the limit. lookups fail with a temporary error if the limit is exceeded. setting the limit to1ensures that lookups do not return multiple values. one and done energy π
π OBSOLETE MAIN.CF PARAMETERS π
for compatibility with other Postfix lookup tables, SQLite parameters can also be defined in main.cf. in order to do that, specify as SQLite source a name that doesn't begin with a slash or a dot. the SQLite parameters will then be accessible as the name you've given the source in its definition, an underscore, and the name of the parameter.
for example, if the map is specified as "sqlite:sqlitename", the parameter "query" would be defined in main.cf as "sqlitename_query". see, it's just a little name-glue situation π
π OBSOLETE QUERY INTERFACE π
okay this section describes an interface that is deprecated as of Postfix 2.2. it is replaced by the more general query interface described above. if the query parameter is defined, the legacy parameters described here are ignored. please migrate to the new interface as the legacy interface may be removed in a future release. (not me warning you twice π)
the following parameters can be used to fill in a SELECT template statement of the form:
SELECT [select_field]
FROM [table]
WHERE [where_field] = '%s'
[additional_conditions]
the specifier %s is replaced by the search string, and is escaped so if it contains single quotes or other odd characters, it will not cause a parse error, or worse, a security problem. π₯ (yes that's a real warning, respect it)
select_fieldβ the SQL "select" parameter. example:
select_field = forw_addr
tableβ the SQL "select .. from" table name. example:
table = mxaliases
where_fieldβ the SQL "select .. where" parameter. example:
where_field = alias
additional_conditionsβ additional conditions to the SQL query. example:
additional_conditions = AND status = 'paid'
π SEE ALSO π
postmap(1), Postfix lookup table maintenancepostconf(5), configuration parametersldap_table(5), LDAP lookup tablesmysql_table(5), MySQL lookup tablespgsql_table(5), PostgreSQL lookup tables
π§ README FILES π§
use "postconf readme_directory" or "postconf html_directory" to locate this information. go on, the docs are right there waiting for you β¨
DATABASE_README, Postfix lookup table overviewSQLITE_README, Postfix SQLITE howto
π LICENSE π
The Secure Mailer license must be distributed with this software. (legal stuff, but make it fashion π )
β HISTORY β
SQLite support was introduced with Postfix version 2.8. iconic behavior tbh.
π AUTHOR(S) π
Original implementation by: Axel Steiner
and that's the whole page, bestie!! πβ¨ππ¦πΈ this was SQLITE_TABLE(5) from the File Formats Manual, and yes it really is that iconic. mwah, go configure something. π«Ά
β SQLITE_TABLE(5), signing off ππ
π¦ where this page comes from
- alpine 3.24: postfix-doc 3.11.7-r0 Β· IPL-1.0 EPL-2.0
- arch rolling: postfix-sqlite 3.11.7-1 Β· EPL-2.0 OR IPL-1.0 AND BSD-4-Clause-UC
- nixos 26.05: postfix 3.11.7
- nixpkgs unstable: postfix 3.11.7
- ubuntu stonking: postfix 3.11.7-1ubuntu2
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms