tmp-postgres- Start and stop a temporary postgres

Safe HaskellNone



This module provides the high level functions that are re-exported by Database.Postgres.Temp. Additionally it includes some identifiers that are used for testing but are not exported.



data DB Source #

Handle for holding temporary resources, the postgres process handle and postgres connection information. The DB also includes the final Plan that was used to start initdb, createdb and postgres. See toConnectionString for converting a DB to postgresql connection string.




Pretty DB Source # 
Instance details

Defined in Database.Postgres.Temp.Internal


pretty :: DB -> Doc #

prettyList :: [DB] -> Doc #

toConnectionString :: DB -> ByteString Source #

Convert a DB to a connection string. Alternatively one can access the Options using toConnectionOptions

toConnectionOptions :: DB -> Options Source #

Convert a DB to a connection Options type.

toDataDirectory :: DB -> FilePath Source #

Access the data directory. This was either generated or specified explicitly when creating the Config

defaultPostgresConfig :: [String] Source #

Default postgres options

defaultConfig :: Config Source #

The default configuration. This will create a database called "postgres" via initdb (it's default behavior). It will create a temporary directory for the data and a temporary directory for a unix socket on a random port. Additionally it will use append the following onto the "postgresql.conf"

   shared_buffers = 12MB
   fsync = off
   synchronous_commit = off
   full_page_writes = off
   log_min_duration_statement = 0
   log_connections = on
   log_disconnections = on
   client_min_messages = ERROR

defaultConfig also passes the --no-sync flag to initdb.

If you would like to customize this behavior you can start with the defaultConfig and overwrite fields or combine a defaultConfig with another Config using <> (mappend).

Alternatively you can eschew defaultConfig altogether, however your postgres might start and run faster if you use defaultConfig.

defaultConfig also sets the partialPlanInitDb to pure standardProcessConfig and partialPostgresPlanProcessConfig to standardProcessConfig.

defaultPostgresConf :: [String] -> Config Source #

mappend the defaultConfig with a Config that provides additional "postgresql.conf" lines. Equivalent to

defaultPostgresConf extra = defaultConfig <> mempty
  { configPlan = mempty
    { partialPlanConfig = extra

startConfig Source #


:: Config

extraConfiguration that is mappended to the generated Config. The extra config is mappended second, e.g. generatedConfig <> extraConfiguration

-> IO (Either StartError DB) 

Create temporary resources and use them to make a Config. The generated Config is combined with the passed in extraConfiguration to create a Plan that is used to create a database. The output DB includes references to the temporary resources for cleanup and the final plan that was used to generate the database and processes

start :: IO (Either StartError DB) Source #

Default start behavior. Equivalent to calling startConfig with the defaultConfig

stop :: DB -> IO () Source #

Stop the postgres process and cleanup any temporary directories that might have been created.

stopPostgres :: DB -> IO ExitCode Source #

Only stop the postgres process but leave any temporary resources. Useful for testing backup strategies when used in conjunction with restart or withRestart.

restart :: DB -> IO (Either StartError DB) Source #

Restart the postgres using the Plan from the DB (e.g. resourcesPlan . dbResources)

reloadConfig :: DB -> IO () Source #

Reload the configuration file without shutting down. Calls pg_reload_conf().

withConfig Source #


:: Config

extraConfiguration. Combined with the generated Config. See startConfig for more info

-> (DB -> IO a)

action continuation

-> IO (Either StartError a) 

Exception safe default database create. Takes an action continuation which is given a DB it can use to connect to (see toConnectionString or postgresProcessClientOptions). All of the database resources are automatically cleaned up on completion even in the face of exceptions.

with Source #


:: (DB -> IO a)

action continuation.

-> IO (Either StartError a) 

Default expectation safe interface. Equivalent to withConfig the defaultConfig

withRestart :: DB -> (DB -> IO a) -> IO (Either StartError a) Source #

Exception safe version of restart

optionsToDefaultConfig :: Options -> Config Source #

Attempt to create a Config from a Options. Useful if you want to create a database owned by a specific user you will also login with among other use cases.

prettyPrintDB :: DB -> String Source #

Display a DB