#!/bin/sh

PGDATA=$HOME/pgdata
export PGDATA
time=300

echo 'stopping any running server'
~/install/master/bin/pg_ctl stop -mi
rm -rf $PGDATA

for clients in 32 1 8 16; do
    for x in 1 2 3; do
        for branch in master REL9_1_STABLE; do
            for iso in serializable 'read committed' 'repeatable read'; do
                echo "clients=$clients run=$x branch=$branch iso=$iso"
		~/install/$branch/bin/initdb
		cat >> $PGDATA/postgresql.conf <<EOM;
shared_buffers = 8GB
maintenance_work_mem = 1GB
checkpoint_segments = 30
checkpoint_timeout = 15min
checkpoint_completion_target = 0.9
default_transaction_isolation = '$iso'
EOM
		~/install/$branch/bin/pg_ctl start \
			-l "$HOME/log/log.$branch.$clients.$iso"
		sleep 5
		~/install/$branch/bin/createdb
		pgbench -i -s 100
		pgbench -n -S -T $time -c $clients -j $clients \
			>> "$HOME/results/results.$branch.$clients.$iso"
		psql -c CHECKPOINT
		sleep 5
		~/install/$branch/bin/pg_ctl stop -m fast
		sleep 5
		rm -rf $PGDATA
            done
	done
    done
done
