Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: duckdb install-duckdb clean-duckdb clean-all lintcheck check-regression-duckdb clean-regression
.PHONY: duckdb install-duckdb clean-duckdb clean-all lintcheck check-regression-duckdb clean-regression valgrind-check

MODULE_big = pg_duckdb
EXTENSION = pg_duckdb
Expand Down Expand Up @@ -109,6 +109,13 @@ check: installcheck pycheck schedulecheck
schedulecheck:
./scripts/schedule-check.sh

valgrind-check:
@if [ -z "$(PG_SRC)" ]; then \
echo "Usage: make valgrind-check PG_SRC=/path/to/postgres"; \
exit 1; \
fi
./scripts/valgrind_pgduckdb.sh PG_SRC=$(PG_SRC)

duckdb: $(FULL_DUCKDB_LIB)

.git/modules/third_party/duckdb/HEAD:
Expand Down
93 changes: 93 additions & 0 deletions scripts/valgrind_pgduckdb.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
#!/bin/bash

set -euo pipefail

# Check arguments
if [ $# -ne 1 ] || [[ "$1" != PG_SRC=* ]]; then
echo "Usage: $0 PG_SRC=/path/to/postgres"
exit 1
fi

PG_SRC="${1#PG_SRC=}"

if [ ! -d "$PG_SRC" ]; then
echo "Error: PostgreSQL source directory '$PG_SRC' does not exist"
exit 1
fi

echo "Building PostgreSQL with Valgrind support..."

# Setup temp directories
TEMP_DIR=$(mktemp -d)
PG_INSTALL="$TEMP_DIR/postgres_install"
PG_DATA="$TEMP_DIR/postgres_data"
PG_LOG="$TEMP_DIR/postgres_log"

# Cleanup function
cleanup() {
if [ -n "${PG_PID:-}" ]; then
kill $PG_PID 2>/dev/null || true
fi
rm -rf "$TEMP_DIR"
}

trap cleanup EXIT

# Build PostgreSQL
cd "$PG_SRC"
./configure --prefix="$PG_INSTALL" --enable-debug \
CFLAGS="-O0 -g -DUSE_VALGRIND" \
CXXFLAGS="-O0 -g -DUSE_VALGRIND"
make -j$(nproc)
make install
cd - > /dev/null

# Build pg_duckdb
echo "Building pg_duckdb..."
make clean
make PG_CONFIG="$PG_INSTALL/bin/pg_config"

# Setup and start PostgreSQL
echo "Starting PostgreSQL..."
"$PG_INSTALL/bin/initdb" -D "$PG_DATA" --no-locale
"$PG_INSTALL/bin/pg_ctl" -D "$PG_DATA" -l "$PG_LOG/postgres.log" start
sleep 3

if ! "$PG_INSTALL/bin/pg_ctl" -D "$PG_DATA" status > /dev/null 2>&1; then
echo "PostgreSQL failed to start"
cat "$PG_LOG/postgres.log"
exit 1
fi

PG_PID=$(cat "$PG_DATA/postmaster.pid" 2>/dev/null || echo "")

# Run Valgrind test
echo "Running Valgrind test..."
TEST_SQL="test/regression/sql/valgrind_basic.sql"

if [ ! -f "$TEST_SQL" ]; then
echo "Test file '$TEST_SQL' not found"
exit 1
fi

valgrind \
--tool=memcheck \
--leak-check=full \
--show-leak-kinds=all \
--track-origins=yes \
--num-callers=50 \
--error-exitcode=99 \
--suppressions="$PG_SRC/src/tools/valgrind.supp" \
"$PG_INSTALL/bin/psql" \
-h localhost -p 5432 -U "$(whoami)" -d postgres \
-f "$TEST_SQL"

EXIT_CODE=$?

if [ $EXIT_CODE -eq 0 ]; then
echo "Valgrind test passed"
else
echo "Valgrind test failed"
fi

exit $EXIT_CODE
27 changes: 27 additions & 0 deletions test/regression/expected/valgrind_basic.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
CREATE EXTENSION pg_duckdb;
SELECT * FROM duckdb.query('SELECT 42 as answer');
answer
--------
42
(1 row)

SELECT * FROM duckdb.query('SELECT generate_series(1, 10) as num');
num
-----
1
2
3
4
5
6
7
8
9
10
(10 rows)

SELECT * FROM duckdb.query('SELECT ''Hello, Valgrind!'' as message');
message
------------------
Hello, Valgrind!
(1 row)
7 changes: 7 additions & 0 deletions test/regression/sql/valgrind_basic.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
CREATE EXTENSION pg_duckdb;

SELECT * FROM duckdb.query('SELECT 42 as answer');

SELECT * FROM duckdb.query('SELECT generate_series(1, 10) as num');

SELECT * FROM duckdb.query('SELECT ''Hello, Valgrind!'' as message');