tmp-postgres: Start and stop a temporary postgres

[ bsd3, library, program, web ] [ Propose Tags ]

Start and stop a temporary postgres. See

[Skip to Readme]


Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees


Versions [RSS],,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
Change log
Dependencies ansi-wl-pprint, async, base (>=4.6 && <5), base64-bytestring, bytestring, containers, cryptohash-sha1, deepseq, directory, generic-monoid, port-utils, postgres-options (>=, postgresql-simple, process (>=, stm, temporary, tmp-postgres, transformers, unix [details]
License BSD-3-Clause
Copyright 2017-2019 Jonathan Fischoff
Author Jonathan Fischoff
Category Web
Home page
Source repo head: git clone
Uploaded by JonathanFischoff at 2019-12-29T07:20:55Z
Distributions NixOS:
Reverse Dependencies 4 direct, 1 indirect [details]
Executables with-cache-loop, soak-test
Downloads 33467 total (58 in the last 30 days)
Rating 2.25 (votes: 2) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2019-12-29 [all 1 reports]

Readme for tmp-postgres-

[back to package description]

Hackage Travis CI Status


tmp-postgres provides functions for creating a temporary postgres instance. By default it will create a temporary data directory and a temporary directory for a UNIX domain socket for postgres to listen on.

Here is an example using the expection safe 'with' function:

with $ \db -> bracket
  (connectPostgreSQL (toConnectionString db))
  close $
  \conn -> execute_ conn "CREATE TABLE foo (id int)"

To extend or override the defaults use withConfig (or startConfig).

tmp-postgres ultimately calls initdb (optionally) , postgres and createdb (optionally).

All of the command line, environment variables and configuration files that are generated by default for the respective executables can be extended.

In general tmp-postgres is useful if you want a clean temporary postgres and do not want to worry about clashing with an existing postgres instance (or needing to ensure postgres is already running).

Here are some different use cases for tmp-postgres and their respective configurations:

  • The default 'with' and 'start' functions can be used to make a sandboxed temporary database for testing.
  • By disabling initdb one could run a temporary isolated postgres on a base backup to test a migration.
  • By using the 'stopPostgres' and 'withRestart' functions one can test backup strategies.

WARNING!! Ubuntu's PostgreSQL installation does not put initdb on the PATH. We need to add it manually. The necessary binaries are in the /usr/lib/postgresql/VERSION/bin/ directory, and should be added to the PATH

echo "export PATH=$PATH:/usr/lib/postgresql/VERSION/bin/" >> /home/ubuntu/.bashrc



$ brew install postgres
$ stack install tmp-postgres


Ubuntu's PostgreSQL installation does not put initdb on the PATH. We need to add it manually.

$ sudo apt-get install postgresql-VERSION
$ echo "export PATH=$PATH:/usr/lib/postgresql/VERSION/bin/" >> /home/ubuntu/.bashrc
$ stack install tmp-postgres