#!/bin/sh

PGBIN=bin

rm -rf act sby

$PGBIN/initdb -D act
echo "wal_level = hot_standby" >> act/postgresql.conf
echo "hot_standby = on" >> act/postgresql.conf
echo "max_wal_senders = 4" >> act/postgresql.conf
echo "local replication postgres trust" >> act/pg_hba.conf

$PGBIN/pg_ctl -D act -w start
$PGBIN/pg_basebackup -D sby -c fast

echo "port = 5433" >> sby/postgresql.conf
echo "standby_mode = on" >> sby/recovery.conf
echo "primary_conninfo = ''" >> sby/recovery.conf

$PGBIN/pg_ctl -D sby -w start

$PGBIN/psql -c "create table t (i int);"
$PGBIN/psql -c "insert into t values(1);"
$PGBIN/psql -c "checkpoint;"
$PGBIN/psql -c "vacuum;"

$PGBIN/psql -p 5433 -c "checkpoint;"

$PGBIN/psql -c "delete from t;"
$PGBIN/psql -c "vacuum;"

$PGBIN/pg_ctl -D sby -m i stop
$PGBIN/pg_ctl -D act -m i stop

$PGBIN/pg_ctl -D sby start
