-
Notifications
You must be signed in to change notification settings - Fork 3
/
pg_tmp.1
102 lines (102 loc) · 2.94 KB
/
pg_tmp.1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
.\"
.\" Copyright (c) 2014 Eric Radman <[email protected]>
.\"
.\" Permission to use, copy, modify, and distribute this software for any
.\" purpose with or without fee is hereby granted, provided that the above
.\" copyright notice and this permission notice appear in all copies.
.\"
.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
.Dd September 5, 2024
.Dt PG_TMP 1
.Os
.Sh NAME
.Nm pg_tmp
.Nd quickly spin up temporary PostgreSQL database
.Sh SYNOPSIS
.Nm pg_tmp
.Op Fl k
.Op Fl t Op Fl p Ar port
.Op Fl w Ar timeout
.Op Fl o Ar extra-options
.Op Fl d Ar datadir
.Sh DESCRIPTION
The
.Nm
utility creates a temporary instance of PostgreSQL and prints the connection URL
to standard output.
.Nm
spawns a background process that initializes a new database under
.Pa /tmp/ephemeralpg.*/${PGVER}
which is used by subsequent invocations to reduce startup time.
The arguments are as follows:
.Bl -tag -width Ds
.It Fl k
Keep the temporary directory after the server is shut down.
.It Fl w
Shut down and remove the database after the specified
.Ar timeout .
If one or more clients are still connected then
.Nm
sleeps and retries again after the same interval.
A value of 0 will leave the server running indefinitely.
The default is 60 seconds.
.It Fl t
Use a TCP port selected by
.Xr getsocket 1 .
A port may be selected using the
.Fl p
flag.
Otherwise the path to a Unix socket is returned.
.It Fl o
Specifies extra-options to be passed directly to the
.Xr postgres 1
binary.
These options should usually be surrounded by quotes to ensure that they are
passed through as a group.
.It Fl d
Specify the temporary directory to use.
May be used with the optional arguments
.Ar initdb ,
.Ar start
and is required for
.Ar stop .
If this option is used
.Nm
will not initialize a new database for subsequent invocations use.
.El
.Sh ENVIRONMENT
.Bl -tag -width TMPDIR
.It Ev TMPDIR
base directory in which to create and run the ephemeral instances of
.Xr postgres 1
.It Ev LC_ALL
Set locale to ensure proper startup on Mac OS.
If not set the default is
.Ql C .
.El
.Sh EXAMPLES
Create a temporary database and run a query:
.Bd -literal -offset indent
uri=$(pg_tmp)
psql $uri -f my.sql
.Ed
.Pp
Start a temporary server with a custom extension:
.Bd -literal -offset indent
uri=$(pg_tmp -o "-c shared_preload_libraries=$PWD/auth_hook")
psql $uri -c "SELECT 1"
.Ed
.Pp
Start a temporary database that recycles WAL segments to reduce space
.Bd -literal -offset indent
pg_tmp -o "-c max_wal_size=48MB -c min_wal_size=32M"
.Ed
.Sh SEE ALSO
.Xr pg_ctl 1