#Pre condition:
#Create database and set the export PGDATA 
export PGDATA=~/work/data
export PGPORT=5432
export LD_LIBRARY_PATH=~/work/installation/lib:$LD_LIBRARY_PATH

#for i in "scale_factor shared_buffers time_for_readings no_of_readings orig_or_patch"
for i in "100 8GB 300 3 0" "300 8GB 300 3 0" "1000 8GB 300 3 0" "3000 8GB 300 3 0"
#for i in "1000 8GB 300 1 0" "3000 8GB 300 1 0" "1000 8GB 300 1 1" "3000 8GB 300 1 1" "1000 8GB 300 1 2" "3000 8GB 300 1 2"
#for i in "3000 8GB 900 1 2" "3000 16GB 900 1 2" "4000 16GB 900 1 2" "3000 8GB 900 1 1" "3000 16GB 900 1 1" "4000 16GB 900 1 1" "3000 8GB 900 1 0" "3000 16GB 900 1 0" "4000 16GB 900 1 0"
#for i in "3000 8GB 900 1 1" "3000 8GB 900 1 0"
do
scale_factor=`echo $i | cut -d" " -f1`
shared_bufs=`echo $i | cut -d" " -f2`
time_for_reading=`echo $i | cut -d" " -f3`
no_of_readings=`echo $i | cut -d" " -f4`
orig_or_patch=`echo $i | cut -d" " -f5`

if [ $orig_or_patch = "0" ]
then
	run_bin="org"	
elif [ $orig_or_patch = "1" ]
then
	run_bin="changed_freelist_mgmt_onefourth"    
else 
	run_bin="changed_freelist_mgmt_onesixth"    
fi

# -----------------------------------------------

echo "Start of script for $scale_factor $shared_bufs " >> test_results.txt


echo "============== $run_bin =============" >> test_results.txt
cp postgres_${run_bin} postgres

#Start the server
./postgres -c shared_buffers=$shared_bufs &

sleep 5 

#Initialize the database
#if [ $1 = "1" ]; then
	./pgbench -i -s $scale_factor -d postgres  >> test_results.txt 
#fi

for threads in 8 16 32 64 128 256
do       
        #Start taking reading for $7 number of readings
	for ((readcnt = 1 ; readcnt <= $no_of_readings ; readcnt++))
	do
		echo "================================================"  >> test_results.txt
		echo $scale_factor, $shared_bufs, $threads, $threads, $time_for_reading Reading - ${readcnt}  >> test_results.txt

		# Run pgbench	
		./pgbench -c $threads -j $threads -T $time_for_reading -S  postgres  >> test_results.txt
	done;
done;

./psql -d postgres -c "checkpoint" >> test_results.txt
./pg_ctl stop
sleep 1


mv test_results.txt test_results_list_${scale_factor}_${shared_bufs}_${run_bin}.txt
done;
=