#!/usr/bin/env bash # pg_upgrade from an old release to two builds of the new one (master and patched), # schema only, alternating rounds. Prints one line per run with the user-space instructions # of the whole pg_upgrade process tree (pg_dump, restore and both servers; perf stat) and the # wall clock time. The instruction count is the stable figure: the wall clock includes # copying and syncing files, which depends on whatever else the disk is doing. # # OLDBIN=... MASTERBIN=... PATCHEDBIN=... WORKDIR=... pg_upgrade-bench.sh # # Optional: EXTRABIN= EXTRALABEL= adds a third build; UPGRADE_OPTS is passed # to pg_upgrade (for example --no-sync). The order of the builds rotates between rounds. # # schema "wide": one range-partitioned table, 1000 partitions x 200 NOT NULL int columns # and a primary key # schema "tom": the case from the b3f0e0503f3 thread, 100 tables x 1000 # "float check (a > 10.2)" columns, each with one INHERITS child set -uo pipefail S=$1 N=$2 : "${OLDBIN:?} ${MASTERBIN:?} ${PATCHEDBIN:?} ${WORKDIR:?}" W=$WORKDIR/$S mkdir -p "$W"; cd "$W" || exit 1 gen() { if [ "$S" = wide ]; then cols=$(seq -s, -f 'c%g int not null' 1 200) echo "create table p (id int not null, $cols, primary key (id)) partition by range (id);" for i in $(seq 0 999); do echo "create table p$i partition of p for values from ($((i*10))) to ($((i*10+10)));" done else for i in $(seq 0 99); 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 fi } if [ ! -f "$W/old/PG_VERSION" ]; then "$OLDBIN"/initdb -D "$W/old" -U postgres -A trust >/dev/null || exit 1 "$OLDBIN"/pg_ctl -D "$W/old" -o "-p 54811 -k $W -c max_locks_per_transaction=1024" \ -l "$W/old.log" -w start >/dev/null gen > "$W/schema.sql" "$OLDBIN"/psql -X -q -h "$W" -p 54811 -U postgres -d postgres -v ON_ERROR_STOP=1 \ -f "$W/schema.sql" || exit 1 "$OLDBIN"/psql -X -At -h "$W" -p 54811 -U postgres -d postgres -c \ "select 'old: '||version()||' | constraints='||count(*) from pg_constraint where connamespace='public'::regnamespace" "$OLDBIN"/pg_ctl -D "$W/old" -w stop >/dev/null fi labels=(master patched); bins=("$MASTERBIN" "$PATCHEDBIN") [ -n "${EXTRABIN:-}" ] && { labels+=("${EXTRALABEL:-extra}"); bins+=("$EXTRABIN"); } nb=${#labels[@]} for r in $(seq 1 "$N"); do for k in $(seq 0 $((nb - 1))); do i=$(( (k + r - 1) % nb )); b=${labels[$i]}; B=${bins[$i]} rm -rf "$W/new-$b" "$W/run-$b"; mkdir -p "$W/run-$b" "$B"/initdb -D "$W/new-$b" -U postgres -A trust >/dev/null || exit 1 cd "$W/run-$b" t0=$(date +%s.%N) perf stat -x, -e instructions:u -o "$W/run-$b/perf.txt" -- \ "$B"/pg_upgrade -U postgres -b "$OLDBIN" -B "$B" -d "$W/old" -D "$W/new-$b" \ -p 54811 -P 54812 -s "$W" --copy ${UPGRADE_OPTS:-} > "$W/run-$b/out.txt" 2>&1 rc=$? t1=$(date +%s.%N) cd "$W" grep -q 'Upgrade Complete' "$W/run-$b/out.txt" || rc="$rc(no 'Upgrade Complete')" ins=$(awk -F, '/instructions/{print $1}' "$W/run-$b/perf.txt") printf '%s\tround=%d\t%s\texit=%s\tinstr_G=%.2f\twall_s=%.2f\n' "$S" "$r" $b "$rc" \ "$(echo "$ins/1000000000" | bc -l)" "$(echo "$t1 - $t0" | bc)" done done