Postgres non-durable options Docker container.

Some weeks ago I was at Pycamp whit LeCoVi working on the Pyar website (check the link PyCamp is the best event ever!) and I showed him my configuration to speed-up django tests. Some days ago he asked me for the config. I think that it'is better to share it in my blog, so here I'm.

When you work with a framework like Django, to develop it with the same database that you run in production is a really good idea. It's really easy using docker-compose. And to speed up your tests you can configure postgres with its non-durable options.

Here my recipe to do it.

I'm using the oficial Postgres Docker image adding only some scripts:

FROM postgres:9.4.4
MAINTAINER gilgamezh <>


Here the content of I'm using an environment variable to enable or disable the non_durable settings:


    cp / /docker-entrypoint-initdb.d/

# run the default img entrypoint
/bin/sh / postgres

And here the script to change the Postgres configuration:


# setting non-durable options
echo "Configuring postgres non-durable options."
# no need to flush data to disk.
echo "fsync = off" >> /var/lib/postgresql/data/postgresql.conf
# no need to force WAL writes to disk on every commit.
echo "synchronous_commit = off" >> /var/lib/postgresql/data/postgresql.conf
# no need to guard against partial page writes.
echo "full_page_writes = off" >> /var/lib/postgresql/data/postgresql.conf

Then in my docker-compose.yml file I'm setting the POSTGRES_NON_DURABLE_SETTINGS variable:


With these changes my tests are running a lot faster. 🚀🚀🚀


Comments powered by Disqus