BSD-3-Clause licensed by Jonathan Fischoff
Maintained by [email protected]
This version can be pinned in stack with:tmp-postgres-1.34.1.0@sha256:7d6fd2e6f737890857aa60be1ba2828093c057db272e16180e99cd51566fead7,4753

Hackage Travis CI Status

tmp-postgres

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

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

Changes

Changelog for tmp-postgres

  • 1.34.1.0

    • #229 Add a auto_explain config
  • 1.34.0.1

    • #244 Fix cacheDbConfig doc
  • 1.34.0.0

    • #235 Take two to solve deadlocking on cacheAction. This time it is still possible but fixes #239
    • #239 First time action cache is made get cp failure
  • 1.33.0.0

    • #240 cacheAction should create the parent directories
  • 1.32.0.1

    • #234 Extend core with a initdb cache primitive
    • #232 Fix multithread initdb creation bug
  • 1.32.0.0

    • #235 Fixed bug where nested calls to cacheAction would deadlock. cacheAction no longer creates parent directories.
  • 1.31.0.3

    • #233 Add missing NOINLINE for global lock
  • 1.31.0.2

    • #230 Fix bug when the same cache is built concurrently.
  • 1.31.0.1

    • #227 remove mention of defaultPostgresConf in doc
    • #228 add track_io_timing = on to verboseConfig
  • 1.31.0.0

    • #224 Remove defaultPostgresConf
    • #223 Doc fixes
  • 1.30.0.1

    • #221 Make verboseConfig support pgbadger
    • #218 Document difference between takeSnapshot and cacheAction
  • 1.30.0.0

    • #217 verboseConfig is not verbose enough
    • #216 cacheAction does not handle ~ properly bug
    • #219 verboseConfig creates a database
  • 1.29.0.1

    • #214 Parallel stop is 8 ms faster.
  • 1.29.0.0

    • #211 Revert behavior of Permanent to not create the directory if it does not exist
    • #210 The signature of takeSnapshot is not as useful as it could be breaking change
  • 1.28.1.0

    • #208 Only hash important envs for initdb cache.
  • 1.28.0.0

    • #200 Change behavior of Permanent. We now create the directory if it does not exist. Other changes
  • 1.27.0.4

    • #193 and #194 Doc fixes
  • 1.27.0.3

    • #195, #196, #197, #198 Doc Fixes
  • 1.27.0.2

    • Doc Fixes
  • 1.27.0.1

    • Doc Fixes
  • 1.27.0.0

    • #191 Remove leading spaces in code examples
    • #192 startConfig bullet points are out of date
    • #189 Remove reloadConfig
  • 1.26.0.0

    • #187 Remove stopPostgresGracefully from public interface
  • 1.25.0.1

    • #188 Document all fields of Config
  • 1.25.0.0

    • #186 Rename CacheResources and cacheResourcesToConfig
  • 1.24.0.0

    • #185 rename makeDataDirPermanent to makeDataDirectoryPermanent
  • 1.23.0.3

    • #122 Try to minize failed deletes … again.
  • 1.23.0.2

    • #183 More Doc
  • 1.23.0.1

    • #182 Doc Fixies
  • 1.23.0.0

    • #175 Flatten Config
    • #178 Documentation Fixes
    • #179 Remove Public Config.hs
    • #180 Remove Lenses
  • 1.22.0.0

    • #174 Better postgresql.conf type.
  • 1.21.1.1

    • #172 Fix verboseLogging not working
  • 1.21.1.0

    • #135 Add defaultConfig_9_3_10
    • #170 Expose cacheConfig
    • #169 Documentation Reorg
  • 1.21.0.0

    • #165 Make silent the default.
  • 1.20.0.1

    • #164 Documentation fixes.
  • 1.20.0.0

    • #144 Make a Cache type.
    • #162 Make a Snapshot alias.
  • 1.19.0.1

    • #146 Better version hashing for making cache directories.
    • Documentation fixes
  • 1.19.0.0

    • #154 Change ’createDefaultCacheConfigtodefaultCacheConfig`.
  • 1.18.0.0

    • #143 Remove the withNewDb API
  • 1.17.0.0

    • #156 Deprecate NewDb functions.
    • #155 Better monoids for initDbConfig and createDbConfig.
    • #142 Cluster save points.
  • 1.16.1.0

    • #152 Add stopPostgresGracefully function.
  • 1.16.0.0

    • #149 CopyDirectoryCommand partial and rename the old CopyDirectoryCommand to CompleteCopyDirectoryCommand.
  • 1.15.1.1

    • #141 Documentation fixes.
  • 1.15.1.0

    • #119 Add initdb cache
    • #134 Expand tilde in Permanent DirectoryType setup.
  • 1.15.0.0

    • #137 Remove SocketClass and listen unconditionally on 127.0.0.1, ::1 and a UNIX socket.
    • #138 Fix bug where optionsToDefaultConfig would make createdb plan even if one is not needed.
  • 1.14.1.0

    • #122 Fix bug that would prevent temporary directory removal
  • 1.14.0.1

    • #129 Fix resource leak in executeProcess
  • 1.14.0.0

    • #126 Check for an empty data directory to give a better error message
    • #114 Silent postgresql.conf
  • 1.13.1.2

    • #124 Respect database name in withNewDbConfig
  • 1.13.1.1

    • #116 Don’t create postgres or template1 databases in optionsToDefaultConfig
  • 1.13.1.0

    • #113 Faster shutdown using SIGQUIT and removed manual session termination.
    • #115 Add password support to optionsToDefaultConfig
  • 1.13.0.0

    • #108 ‘startNewDBConfig’ functions added and related.
  • 1.12.0.1

    • Documentation fixes
  • 1.12.0.0

    • #64 Add the ‘withNewDB’ and ‘withNewDBConfig’ functions.
  • 1.11.0.0

    • #90 Extend generated config to provide default Handles and connection timeout.
    • #81 Create public Config module for better documentation organization.
  • 1.10.0.0

    • #58 Add connection timeout.
    • Rename partialPlanLoggerL to loggerL.
    • Add temporaryDirectoryL.
    • #31 A silent defaults.
    • #20 Include stderr in errors.
  • 1.9.0.2

    • Documentation fixes.
  • 1.9.0.1

    • Documentation fixes.
  • 1.9.0.0

    • #41 Configurable temporary directory.
    • #59 Change EnvVars to EnvironmentVariables.
  • 1.8.0.0

    • Get rid of Partial prefix. Add a Complete prefix to the internal configuration types.
    • Remove the partial prefix.
    • Expand abbreviations.
    • Order the Event type creation time.
  • 1.7.1.0

    • #35 Add Lenses for configuration.