A Go-based benchmark tool for testing PostgreSQL 18 performance with UUID generation and bulk insertions.
# Start PostgreSQL 18 container
docker-compose up -d
# Check if database is ready
docker-compose logs postgres
# Build the benchmark tool
go build -o benchmark main.go
# Run benchmark with pre-generated UUID v7
./benchmark \
--database-url "postgres://benchuser:benchpass@localhost:5432/benchmark?sslmode=disable" \
--records 10000 \
--uuid-version v7 \
--record-size 1000
# Run benchmark with PostgreSQL-generated UUID v7
./benchmark \
--database-url "postgres://benchuser:benchpass@localhost:5432/benchmark?sslmode=disable" \
--records 10000 \
--uuid-version v7pg \
--record-size 1000
# Run benchmark with pre-generated UUID v4
./benchmark \
--database-url "postgres://benchuser:benchpass@localhost:5432/benchmark?sslmode=disable" \
--records 5000 \
--uuid-version v4 \
--record-size 500
# Run benchmark with PostgreSQL-generated UUID v4
./benchmark \
--database-url "postgres://benchuser:benchpass@localhost:5432/benchmark?sslmode=disable" \
--records 5000 \
--uuid-version v4pg \
--record-size 500
# Run benchmark with read performance test (v4/v7 only)
./benchmark \
--database-url "postgres://benchuser:benchpass@localhost:5432/benchmark?sslmode=disable" \
--records 10000 \
--uuid-version v7 \
--enable-read-test \
--read-test-count 100 \
--read-test-range 10 \
--read-test-batch-size 5
# Run unit tests
go test -v
# Run tests with coverage
go test -cover
The Docker Compose setup provides:
- Image:
postgres:18-trixie
- Database:
benchmark
- User:
benchuser
- Password:
benchpass
- Port:
5432
# Start services
docker-compose up -d
# Stop services
docker-compose down
# View logs
docker-compose logs postgres
# Connect to database
docker-compose exec postgres psql -U benchuser -d benchmark
# Remove all data (including volumes)
docker-compose down -v
--database-url
: PostgreSQL connection string (required)--records
: Number of records to insert (required)--uuid-version
: UUID version to use (v4, v7, v4pg, v7pg, default: v4)v4
/v7
: Pre-generated UUIDs in Go applicationv4pg
/v7pg
: PostgreSQL-generated UUIDs using database functions
--record-size
: Size of each record in bytes (default: 1000)
--enable-read-test
: Enable read performance test after insert--read-test-count
: Number of read operations to perform (default: 100)--read-test-range
: Percentage range (1-100) of records to search in (default: 10)--read-test-batch-size
: Number of UUIDs to search per read operation (default: 10)
The tool provides comprehensive performance metrics including:
- Total insertion time
- Records per second
- Data throughput (MB/sec)
- Batch processing statistics
- Ensure PostgreSQL container is running:
docker-compose ps
- Check container logs:
docker-compose logs postgres
- Verify port 5432 is not in use by another service
- Use larger batch sizes for better throughput
- UUID v7 may have better performance characteristics than v4
- Monitor system resources during large benchmarks