#!/bin/bash

# Init and start the postgres daemon
initdb --no-locale
pg_ctl start -w -o "-c listen_addresses='*' -c unix_socket_permissions=0700 -c max_connections=9990 -c shared_preload_libraries=pg_stat_statements -c session_preload_libraries=auto_explain -c auto_explain.log_min_duration=100ms"
POSTGRID=`cat /var/lib/postgresql/data/postmaster.pid | perl -le '<>=~m#(\d+)# and print $1'`

# Create uniworx and uniworx_test database
psql -f /schema.sql postgres

# Wait for postgres daemon to terminate
while [ -e /proc/$POSTGRID ]; do
    sleep 0.5;
done