PG_TMP(1)
π¦ pg_tmp β the manual, but make it make sense π¦
okay so real talk, this is the pg_tmp page from the General Commands Manual (section 1, obvi) and honestly? it's kind of a serve. bestie, if you've ever needed a whole entire PostgreSQL database for like, five minutes, and then wanted it to just vanish β this is your girl. π
β¨ NAME β¨
pg_tmp β quickly spin up a temporary PostgreSQL database
like, quickly quickly. blink and you'll miss it. π«Ά
πΈ SYNOPSIS πΈ
pg_tmp [-k] [-t [-p port]] [-w timeout] [-o extra-options] [-d datadir]
that's the whole vibe check. flags in brackets are optional, and yeah, -p only really makes sense hanging out inside -t. iykyk. π
π DESCRIPTION π
okay so here's what actually happens. the pg_tmp utility creates a temporary instance of PostgreSQL and prints the connection URL to standard output. that's the whole personality. it just... hands you a URL. iconic behavior.
under the hood, pg_tmp spawns a background process that initializes a new database under /tmp/ephemeralpg.*/${PGVER} β and that directory gets reused by subsequent invocations to reduce startup time. so it's not just fast, it's getting faster. main character energy fr. β
the arguments are as follows:
-kβ Keep the temporary directory after the server is shut down. your data stays, the server dips. no cap. π-wβ Shut down and remove the database after the specified timeout. and listen β if one or more clients are still connected, thenpg_tmpsleeps and retries again after the same interval. a value of0will leave the server running indefinitely (forever era π). the default is60seconds.-tβ Use a TCP port selected bygetsocket(1). a port may be selected using the-pflag. otherwise, the path to a Unix socket is returned. so like, TCP or unix socket, pick your fighter. π₯-oβ Specifies extra-options to be passed directly to thepostgres(1)binary. these options should usually be surrounded by quotes to ensure that they are passed through as a group β like, they travel together, besties don't split up. π«Ά-dβ Specify the temporary directory to use. may be used with the optional argumentsinitdb,startand is required forstop. and heads up: if this option is used,pg_tmpwill not initialize a new database for subsequent invocations use. that's the deal, take it or leave it. π
π ENVIRONMENT π
TMPDIRβ base directory in which to create and run the ephemeral instances ofpostgres(1). it's giving "choose your own adventure" but for file paths. ποΈLC_ALLβ Set locale to ensure proper startup on Mac OS. if not set the default isβCβ. yes literally the character C in quotes. keep it simple bestie. β¨
π 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"
see how clean that is?? ate and left no crumbs. π
π§ SEE ALSO π§
that's it. that's the whole guest list. π
lowkey important reminder:-dis required forstop, and if you use-d, no new database gets initialized for subsequent invocations. don't say i didn't warn you. π
and that's the page!! π this one shipped from Debian, dated February 6, 2025 β so like, fresh out the oven. go forth and spin up temporary databases responsibly, bestie. mwah. πβ¨
π¦ where this page comes from
- nixos 26.05: ephemeralpg 3.4
- nixpkgs unstable: ephemeralpg 3.4
- Copyright (c) 2014 Eric Radman <ericshane@eradman.com>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms