# temp-postgres The `temp-postgres` utility runs the [PostgreSQL](https://www.postgresql.org/) server off a temporary data directory. See the [original blog post](https://www.skreutz.com/posts/temporary-postgresql-server/) for an introduction. The project's source code is hosted on . ## Usage Create and serve a temporary database: ```sh temp-postgres ``` Wrap the `psql` command to connect to the temporary database once the server is ready: ```sh temp-postgres -- psql ``` Run [SQLx integration tests](https://docs.rs/sqlx/latest/sqlx/attr.test.html) against a temporary database: ```sh temp-postgres -- cargo test ``` Or configure `temp-postgres` as a wrapper for [cargo-nextest](https://nexte.st/): ```toml experimental = ["wrapper-scripts"] [scripts.wrapper.temp-postgres] command = 'temp-postgres' [[profile.default.scripts]] platform = { host = 'cfg(unix)' } run-wrapper = 'temp-postgres' ``` Set up a symlink to enable static client configuration: ```sh temp-postgres --symlink ./db psql --host "$(realpath ./db)" ``` Specify a database name, and PostgreSQL user name: ```sh temp-postgres --dbname myproject --username alex ``` See the manual page for details. ## Dependencies The `temp-postgres` utility depends on `sh(1)` and `postgres(1)`. On OpenBSD you can install the dependencies using `pkg_add(1)`: ```sh doas pkg_add postgresql-server postgresql-client ``` On FreeBSD you can install the dependencies using `pkg-install(8)`: ```sh sudo pkg install postgresql16-server postgresql16-client ``` On Void Linux you can install the dependencies using `xbps-install(1)`: ```sh sudo xbps-install -S dash postgresql postgresql-client ``` On Arch Linux you can install the dependencies using `pacman(8)`: ```sh sudo pacman -Syu postgresql ``` ## Installation ```sh ./configure make sudo make install ``` Alternatively you can run or install the experimental Nix flake: ```sh nix run git+https://git.skreutz.com/temp-postgres.git -- --help ``` Try using Nix' `--refresh` flag, or adding `?ref=main&shallow=0` to the URL if you experience caching issues. See the [NixOS example](./examples/nixos) for how to install `temp-postgres` on NixOS using Nix flakes.