TABLE_POSTGRESQL(5)
β¨ table_postgresql β the vibe guide π
aka the TABLE_POSTGRESQL(5) page, from the File Formats Manual section of your local man setup π
πΈ NAME πΈ
table_postgresql β bestie, this is the format description for smtpd PostgreSQL tables π
π¦ DESCRIPTION π¦
Okay so. This manual page documents the file format of the PostgreSQL tables that the smtpd(8) mail daemon uses. That's it, that's the whole job, and it eats every time π
The format described here applies to tables as defined in smtpd.conf(5). iykyk
π POSTGRESQL TABLE π
A postgresql table lets you store usernames, passwords, aliases, and domains in a format that's shareable across various machines that support postgres(1). Cross-machine slay fr fr β¨
The table gets used by smtpd(8) when:
- it's authenticating a user π
- user information like user-id and/or home directory is required for a delivery π¬
- a domain lookup may be required π
- and/or it's looking for an alias π
A PostgreSQL table consists of one or more postgresql(1) databases with one or more tables. Nested. Layers. Iconic.
β οΈ Big one, bestie: if the table is used for authentication, the password should be encrypted using the crypt(3) function. Do not be out here storing plaintext, that's giving chaos π
Such passwords can be generated using the encrypt(1) utility or the smtpctl(8) encrypt command. Use them. Please. π«Ά
π POSTGRESQL TABLE CONFIG FILE π
The following configuration options are available:
conninfo host='host' user='user' password='password' dbname='dbname'β Connection info needed to connect to the PostgreSQL database. For example:
conninfo host='db.example.com' user='maildba' password='...' dbname='opensmtpdb'
query_alias SQL statementβ This is used to provide a query to look up aliases. The question mark is replaced with the appropriate data. For alias it is the left hand side of the SMTP address. This expects oneVARCHARto be returned with the user name the alias resolves to.query_credentials SQL statementβ This is used to provide a query for looking up user credentials. The question mark is replaced with the appropriate data. For credentials it is the left hand side of the SMTP address. The query expects that there are twoVARCHARSreturned, one with a user name and one with a password incrypt(3)format.query_domain SQL statementβ This is used to provide a query for looking up a domain. The question mark is replaced with the appropriate data. For the domain it would be the right hand side of the SMTP address. This expects oneVARCHARto be returned with a matching domain name.query_mailaddrmap SQL statementβ This is used to provide a query to look up senders. The question mark is replaced with the appropriate data. This expects oneVARCHARto be returned with the address the sender is allowed to send mails from.
A generic SQL statement would be something like:
query_ SELECT value FROM table WHERE key=$1;
^ this is the blueprint, bestie. memorise it π
π FILES π
/etc/mail/postgres.confβ Defaulttable-postgresql(5)configuration file. π
β EXAMPLES β
π§ GENERIC EXAMPLE π§
Example based on the OpenSMTPD FAQ: Building a Mail Server. The filtering part is excluded in this example. (Not here, not invited, filtered out π)
The configuration below is for a medium-size mail server which handles multiple domains with multiple virtual users and is based on several assumptions. One is that a single system user named vmail is used for all virtual users. This user needs to be created:
# useradd -g =uid -c "Virtual Mail" -d /var/vmail -s /sbin/nologin vmail
# mkdir /var/vmail
# chown vmail:vmail /var/vmail
PostgreSQL schema:
CREATE TABLE domains (
id SERIAL,
domain VARCHAR(255) NOT NULL DEFAULT ''
);
CREATE TABLE virtuals (
id SERIAL,
email VARCHAR(255) NOT NULL DEFAULT '',
destination VARCHAR(255) NOT NULL DEFAULT ''
);
CREATE TABLE credentials (
id SERIAL,
email VARCHAR(255) NOT NULL DEFAULT '',
password VARCHAR(255) NOT NULL DEFAULT ''
);
That can be populated as follows:
INSERT INTO domains VALUES (1, "example.com");
INSERT INTO domains VALUES (2, "example.net");
INSERT INTO domains VALUES (3, "example.org");
INSERT INTO virtuals VALUES (1, "abuse@example.com", "bob@example.com");
INSERT INTO virtuals VALUES (2, "postmaster@example.com", "bob@example.com");
INSERT INTO virtuals VALUES (3, "webmaster@example.com", "bob@example.com");
INSERT INTO virtuals VALUES (4, "bob@example.com", "vmail");
INSERT INTO virtuals VALUES (5, "abuse@example.net", "alice@example.net");
INSERT INTO virtuals VALUES (6, "postmaster@example.net", "alice@example.net");
INSERT INTO virtuals VALUES (7, "webmaster@example.net", "alice@example.net");
INSERT INTO virtuals VALUES (8, "alice@example.net", "vmail");
INSERT INTO credentials VALUES (1, "bob@example.com", "$2b$08$ANGFKBL.BnDLL0bUl7I6aumTCLRJSQluSQLuueWRG.xceworWrUIu");
INSERT INTO credentials VALUES (2, "alice@example.net", "$2b$08$AkHdB37kaj2NEoTcISHSYOCEBA5vyW1RcD8H1HG.XX0P/G1KIYwii");
/etc/mail/postgresql.conf
conninfo host='db.example.com' user='maildba' password='OpenSMTPDRules!' dbname='opensmtpdb'
query_alias SELECT destination FROM virtuals WHERE email=$1;
query_credentials SELECT email, password FROM credentials WHERE email=$1;
query_domain SELECT domain FROM domains WHERE domain=$1;
/etc/mail/smtpd.conf
table domains postgres:/etc/mail/postgres.conf
table virtuals postgres:/etc/mail/postgres.conf
table credentials postgres:/etc/mail/postgres.conf
listen on egress port 25 tls pki mail.example.com
listen on egress port 587 tls-require pki mail.example.com auth <credentials>
accept from any for domain <domains> virtual <virtuals> deliver to mbox
copy paste, hit enter, main character energy, periodt π
π¦ MOVING FROM POSTFIX (& POSTFIXADMIN) π¦
/etc/mail/postgres.conf
conninfo host='db.example.com' user='postfix' password='...' dbname='postfix'
query_alias SELECT destination FROM alias WHERE email=$1;
query_credentials SELECT username, password FROM mailbox WHERE username=$1;
query_domain SELECT domain FROM domain WHERE domain=$1;
The rest of the config remains the same. glow-up complete, no notes β¨
π TODO π
Documenting the following query options:
query_netaddr
query_userinfo
query_source
query_mailaddr
query_addrname
π«Ά Man page said "not me leaving these five undocumented", and honestly? relatable. someday bestie, someday.
π SEE ALSO π
encrypt(1), crypt(3), smtpd.conf(5), smtpctl(8), smtpd(8)
πΈ HISTORY πΈ
The first version of table_postgresql was written in 2016. It was converted to the stdio table protocol in 2024. a glow-up eight years in the making, we love to see it π
π AUTHORS π
table_postgresql was initially written by Gilles Chehade <gilles@poolp.org>. The conversion to the stdio table protocol was done by Omar Polo <op@openbsd.org>.
okay bestie that's the whole page π this lil cutie shipped with Debian and its page date is April 21, 2024 β that's the version/date info, folded in all cute at the end like a signature. mwah π«Άβ¨
π¦ where this page comes from
- alpine 3.24: opensmtpd-table-postgres-doc 1.1.1-r0 Β· ISC
- arch rolling: opensmtpd-table-postgres 1.1.1-1 Β· ISC
- debian trixie: opensmtpd-table-postgres 1.1.1-1+b1 Β· ISC
- nixos 26.05: opensmtpd-table-postgres 1.1.1
- nixpkgs unstable: opensmtpd-table-postgres 1.1.1
- ubuntu questing: opensmtpd-table-postgres 1.1.1-1
- ubuntu resolute: opensmtpd-table-postgres 1.1.1-1build1 Β· ISC
- ubuntu stonking: opensmtpd-table-postgres 1.1.1-1build1 Β· ISC
- Copyright (c) 2013 Eric Faurot <eric@openbsd.org>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms