#!/usr/bin/env bash

set -e

PATH=/home/tomas/builds/master/bin:$PATH
DATADIR=/mnt/raid-nvme/data-batching

rm -Rf $DATADIR

pg_ctl -D $DATADIR init

echo 'shared_buffers = 8GB' >> $DATADIR/postgresql.conf
echo 'io_workers = 12' >> $DATADIR/postgresql.conf

pg_ctl -D $DATADIR -l pg.log start

createdb test

for s in 1000000 10000000 100000000; do

	psql test <<EOF
drop table if exists bar_$s;
create table bar_$s (a int, b int, c int, d int, e int, f int, g int, h int, i text, j int, k int, l int, m int, n int, o int);
insert into bar_$s select i, i, i, i, i, i, i, i, repeat('x', 100), i, i, i, i, i, i from generate_series(1, $s) i;
EOF

	echo "bar_$s created"

done

pg_ctl -D $DATADIR -l pg.log stop
