#!/bin/bash
# usage: wal_run.sh <install prefix> <data dir> <port>
set -e
P=$1; D=$2; PORT=$3
HERE=$(dirname "$0")
rm -rf "$D"
"$P/bin/initdb" -D "$D" -U postgres >/dev/null
"$P/bin/pg_ctl" -D "$D" -o "-p $PORT -k /tmp" -l "$D/log" -w start >/dev/null
"$P/bin/pgbench" -h /tmp -p $PORT -U postgres -i -s 5 -q postgres >/dev/null 2>&1
"$P/bin/pgbench" -h /tmp -p $PORT -U postgres -c 4 -t 2000 postgres >/dev/null 2>&1
"$P/bin/psql" -h /tmp -p $PORT -U postgres -X -q postgres <<'SQL' >/dev/null
CREATE INDEX ON pgbench_accounts (abalance);
VACUUM ANALYZE;
CHECKPOINT;
SQL
"$P/bin/pg_ctl" -D "$D" -m fast -w stop >/dev/null
uv run --no-project python "$HERE/wal_padding.py" "$P/bin/pg_waldump" "$D/pg_wal"
