NAME
pg_tmp —
    quickly spin up temporary PostgreSQL
    database
SYNOPSIS
| pg_tmp | [ -k] [-t[-pport]]
      [-wtimeout]
      [-oextra-options]
      [-ddatadir] | 
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.
- -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.
- -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.
- -o
- Specifies extra-options to be passed directly to the postgres(1) binary. These options should usually be surrounded by quotes to ensure that they are passed through as a group.
- -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.
ENVIRONMENT
- TMPDIR
- base directory in which to create and run the ephemeral instances of postgres(1)
- LC_ALL
- Set locale to ensure proper startup on Mac OS. If not set the default is
      ‘C’.
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"