export PGDATA=/mnt/data-mag/dilip.kumar/pgdata
export PGPORT=54321
export LD_LIBRARY_PATH=/home/dilip/PG_CODES/base/waiter/lib/:$LD_LIBRARY_PATH

for threads in 1 8 16
do
        ./postgres -c shared_buffers=512MB -c max_wal_size=20GB -c checkpoint_timeout=12min -p 54321&
        sleep 5
        #drop and recreate database
        ./dropdb postgres
        ./createdb postgres
        #initialize database
        ./pgbench -i -s 1 postgres
        ./psql -d postgres -c "create table test_data(a int, b text)"
        ./psql -d postgres -c "insert into test_data values(generate_series(1,1000),repeat('x', 1024))"

        rm -rf /tmp/copybinarywide

        ./psql -d postgres -c "COPY (select g.i::text FROM generate_series(1, 10000) g(i)) TO '/tmp/copybinarywide' WITH BINARY";

        ./psql -d postgres -c "create table data (a int, data text)"

        sleep 5
        ./pgbench -c $threads -j $threads -f insert_script -T 120 postgres >> test_results.txt
        sleep 10
        ./psql -d postgres -c "ANALYZE data"
        ./psql -d postgres -c "SELECT count(*) FROM data" >> test_results.txt
	./psql -d postgres -c "SELECT relpages FROM pg_class WHERE relname='data'" >> test_results.txt
        ./psql -d postgres -c "drop table data"
        ./psql -d postgres -c "drop table test_data"
        ./psql -d postgres -c "checkpoint" >> test_results.txt
        ./pg_ctl stop
done

