Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mnahkies/ephemeral-postgres
Starts a postgres in docker where any credentials or database name is accepted
https://github.com/mnahkies/ephemeral-postgres
Last synced: 13 days ago
JSON representation
Starts a postgres in docker where any credentials or database name is accepted
- Host: GitHub
- URL: https://github.com/mnahkies/ephemeral-postgres
- Owner: mnahkies
- License: mit
- Created: 2023-04-07T12:19:22.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-02-25T11:24:38.000Z (9 months ago)
- Last Synced: 2024-05-15T15:39:41.309Z (6 months ago)
- Language: C
- Homepage:
- Size: 7.81 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ephemeral-postgres
A bash script that starts an ephemeral postgres locally in docker for **development purposes**.
**Data is destroyed** between runs, on Linux the data is stored on a `tmpfs` / ramdisk
for faster startup.The container loads a `ClientAuthentication` hook `ensure_role_and_database_exists` that
automatically creates roles & databases that don't exist when connections are made.This allows you to just start the container and not worry about pre-creating users or
databases for your integration test suites, etc.By default, it will create users with `LOGIN CREATEDB` and authenticate using `TRUST` but
this can be customized with the environment variables below.## Installation
- Requires `docker` to be installed https://docs.docker.com/engine/install/
- Clone the repo
- (Optionally) add the repo to your `$PATH`## Usage
Start the `postgres` server:
```shell
start-ephemeral-postgres.sh
```**Options**
- `POSTGRES_VERSION=16`
- `POSTGRES_PASSWORD=postgres`
- `POSTGRES_HOST_AUTH_METHOD=trust` - could be `scram-sha-256` / `md5` / etc
- `ROLE_ATTRIBUTES='LOGIN CREATEDB'` - could be `SUPERUSER` / `CREATEROLE BYPASSRLS` / etcConnect using `psql`:
```shell
docker exec -it postgres psql -U postgres postgres
docker exec -it postgres psql -U any_username any_database_name
```## References
See https://github.com/taminomara/psql-hooks for the unofficial documentation of Postgresql hooks
These slides are also a good reference: https://wiki.postgresql.org/images/e/e3/Hooks_in_postgresql.pdf