pgbox 🐘📦
pgbox is a CLI tool for running PostgreSQL in Docker with your choice of extensions.
It is designed for experimentation and prototyping, making it easy to test extensions before using them in a project.
Why pgbox?
- Quick setup: Spin up PostgreSQL with any set of extensions in seconds
- Easy experimentation: Test extensions locally before adding them to your stack
- Export to Docker: Export Docker Compose files when ready for your project
- 150+ extensions supported: From apt.postgresql.org
Think of pgbox as a PostgreSQL sandbox — a safe place to explore 150+ extensions without manual installs or risking your development database.
Installation
Download Pre-built Binary
Download the latest release for your platform from GitHub Releases.
Using the install script
curl -sSL https://raw.githubusercontent.com/ahacop/pgbox/main/install.sh | sh
Manual download
- Download the appropriate archive for your platform from releases
- Extract and move to your PATH:
tar -xzf pgbox_*_Linux_x86_64.tar.gz
sudo mv pgbox /usr/local/bin/
Using Go
go install github.com/ahacop/pgbox@latest
Using Nix Flake
# Run directly without installation
nix run github:ahacop/pgbox -- --help
# Start with specific extensions
nix run github:ahacop/pgbox -- up --ext pgvector,postgis
Build from Source
git clone https://github.com/ahacop/pgbox
cd pgbox
make build
# Optional: Install to GOPATH/bin
make install
Usage
Quick Start
# Start PostgreSQL with default settings (no extensions)
./pgbox up
# Start PostgreSQL with specific extensions
./pgbox up --ext pgvector,hypopg
# List available extensions
./pgbox list-extensions
# Connect to running PostgreSQL instance
./pgbox psql
# Stop and remove containers
./pgbox down
Common Commands
Starting PostgreSQL
# Start with default settings (PostgreSQL 18, port 5432)
./pgbox up
# Start with specific extensions
./pgbox up --ext pgvector,postgis,pg_trgm
# Start with custom PostgreSQL version
./pgbox up --pg-version 16
# Start on a different port
./pgbox up --port 5433
# Start with custom credentials
./pgbox up --user myuser --password mypass --database mydb
# Start without detaching (see logs in foreground)
./pgbox up --detach=false
# Start with custom container name
./pgbox up --name my-postgres-dev
Managing Containers
# Check status of running containers
./pgbox status
# View container logs
./pgbox logs
# Follow logs in real-time
./pgbox logs --follow
# Restart container
./pgbox restart
# Stop container (keeps data)
./pgbox down
# Stop and remove container with volumes
./pgbox down --volumes
# Clean up all pgbox containers and volumes
./pgbox clean
Working with PostgreSQL
# Connect with psql
./pgbox psql
# Connect to specific container by name
./pgbox psql --name my-postgres-dev
# Pass arguments to psql
./pgbox psql -- -c "SELECT version();"
# List available extensions
./pgbox list-extensions
# Search for specific extensions
./pgbox list-extensions | grep vector
Exporting for your project
# Export Docker configuration to directory
./pgbox export ./my-postgres
# Export with specific version and extensions
./pgbox export ./my-postgres -v 16 --ext pgvector,hypopg
# Export with custom port
./pgbox export ./my-postgres -p 5433
# Generated files:
# - Dockerfile: Custom image with extensions
# - docker-compose.yml: Complete Docker Compose setup with required configurations
# - init.sql: SQL script to create extensions
# - postgresql.conf (if needed): PostgreSQL configuration for extensions requiring preload
Development
Prerequisites
- Go 1.24+
- Docker
- Optional: golangci-lint for linting
Building
# Build the binary
make build
# Run tests
make test
# Run all checks (format, vet, test)
make check
# Clean build artifacts
make clean
Testing
# Run tests
make test
# Run tests with coverage
make test-coverage
# Test export functionality
make export EXTS=pgvector,pg_cron PG_VERSION=18
# Run PostgreSQL with extensions
make run EXTS=pgvector,pg_cron PORT=5432
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Release Process (Maintainers)
Creating a Release
-
Ensure all changes are committed and pushed
git status
git push origin main
-
Run the release preparation script
./scripts/prepare-release.sh v0.3.0
This script will:
- Update the
VERSION file
- Update the
vendorHash in flake.nix
- Run tests
- Create a git commit and tag
-
Push the commit and tag
git push origin main
git push origin v0.3.0
-
GitHub Actions will automatically:
- Run tests and quality checks
- Build binaries for Linux and macOS (amd64/arm64)
- Create a GitHub release with pre-built binaries and checksums
-
Verify the release
./scripts/test-release.sh --tag v0.3.0
Testing Releases
# Test latest release (dry-run, no installation)
./scripts/test-release.sh --dry-run
# Test specific release with full installation
./scripts/test-release.sh --tag v0.2.2
# Test local release build
make release-snapshot
License
GPL-3.0