#!/usr/bin/env bash # Where does the restore of Tom's case go? The case from the b3f0e0503f3 thread, cut to 10 # tables (10 x 1000 inherited CHECK constraints), is dumped with pg_dump --binary-upgrade from # the old release and restored into master and into patched, alternating rounds. For each # restore it prints the user-space instructions of the whole server (perf stat), the wall # clock, and the summed server-side duration of the ADD CONSTRAINT statements, of the # INHERIT statements (the only ones that run MergeConstraintsIntoExisting) and of the rest. # # OLDBIN=... MASTERBIN=... PATCHEDBIN=... WORKDIR=... restore-split.sh set -uo pipefail N=$1 : "${OLDBIN:?} ${MASTERBIN:?} ${PATCHEDBIN:?} ${WORKDIR:?}" W=$WORKDIR/split mkdir -p "$W"; cd "$W" || exit 1 rm -rf old new-* ./*.log ./*.sql ./*.perf "$OLDBIN"/initdb -D old -U postgres -A trust >/dev/null || exit 1 "$OLDBIN"/pg_ctl -D old -o "-p 54821 -k $W" -l old.log -w start >/dev/null for i in $(seq 0 9); do echo "CREATE TABLE test_inh_check$i (" for j in $(seq 0 999); do echo "a$j float check (a$j > 10.2),"; done echo "b float);" echo "CREATE TABLE test_inh_check_child$i() INHERITS(test_inh_check$i);" done > schema.sql "$OLDBIN"/psql -X -q -h "$W" -p 54821 -U postgres -d postgres -v ON_ERROR_STOP=1 -f schema.sql "$MASTERBIN"/pg_dump -h "$W" -p 54821 -U postgres --schema-only --binary-upgrade \ -f dump.sql postgres "$OLDBIN"/pg_ctl -D old -w stop >/dev/null for r in $(seq 1 "$N"); do for b in master patched; do if [ $b = master ]; then B=$MASTERBIN; else B=$PATCHEDBIN; fi rm -rf "new-$b"; "$B"/initdb -D "new-$b" -U postgres -A trust >/dev/null perf stat -e instructions:u -x, -o "$b-$r.perf" -- "$B"/postgres -D "$W/new-$b" \ -p 54822 -k "$W" -b -c log_min_duration_statement=0 -c log_line_prefix= \ > "$b-$r.log" 2>&1 & until "$B"/pg_isready -q -h "$W" -p 54822; do sleep 0.2; done t0=$(date +%s.%N) "$B"/psql -X -q -o /dev/null -h "$W" -p 54822 -U postgres -d postgres \ -v ON_ERROR_STOP=1 -f dump.sql t1=$(date +%s.%N) "$B"/pg_ctl -D "new-$b" -m fast -w stop >/dev/null; wait ins=$(awk -F, '/instructions/{print $1}' "$b-$r.perf") k=$(awk '/duration: .* ms +statement: /{d=$3 if ($0 ~ / INHERIT /) i+=d; else if ($0 ~ /ADD CONSTRAINT/) a+=d; else o+=d} END{printf "addcon_s=%.2f\tinherit_s=%.2f\tother_s=%.2f", a/1000, i/1000, o/1000}' \ "$b-$r.log") printf 'tom10\tround=%d\t%s\tinstr_G=%.3f\twall_s=%.2f\t%s\n' "$r" $b \ "$(echo "$ins/1000000000" | bc -l)" "$(echo "$t1 - $t0" | bc)" "$k" done done