Postfix memcached Howto


Introduction

The Postfix memcache map type allows you to hook up Postfix to a memcached server. This implementation allows for multiple memcached servers: you can use one for a virtual(5) table, two for an access(5) table, and three for an aliases (5) table if you want.

The memcache map type can be used to reduce the load on another map type, e.g. pgsql. By placing the memcache map before the pgsql map, a key not found in the memcache will fall through to the database. You'll need to figure out a way to reverse populate the cache from the database yourself.

This map type can be seen as an alternative to the proxymap(8) service.

Building Postfix with memcached support

In order to build Postfix with memcached map support, you specify -DHAS_MEMCACHE, and the directory where libmemcache resides (both memcache.c and memcache.h are used.)

For example:

% make tidy
% make -f Makefile.init makefiles \
        'CCARGS=-DHAS_MEMCACHE -I/opt/libmemcache'

Then just run 'make'.

Configuring memcached lookup tables

Once Postfix is built with memcache support, you can specify a map type in main.cf like this:

/etc/postfix/main.cf:
    alias_maps = memcache:/etc/postfix/memcache-aliases.cf

The file /etc/postfix/memcache-aliases.cf specifies lots of information telling postfix how to reference the memcache instance(s). For a complete description, see the memcache_table(5) manual page.

Example: local aliases

#
# memcache config file for local(8) aliases(5) lookups
#

#
# The memcached servers that Postfix will try to connect to
# If no servers are specified, localhost is used.
# If no port is specified, 11211 is used.

servers = mc01.some.domain mc02.some.domain

# The key_format to use. The default is just to use whatever postfix
# sends us. See memcache_table(5) for more details
key_format = %u:mail_alias

Credits