#!/usr/bin/env sh

pg_ctl -D node1 stop > /dev/null
pg_ctl -D node2 stop > /dev/null

rm -rf node1 node2
rm node1.log node2.log

initdb -D node1
initdb -D node2

echo "port = 5433" >> node2/postgresql.conf

echo "enable_partitionwise_join = 'on'" >> node1/postgresql.conf
echo "enable_partitionwise_aggregate = 'on'" >> node1/postgresql.conf
echo "postgres_fdw.use_remote_estimate = true" >> node1/postgresql.conf

echo "enable_partitionwise_join = 'on'" >> node2/postgresql.conf
echo "enable_partitionwise_aggregate = 'on'" >> node2/postgresql.conf
echo "postgres_fdw.use_remote_estimate = true" >> node2/postgresql.conf

pg_ctl -D node1 -l node1.log start
pg_ctl -D node2 -l node2.log start

createdb
createdb -p5433

psql -f init1.sql
psql -p5433 -f init2.sql

psql -f load.sql

psql -c "ANALYSE"
psql -p5433 -c "ANALYSE"
