NAME
pg_tmp —
quickly spin up temporary PostgreSQL
database
SYNOPSIS
pg_tmp |
[-kt] [-d
datadir] [-o
pgoptions] [-p
port] [-w
timeout] |
DESCRIPTION
The pg_tmp utility creates a temporary
instance of PostgreSQL and prints the connection URL to standard output.
pg_tmp spawns a background process that initializes
a new database under /tmp/ephemeralpg.*/${PGVER}
which is used by subsequent invocations to reduce startup time. The
arguments are as follows:
-k- Keep the temporary directory after the server is shut down.
-t- Use a TCP port selected by
getsocket(1). A port may be selected using the
-pflag. Otherwise the path to a Unix socket is returned. -d- Specify the temporary directory to use. May be used with the optional
arguments initdb, start and is
required for stop. If this option is used
pg_tmpwill not initialize a new database for subsequent invocations use. -o- Specifies options to be passed directly to the postgres(1) server. These options should usually be surrounded by quotes to ensure that they are passed through as a group.
-p- TCP port to listen on.
-w- Shut down and remove the database after the specified
timeout. If one or more clients are still connected
then
pg_tmpsleeps and retries again after the same interval. A value of 0 will leave the server running indefinitely. The default is 60 seconds.
ENVIRONMENT
LC_ALL- Set locale to ensure proper startup on Mac OS. If not set the default is
‘
C’. TMPDIR- base directory in which to create and run the ephemeral instances of postgres(1)
EXAMPLES
Create a temporary database and run a query:
uri=$(pg_tmp) psql $uri -f my.sql
Start a temporary server with a custom extension:
uri=$(pg_tmp -o "-c shared_preload_libraries=$PWD/auth_hook") psql $uri -c "SELECT 1"
Start a temporary database that recycles WAL segments to reduce space
pg_tmp -o "-c max_wal_size=48MB -c min_wal_size=32M"