#!/bin/bash

INSTALL=~/install/postgres
PGDATA=~/junk/pgdata
PGPORT=5435

rm -fr $PGDATA
$INSTALL/bin/initdb -D $PGDATA
cat << EOF >> $PGDATA/postgresql.conf
  autovacuum = off
  port = $PGPORT
EOF

$INSTALL/bin/pg_ctl -D $PGDATA -w start
$INSTALL/bin/psql postgres -p $PGPORT -c "UPDATE pg_database SET datallowconn = true"
start_xid=` $INSTALL/bin/psql -p $PGPORT postgres --tuples -c "SELECT txid_current()" `
( for ((i=start_xid;i<65532;i++)) ; do echo "SELECT txid_current();"; done ) | $INSTALL/bin/psql -p $PGPORT postgres > /dev/null
$INSTALL/bin/vacuumdb -p $PGPORT --freeze --all 
$INSTALL/bin/psql postgres -p $PGPORT -c "CHECKPOINT"
$INSTALL/bin/pg_ctl -D $PGDATA -w stop
