#!/bin/sh

# Use this script as a wrapper to run PG under valgrind in "make check"
# scenarios.  Rename the built postgres executable to postgres.orig
# and then copy this script to $PGBLDROOT/src/backend/postgres.

# Note: a disadvantage of this approach is that the backend will see
# $PGBLDROOT/src/backend/ as its my_exec_path, hence will not pick up
# anything in the temp install dir, but will go to the configured install
# dir.  Must "make install" extensions and other stuff to work properly.

exec valgrind \
    --quiet \
    --suppressions=$PGSRCROOT/src/tools/valgrind.supp \
    --suppressions=$HOME/misc/my-valgrind.supp \
    --time-stamp=yes --error-exitcode=128 --trace-children=yes \
    --log-file=$HOME/valgrind-logs/%p.log $PMVALGRIND \
    $PGBLDROOT/src/backend/postgres.orig "$@"
