This guide covers testing pgtrace components and running the system.
Use the automated setup script:
./scripts/test-setup.shThis script will:
- Check prerequisites (Rust, Elixir, PostgreSQL)
- Set up database (Docker or local)
- Run migrations
- Build all components
- Verify setup
# Start Docker containers
docker-compose up -d
# Run migrations
export PGPASSWORD=postgres
for file in store/migrations/*.sql; do
psql -h localhost -p 5433 -U postgres -d pgtrace_store -f "$file"
done# Create database
createdb pgtrace_store
# Run migrations
for file in store/migrations/*.sql; do
psql -d pgtrace_store -f "$file"
done# Agent
cd agent
cargo build --release
# CLI
cd ../cli
cargo build --release
# Server
cd ../server
mix deps.get
mix compileRun the basic test script:
./scripts/test-basic.shOr run tests manually:
# Set database connection
export PGTRACE_STORE_DSN="postgres://postgres:postgres@localhost:5433/pgtrace_store"
# Test CLI
cd cli
cargo run --release -- doctor
# Test database connection
psql "$PGTRACE_STORE_DSN" -c "SELECT COUNT(*) FROM pgtrace.nodes;"# Rust tests
cd agent && cargo test
cd ../cli && cargo test
# Elixir tests
cd server && mix test- Configure agent (see
agent/pgtrace-agent.yaml.example):
node_id: "test-node-1"
source:
dsn: "postgres://postgres:postgres@localhost:5434/postgres"
store:
dsn: "postgres://postgres:postgres@localhost:5433/pgtrace_store"- Start source database (if using Docker):
docker-compose up -d postgres-source- Run agent:
cd agent
cargo run --release -- run --config pgtrace-agent.yaml- Verify data is being collected:
# In another terminal
psql "postgres://postgres:postgres@localhost:5433/pgtrace_store" -c "SELECT COUNT(*) FROM pgtrace.events;"
psql "postgres://postgres:postgres@localhost:5433/pgtrace_store" -c "SELECT * FROM pgtrace.nodes;"cd cli
export PGTRACE_STORE_DSN="postgres://postgres:postgres@localhost:5433/pgtrace_store"
# Doctor command
cargo run --release -- doctor
# Tail events (if agent is running)
cargo run --release -- tail --node test-node-1 --window 5m
# Incident snapshot
cargo run --release -- incident --node test-node-1 --at "now" --window 10m
# Lock chains
cargo run --release -- locks --node test-node-1 --at now-
Configure database in
server/config/config.exs -
Start server:
cd server
mix phx.server- Test API endpoints:
# Health check
curl http://localhost:4000/api/v1/health
# Timeline
curl "http://localhost:4000/api/v1/nodes/test-node-1/timeline?from=2026-01-13T00:00:00Z&to=2026-01-13T23:59:59Z"
# Spikes
curl "http://localhost:4000/api/v1/nodes/test-node-1/spikes?from=2026-01-13T00:00:00Z&to=2026-01-13T23:59:59Z&metric=waits"- Test UI:
# Open in browser
open http://localhost:4000Simulate a lock storm to test lock edge detection:
-- Session 1
BEGIN;
LOCK TABLE some_table IN ACCESS EXCLUSIVE MODE;
-- Session 2 (in another terminal)
BEGIN;
SELECT * FROM some_table; -- Will waitRun agent and check:
cargo run --release -- locks --node test-node-1 --at nowGenerate query load:
-- Run heavy query repeatedly
SELECT pg_sleep(1);Check query statistics:
cargo run --release -- query --node test-node-1 --qhash <qhash> --window 15mInsert marker via SQL:
INSERT INTO pgtrace.markers (node_id, ts, label, meta, source)
VALUES ('test-node-1', now(), 'test deployment', '{"version": "1.0.0"}'::jsonb, 'manual');Or via API:
curl -X POST http://localhost:4000/api/v1/markers \
-H "Content-Type: application/json" \
-d '{"node_id": "test-node-1", "label": "test deployment", "meta": {"version": "1.0.0"}}'Database migrations run successfully All components compile without errors CLI doctor command works Database connection successful Agent can connect to source database Agent can write to store database Server starts without errors API endpoints respond UI loads in browser
# Check PostgreSQL is running
pg_isready -h localhost -p 5433
# Test connection
psql "postgres://postgres:postgres@localhost:5433/pgtrace_store" -c "SELECT 1"
# Check tables
psql "postgres://postgres:postgres@localhost:5433/pgtrace_store" -c "\dt pgtrace.*"- Check source database connection
- Verify agent has required permissions
- Check agent logs for errors
- Verify node_id is configured correctly
- Verify PGTRACE_STORE_DSN is set
- Check database connection
- Ensure migrations have been run
- Check user has pgtrace_reader role
- Check database configuration in config.exs
- Verify migrations are run
- Check logs:
mix phx.servershows errors - Ensure all dependencies are installed:
mix deps.get
For performance testing, see docs/OPERATIONS.md.
For CI/CD integration:
# In CI script
./scripts/test-setup.sh
./scripts/test-basic.sh
cd agent && cargo test
cd ../cli && cargo test
cd ../server && mix test