| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Database.Postgres.Temp
Contents
Description
This module provides functions greating a temporary postgres instance on a random port for testing.
result <-start[] case result of Left err -> print err Right tempDB -> do -- Do stuffstoptempDB
The are few different methods for starting postgres which provide different
methods of dealing with stdout and stderr.
The start methods use a config based on the one used by pg_tmp, but can be overriden by in different values to the first argument of the start functions.
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
Synopsis
- data DB = DB {}
- data StartError
- start :: Options -> IO (Either StartError DB)
- startLocalhost :: Options -> IO (Either StartError DB)
- startAndLogToTmp :: Options -> IO (Either StartError DB)
- startWithHandles :: SocketClass -> Options -> Handle -> Handle -> IO (Either StartError DB)
- data Options = Options {}
- defaultOptions :: Options
- data InitDbOptions = InitDbOptions {}
- defaultInitDbOptions :: InitDbOptions
- stop :: DB -> IO (Maybe ExitCode)
- startPostgres :: DB -> IO ()
- stopPostgres :: DB -> IO (Maybe ExitCode)
- reloadConfig :: DB -> IO ()
- data SocketClass
Types
Constructors
| DB | |
Fields
| |
data StartError Source #
Constructors
| InitDBFailed ExitCode | |
| CreateDBFailed [String] ExitCode | |
| StartPostgresFailed [String] ExitCode | |
| StartPostgresDisappeared [String] |
Instances
| Eq StartError Source # | |
Defined in Database.Postgres.Temp.Internal | |
| Show StartError Source # | |
Defined in Database.Postgres.Temp.Internal Methods showsPrec :: Int -> StartError -> ShowS # show :: StartError -> String # showList :: [StartError] -> ShowS # | |
| Exception StartError Source # | |
Defined in Database.Postgres.Temp.Internal Methods toException :: StartError -> SomeException # fromException :: SomeException -> Maybe StartError # displayException :: StartError -> String # | |
Starting postgres
startWithHandles is the most general way to start postgres. It allows the user to
pass in it's own handles for stdout and stderr. start and startAndLogToTmp
both call startWithHandles passing in different handles. start uses the current
process's stdout and stderr and startAndLogToTmp logs to files in the mainDir.
postgres is started with a default config with the following options:
listen_addresses = ''
shared_buffers = 12MB
fsync = off
synchronous_commit = off
full_page_writes = off
log_min_duration_statement = 0
log_connections = on
log_disconnections = on
unix_socket_directories = {mainDir}
client_min_messages = ERROR
Any of the options can be overriden by passing in a different value when starting
Right db <- start [("log_min_duration_statement", "1000")]
Arguments
| :: Options | Extra options which override the defaults |
| -> IO (Either StartError DB) |
start postgres and use the current processes stdout and stderr
startLocalhost :: Options -> IO (Either StartError DB) Source #
start postgres and use the current processes stdout and stderr but use TCP on localhost instead of a unix socket.
Arguments
| :: Options | Extra options which override the defaults |
| -> IO (Either StartError DB) |
Arguments
| :: SocketClass | |
| -> Options | Extra options which override the defaults |
| -> Handle | stdout |
| -> Handle | stderr |
| -> IO (Either StartError DB) |
Start postgres and pass in handles for stdout and stderr
Constructors
| Options | |
Fields
| |
data InitDbOptions Source #
Constructors
| InitDbOptions | |
Fields
| |
Instances
Stopping postgres
Starting and Stopping postgres without removing the temporary directory
startPostgres :: DB -> IO () Source #
This throws AnotherPostgresProcessActive if the postgres
has not been stopped using stopPostgres.
This function attempts to the pidLock before running.
If postgres process fails this throws StartPostgresFailed.
If the postgres process becomes Nothing while starting
this function throws StartPostgresDisappeared.
stopPostgres :: DB -> IO (Maybe ExitCode) Source #
Stop the postgres process. This function attempts to the pidLock before running.
stopPostgres will terminate all connections before shutting down postgres.
stopPostgres is useful for testing backup strategies.
Reloading the config
reloadConfig :: DB -> IO () Source #
Send the SIGHUP signal to the postgres process to start a config reload
data SocketClass Source #