tmp-postgres: Start and stop a temporary postgres

[ bsd3, library, web ] [ Propose Tags ]

tmp-postgres provides functions creating a temporary postgres instance.

By default it will create a temporary directory for the data, a random port for listening and a temporary directory for a UNIX domain socket.

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)"

MacOS and Linux are support. Windows is not.

Requires PostgreSQL 9.3+

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

[Skip to Readme]
Versions [faq] 0.1.0.0, 0.1.0.1, 0.1.0.2, 0.1.0.3, 0.1.0.4, 0.1.0.5, 0.1.0.6, 0.1.0.7, 0.1.0.8, 0.1.1.0, 0.1.1.1, 0.1.2.0, 0.1.2.1, 0.1.2.2, 0.2.0.0, 0.3.0.0, 0.3.0.1, 1.0.0.0, 1.0.0.1, 1.0.0.2, 1.0.1.0, 1.2.0.0, 1.2.0.1, 1.2.1.0, 1.3.0.0, 1.4.0.0, 1.5.0.0, 1.6.0.0, 1.7.0.0, 1.7.0.1, 1.7.1.0, 1.8.0.0, 1.9.0.0, 1.9.0.1, 1.9.0.2
Dependencies async, base (>=4.6 && <5), bytestring, containers, directory, either, generic-monoid, port-utils, postgres-options (>=0.2.0.0), postgresql-simple, process (>=1.2.0.0), temporary, transformers, unix [details]
License BSD-3-Clause
Copyright 2017-2019 Jonathan Fischoff
Author Jonathan Fischoff
Maintainer jonathangfischoff@gmail.com
Category Web
Home page https://github.com/jfischoff/tmp-postgres#readme
Source repo head: git clone https://github.com/jfischoff/tmp-postgres
Uploaded by JonathanFischoff at Fri Nov 8 17:09:06 UTC 2019
Distributions LTSHaskell:0.1.2.2, NixOS:1.4.0.0, Stackage:0.2.0.0
Downloads 5114 total (1010 in the last 30 days)
Rating (no votes yet) [estimated by rule of succession]
Your Rating
  • λ
  • λ
  • λ
Status Hackage Matrix CI
Docs available [build log]
Last success reported on 2019-11-08 [all 1 reports]

Modules

[Index] [Quick Jump]

Downloads

Maintainer's Corner

For package maintainers and hackage trustees


Readme for tmp-postgres-1.5.0.0

[back to package description]

Travis CI Status

tmp-postgres

tmp-postgres provides functions creating a temporary postgres instance. By default it will create a temporary directory for the data, a random port for listening and a temporary directory for a UNIX domain socket.

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, postgres and createdb. All of the command line, environment variables and configuration files that are generated by default for the respective executables can be extended or overrided.

All tmp-postgres by default is most useful for creating tests by configuring "tmp-postgres" differently it can be used for other purposes.

  • By disabling initdb and createdb one could run a temporary postgres on a base backup to test a migration.
  • By using the stopPostgres and withRestart functions one can test backup strategies.

The level of custom configuration is extensive but with great power comes ability to screw everything up. tmp-postgres doesn't validate any custom configuration and one can easily create a Config that would not allow postgres to start.

Installation

macOS

$ brew install postgres
$ stack install tmp-postgres

Ubuntu

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