#!/bin/sh

PGSRC=/data/buildtree/postgres/postgresql-7.2
PGBASEPORT=5400
PGBASEBIN=/data/buildtree/postgres/postgres72

LOG=/home/rbt/temp/bench_namedatalen.log


for newDATALEN in 32 64 128 512 ; do

  PGBIN=${PGBASEBIN}_${newDATALEN}
  PGPORT=`echo "${PGBASEPORT}+${newDATALEN}" | bc`

  sed -E 's/NAMEDATALEN\s[0-9]+/NAMEDATALEN ${newDATALEN}/g' ${PGSRC}/src/include/postgres_ext.h > ${PGSRC}/src/include/postgres_ext.h.tmp
  mv ${PGSRC}/src/include/postgres_ext.h.tmp ${PGSRC}/src/include/postgres_ext.h

  cd ${PGSRC}
  ./configure --prefix=${PGBIN} --with-pgport=${PGPORT} || (echo "UNABLE TO CONFIGURE"; exit)

  make clean
  make clean install

  cd ${PGSRC}/contrib/pgbench

  gmake install


  ${PGBIN}/bin/initdb -D ${PGBIN}/data  || (echo "UNABLE TO INITIALIZE"; exit 1)

  ${PGBIN}/bin/pg_ctl -D ${PGBIN}/data start  || (echo "UNABLE TO START"; exit 1)

  sleep 5

  echo "NAMEDATALEN: ${newDATALEN}" >> ${LOG}
  echo  >> ${LOG}
  time -a -o ${LOG} ${PGBIN}/bin/pgbench -i -s 5 -d template1 -p ${PGPORT}

  time -a -o ${LOG} ${PGBIN}/bin/pgbench -t 3000 -s 5 -d template1 -p ${PGPORT}
  echo  >> ${LOG}
  echo  >> ${LOG}

  ${PGBIN}/bin/pg_ctl -D ${PGBIN}/data stop
  rm -rf ${PGBIN}
done
