Skip to content

Instantly share code, notes, and snippets.

@kennyp
Created March 22, 2024 16:43
Show Gist options
  • Save kennyp/50abe98f57c133e37dc2c883f965b455 to your computer and use it in GitHub Desktop.
Save kennyp/50abe98f57c133e37dc2c883f965b455 to your computer and use it in GitHub Desktop.
Postgresql Layout for direnv
layout_postgres() {
export PGDATA="$(direnv_layout_dir)/postgres"
export PGHOST="$PGDATA"
if [[ ! -d "$PGDATA" ]]; then
initdb
cat >> "$PGDATA/postgresql.conf" <<-EOF
listen_addresses = ''
unix_socket_directories = '$PGHOST'
EOF
echo "CREATE DATABASE $USER;" | postgres --single -E postgres
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment