Skip to content

shibukawa/postgresql-uuidbench

Repository files navigation

PostgreSQL 18 Benchmark Tool

A Go-based benchmark tool for testing PostgreSQL 18 performance with UUID generation and bulk insertions.

Quick Start with Docker

1. Start PostgreSQL 18

# Start PostgreSQL 18 container
docker-compose up -d

# Check if database is ready
docker-compose logs postgres

2. Run the Benchmark

# 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

3. Run Tests

# Run unit tests
go test -v

# Run tests with coverage
go test -cover

Database Configuration

The Docker Compose setup provides:

  • Image: postgres:18-trixie
  • Database: benchmark
  • User: benchuser
  • Password: benchpass
  • Port: 5432

Docker Commands

# 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

Benchmark Parameters

  • --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 application
    • v4pg/v7pg: PostgreSQL-generated UUIDs using database functions
  • --record-size: Size of each record in bytes (default: 1000)

Read Performance Test Options (v4/v7 only)

  • --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)

Example Benchmark Results

The tool provides comprehensive performance metrics including:

  • Total insertion time
  • Records per second
  • Data throughput (MB/sec)
  • Batch processing statistics

Troubleshooting

Database Connection Issues

  1. Ensure PostgreSQL container is running: docker-compose ps
  2. Check container logs: docker-compose logs postgres
  3. Verify port 5432 is not in use by another service

Performance Tips

  • Use larger batch sizes for better throughput
  • UUID v7 may have better performance characteristics than v4
  • Monitor system resources during large benchmarks

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages