# Why a PostgreSQL backend

> Who it is for, when it beats erasure-coded storage, and the alternatives that were evaluated.

---

LLMS index: [llms.txt](/llms.txt)

---

Many small-to-medium applications already run a managed or high-availability PostgreSQL cluster, yet still need an S3 endpoint for user attachments, avatars, PDF exports, or CI artifacts. Running a separate object storage cluster splits operational state across two systems: backups, point-in-time recovery (PITR), database clones, and access control must be coordinated twice and can drift apart.

`pgsilo` solves this by adding a PostgreSQL `ObjectLayer` backend to **Silo** (PGSTY's fork of MinIO), storing all object data, versions, bucket configurations, multipart uploads, and IAM state inside a single PostgreSQL database.

## Lessons from `pgs3` {#lessons-from-pgs3}

Before building `pgsilo`, PGSTY built [`pgs3`](/docs/s3/pgs3/), an in-process PostgreSQL extension in Rust/pgrx that speaks S3 from a background worker. `pgs3` (`v0.1.1`) passed 195 of 195 Ceph `s3-tests` cases and proved that S3 versioning, delete markers, conditional writes, and multipart semantics map cleanly onto PostgreSQL tables. However, it also exposed three structural trade-offs:

1. **Protocol surface maintenance**: implementing SigV4 variants, `aws-chunked` streaming, presigned URLs, POST policies, and modern SDK trailing checksums (`CRC32C`, `CRC64NVME`) from scratch inside a C/Rust extension is a major ongoing cost. Silo already implements the full HTTP and S3 wire layer.
2. **Write-path deduplication overhead**: `pgs3` used content-addressed SHA-256 chunk deduplication and reference counting, which added index lookups and row-lock contention on small-object writes. `pgsilo` drops deduplication: each segment belongs to a single object version or active upload and is deleted by cascade.
3. **Process isolation and managed PostgreSQL compatibility**: a compiled extension cannot be installed on locked-down managed PostgreSQL services, and an HTTP parser bug in a background worker runs inside the database process tree. `pgsilo` runs as a stateless external Go binary and installs only standard SQL tables and PL/pgSQL functions (`PostgreSQL 16+`).

> [!NOTE]
> The initial October 2026 PRD targeted PostgreSQL 18 as the baseline version, but the implemented schema 14 tables and PL/pgSQL functions avoid PostgreSQL 18-only DDL dependencies and run on **PostgreSQL 16, 17, and 18**.

## Target scenarios vs. anti-patterns {#scenarios}

| Priority | User / Scenario | Why `pgsilo` fits |
| --- | --- | --- |
| P1 | Business apps (Odoo, ERP, CRM) | Invoices, attachments, and business rows are backed up and restored together to the exact same PITR timestamp |
| P1 | Self-hosted Supabase / app platforms | Points Supabase Storage's S3 backend at the existing PostgreSQL cluster without provisioning dedicated object disks |
| P1 | Local development & CI pipelines | One PostgreSQL database backs both SQL tables and S3 buckets; `DROP DATABASE` resets the entire test environment |
| P2 | Private / on-premises appliance delivery | Ships S3 storage on customer infrastructure that only permits standard PostgreSQL instances |
| P2 | Transactional SQL + S3 workflows | Reads and writes objects inside `Read Committed` SQL transactions via `silo_api` and joins metadata with business tables |
{.wide}

**When NOT to use `pgsilo` (use Silo erasure-coded mode instead):**

- **Backing up the hosting PostgreSQL cluster itself**: never point a PostgreSQL cluster's own `pgBackRest` repository at a `pgsilo` instance stored inside that same cluster—if the database fails, the backup is unreachable.
- **Large objects (`> 256 MiB` default, `> 1 GiB` hard ceiling)**: video archives, LLM weights, and large Parquet lakes belong on erasure-coded disks.
- **High-throughput observability sinks**: continuous high-bandwidth write streams (Loki, Tempo, Mimir, Thanos) or CDN origin workloads.

## Silo PostgreSQL mode vs. Silo erasure-coded mode {#pg-vs-ec}

Both modes ship in the same `silo` binary and share the same S3 HTTP frontend, SigV4 authentication, IAM engine, and Console:

| Dimension | Silo PostgreSQL mode (`pgsilo`) | Silo erasure-coded mode |
| --- | --- | --- |
| Startup | `SILO_PG_DSN="postgresql://..." silo server` | `silo server /data{1...4}` |
| Recommended scale | `<= 200 GB` per database, `<= 10M` object versions, `<= 256 MiB` per object (max `1 GiB`) | Terabytes to petabytes; up to `5 TiB` per object |
| Where state lives | 100% in PostgreSQL tables (`silo` schema) | Local/distributed disks (`xl.meta` + erasure shards) |
| Unique strengths | Transactional SQL API (`silo_api`), unified `pgBackRest` PITR, stateless gateways | High streaming throughput, erasure coding, site replication, remote tiering |
| Rule of thumb | Choose when objects must share backup, PITR, or SQL transactions with relational data | Choose when object volume exceeds `200 GB` or sustained write throughput exceeds `50 MB/s` |
{.wide}

## Capacity and sizing rationale {#capacity-bounds}

- **Database object volume (`<= 200 GB` recommended)**: at typical `pgBackRest` restore speeds (`200`–`500 MB/s`), a 200 GB database restores in 7–17 minutes, keeping RTO predictable.
- **Object version count (`<= 10M` versions)**: at roughly `0.6 KB` of row and B-tree index metadata per version, 10 million versions occupy ~6 GB of catalog metadata, keeping `ListObjectsV2` and lifecycle index scans fast.
- **Segment size (`8 MiB` default, `1`–`64 MiB` configurable)**: PostgreSQL TOAST supports values up to 1 GB, but buffering a single large `bytea` requires 2–3x its size in gateway and backend memory. Splitting objects into 8 MiB rows bounds per-request memory to two segment buffers (`16 MiB`) regardless of total object size while matching the AWS CLI's default 8 MiB multipart chunk size.

---

Backlinks:

- [Design](/docs/s3/design/)
