2023-11-26 22:44:53 +00:00
# Postgres Flake Template
This is a template for constructing a working environment for local
[Postgres ](https://www.postgresql.org/ ) (version 15.5) usage. [direnv ](https://direnv.net/ )
can be used to a launch a dev shell upon entering this directory (refer to
`.envrc` ). Otherwise run via:
```bash
2023-12-01 17:12:16 +00:00
$ nix develop
2023-11-26 22:44:53 +00:00
```
## Quickstart
2023-12-01 17:58:21 +00:00
An empty Postgres cluster is initialized at `db` . To start the database, run the
following:
2023-11-26 22:44:53 +00:00
```bash
2023-12-01 17:12:16 +00:00
$ pg_ctl -D db -l db/logfile -o --unix_socket_directories=@postgres start
2023-11-26 22:44:53 +00:00
```
2023-12-01 17:06:17 +00:00
In the above command, `@postgres` refers to an [abstract socket name ](https://www.postgresql.org/docs/15/runtime-config-connection.html#GUC-UNIX-SOCKET-DIRECTORIES ).
Rename to whatever is appropriate for your use case. To then connect to this
database instance, run:
2023-11-26 22:44:53 +00:00
```bash
2023-12-01 17:12:16 +00:00
$ psql -h @postgres
2023-11-26 22:44:53 +00:00
```
2023-12-01 17:06:17 +00:00
To later shut the database down, run:
2023-11-28 17:21:56 +00:00
```bash
2023-12-01 17:12:16 +00:00
$ pg_ctl -D db stop
2023-11-28 17:21:56 +00:00
```