pgs3
pgs3 embeds an S3-compatible HTTP server directly inside PostgreSQL background workers. S3 clients (mc, rclone, boto3, DuckDB, s3fs) talk to the endpoint over SigV4 path-style HTTP, while SQL sessions read and write the exact same buckets and objects inside normal database transactions.
pgs3 is currently in early alpha (v0.1.2, release acceptance on PostgreSQL 17–19 on Linux). Small-object throughput targets and the 100,000-object bucket fork target are still being optimized. Review the measured performance and limits before sizing production workloads.
Why store objects in PostgreSQL
Running a separate object store alongside PostgreSQL splits state across two systems: a database rollback can leave orphan blobs behind, backups capture two different timestamps, and tenant isolation has to be maintained twice. pgs3 collapses those boundaries into one PostgreSQL database:
- One transaction boundary: Write application metadata and object bytes in the same SQL transaction—commit together or roll back together.
- One backup and PITR timeline: Physical base backups and WAL archiving recover relational tables, object payloads, versions, and credentials to the same point in time.
- Database-native multi-tenancy: Every S3 access key maps to a PostgreSQL
NOLOGINrole. Bucket and object visibility is enforced by PostgreSQL Row-Level Security (RLS). - Always-on versioning and instant forks: Overwrites append new versions, ordinary deletes insert delete markers, and
pgs3.fork_bucket()clones a bucket’s latest state by sharing content-addressed SHA-256 blobs.
When to use pgs3 (and when not to)
| Workload | Recommendation | Why |
|---|---|---|
| Application attachments, invoices, configs, or AI agent artifacts that must stay consistent with relational rows | Use pgs3 | Shared transactions, unified PITR, and zero extra storage cluster to operate |
| Multi-tenant SaaS workspaces or experiment checkpoints needing cheap bucket forks | Use pgs3 | RLS tenant isolation and copy-on-write pgs3.fork_bucket() |
| Multi-terabyte media archives, high-fanout public CDN origins, or workloads requiring bucket policies/ACLs/lifecycle rules | Use a dedicated S3 store such as Silo | Dedicated object stores avoid PostgreSQL WAL amplification, TOAST overhead, and full-GET buffering |
How pgs3 works
flowchart LR
C["S3 Client (mc / rclone / SDK)"] -->|SigV4 Path-Style HTTP| W["pgs3 HTTP Workers"]
W -->|"SET LOCAL ROLE (RLS)"| SQL["pgs3 SQL API"]
APP["SQL Session / App"] -->|Direct Transaction| SQL
SQL --> META["pgs3.bucket & pgs3.object"]
SQL --> BLOB["pgs3.blob (SHA-256 Dedup)"]
BLOB -->|"<= 64 KiB"| INLINE["Inline bytea"]
BLOB -->|"> 64 KiB"| CHUNK["Chunked / Multipart Extents"]
- HTTP workers handle the wire protocol: Background workers listen on a shared
SO_REUSEPORTTCP port (default127.0.0.1:9000), verify AWS SigV4 signatures, and map each access key to its PostgreSQL tenant role. - SQL enforces all semantics: Inside short transactions, workers run
SET LOCAL ROLEand invoke the samepgs3.*SQL functions that direct SQL callers use. Versioning, preconditions, locking, and RLS isolation live in one place. - Blobs are deduplicated by SHA-256: Every object version points to a canonical content-addressed blob. Small payloads stay inline (
pgs3.inline_threshold, default 64 KiB); larger uploads stream into 4 MiB chunks (pgs3.chunk_size) without holding long database transactions.
Install pgs3, launch a local S3 endpoint inside PostgreSQL, and walk through uploading, overwriting, deleting, and recovering an earlier version with mc (MinIO Client) in three minutes.
Configure mc, rclone, Python boto3, DuckDB httpfs, and s3fs to talk to pgs3. Every client needs three settings: SigV4 signing, path-style addressing, and an explicit endpoint URL.
Go beyond standard S3 with PostgreSQL-native workflows: commit objects in the same transaction as relational rows, restore historical versions, fork whole buckets without copying bytes, and isolate tenants with RLS.
Run pgs3 persistently on PostgreSQL startup, build from source or Docker, terminate TLS in Nginx, route primary/standby traffic, and handle backups, monitoring, and upgrades.
Measured PUT/GET throughput and latency curves comparing pgs3 v0.1.2 against MinIO on the same host, scale benchmarks for LIST and bucket forks, and hard workload boundaries.
Complete lookup for pgs3 v0.1.2: server GUCs, S3 API compatibility subset, SQL functions, and SQLSTATE-to-S3 error mappings.