nZac

Start Postgres Here

I've used this handy little script for a long while to create a postgres server in the directory that the command is run. I'm able to quickly see every SQL command that hits the DB. This is really helpful during development.

Something like start-pg-here -p 5433 allows me to spin up more than one but on a different port. rm -r .postgres-data quickly removes the cluster.

#!/bin/bash

SUPERUSER="${SUPERUSER:-$(whoami)}"

# If the postgres server directory doesn't exist create it
if [ ! -d ./.postgres-data ]; then
  mkdir ./.postgres-data
  initdb --locale=C -E UTF-8 -U "${SUPERUSER}" -W ./.postgres-data
fi

# Start the postgres server
postgres -E -D ./.postgres-data $@

#cli #helpers #postgres #workflow