#!/bin/sh
# usage: make-segment.sh <bindir> <workdir>
# initdb a fresh cluster and overwrite its first WAL record with record.bin
# (58 bytes, CRC already valid, xl_prev = 0), then run pg_waldump on it.
set -e
B=$1; W=$2; HERE=$(cd "$(dirname "$0")" && pwd)
"$B/initdb" -D "$W/data" >/dev/null
mkdir -p "$W/wal"
cp "$W/data/pg_wal/000000010000000000000001" "$W/wal/"
dd if="$HERE/record.bin" of="$W/wal/000000010000000000000001" bs=1 seek=40 conv=notrunc 2>/dev/null
cd "$W/wal" && "$B/pg_waldump" 000000010000000000000001
