PGRest is a cloud-native PostgreSQL connection pooler written in Go, designed as a fully compatible alternative to Supavisor. It provides advanced features like multi-tenant support, read/write splitting, and connection pooling with a RESTful API for management.
- High Performance: Support for 250,000+ idle connections per instance
- Multi-Tenant: Secure isolation between different databases/projects
- Connection Pooling: Transaction, Session, and Proxy modes
- Read/Write Splitting: Automatic query routing to read replicas
- Authentication: Full support for SCRAM-SHA-256, MD5, and password auth
- SSL/TLS: Client and server-side encryption with SNI support
- RESTful API: OpenAPI-compatible management interface
- Monitoring: Prometheus metrics and health checks
- Cloud Native: Kubernetes-ready with horizontal scaling
# Clone the repository
git clone https://github.com/pgrest/pgrest
cd pgrest
# Build the binary
make build
# Run with default configuration
./bin/pgrest# Run with Docker
docker run -p 5432:5432 -p 8080:8080 pgrest/pgrest:latest
# With custom configuration
docker run -p 5432:5432 -p 8080:8080 \
-e DATABASE_URL="postgres://user:pass@host/db" \
-e JWT_SECRET="your-secret" \
pgrest/pgrest:latestPGRest can be configured via environment variables or a configuration file:
# config.yaml
server:
port: 5432
api_port: 8080
ssl_enabled: true
pool:
default_size: 25
max_size: 100
idle_timeout: 900s
checkout_timeout: 30s
auth:
jwt_secret: ${JWT_SECRET}
api_blocklist: []
database:
url: ${DATABASE_URL}
max_connections: 10PGRest implements the full PostgreSQL wire protocol, sitting between your applications and PostgreSQL databases:
┌─────────────┐ ┌─────────────┐ ┌─────────────┐
│ Client │────▶│ PGRest │────▶│ PostgreSQL │
└─────────────┘ └─────────────┘ └─────────────┘
│
▼
┌─────────────┐
│ REST API │
└─────────────┘
curl -X PUT http://localhost:8080/api/tenants/my-project \
-H "Authorization: Bearer $JWT_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"db_host": "postgres.example.com",
"db_port": 5432,
"db_database": "mydb",
"users": [{
"db_user": "appuser",
"db_password": "secret",
"pool_size": 20,
"mode_type": "transaction"
}]
}'# Connect using standard PostgreSQL tools
psql "postgres://appuser.transaction@localhost:5432/mydb"
# Or with any PostgreSQL client libraryPGRest is designed for high performance and scalability:
- Throughput: Within 90% of direct PostgreSQL connections
- Latency: Sub-millisecond connection checkout
- Connections: 250,000+ idle connections per 16-core instance
- Memory: ~4KB per idle connection
# Install dependencies
go mod download
# Run tests
make test
# Build binary
make build
# Run locally
make runpgrest/
├── cmd/pgrest/ # Application entry point
├── internal/ # Internal packages
│ ├── api/ # REST API implementation
│ ├── auth/ # Authentication mechanisms
│ ├── pool/ # Connection pool implementation
│ ├── protocol/ # PostgreSQL wire protocol
│ └── tenant/ # Multi-tenant management
├── pkg/ # Public packages
└── test/ # Integration tests
PGRest exposes Prometheus metrics at /metrics:
pgrest_connections_active: Active connections by tenantpgrest_connections_total: Total connections createdpgrest_pool_checkout_duration: Pool checkout latencypgrest_query_duration: Query execution timepgrest_errors_total: Error count by type
We welcome contributions! Please see CONTRIBUTING.md for guidelines.
PGRest is licensed under the Apache License 2.0. See LICENSE for details.
PGRest maintains full API compatibility with Supavisor while offering:
- Better Performance: Optimized Go implementation
- Enhanced Multi-Database Support: Improved routing and cluster management
- Extended Monitoring: More detailed metrics and tracing
- Simplified Deployment: Single binary with minimal dependencies
- Documentation: https://pgrest.io/docs
- Issues: GitHub Issues
- Discussions: GitHub Discussions