Architecture
pgsilo is the PostgreSQL storage backend for Silo (internal/pgstore and cmd/pg-*), serving S3 as a service API protocol. Stateless Silo gateways handle the S3 wire protocol, SigV4 authentication, IAM evaluation, encryption and the Console front end. PostgreSQL stores object bodies, versions, multipart state, bucket configuration, IAM state and background maintenance leases.
flowchart LR
S3["S3 clients and Console"] --> GW["Silo gateway"]
APP["Business application"] --> SQL["silo_api public SQL functions"]
GW --> PG[("PostgreSQL primary")]
SQL --> PG
PG -->|"Physical replication"| REPLICA[("PostgreSQL standby")]
RGW["Read-only Silo gateway"] --> REPLICA
GW --> KEYS["Externally retained TLS and encryption keys"]Persistent data and schemas
Gateways keep no persistent local object directory. PostgreSQL stores object bodies as bytea segments of 8 MiB by default (configurable from 1 MiB to 64 MiB). The default object size limit is 256 MiB, and can be set up to 1 GiB when initializing the store. Object metadata and segments become visible in the same database transaction; concurrent readers never see half-written objects.
The database uses three schemas with separate responsibilities:
| Schema | Purpose | Application access |
|---|---|---|
silo | Private object bodies, metadata, versions, IAM, coordination and maintenance state | Do not grant access |
silo_api | Eleven public SQL functions for object and bucket operations | Grant explicit EXECUTE on required functions |
silo_bucket | One ACL relation per bucket for PostgreSQL native authorization | Grant explicit SELECT, INSERT, DELETE and other required privileges |
A bucket’s name is distinct from its internal identity and ACL relation. Deleting and recreating a bucket with the same name creates a new bucket identity and a new ACL relation in silo_bucket; previous grants, annotations and in-flight requests do not carry over.
Two access paths
Before an S3 HTTP request touches storage, the gateway verifies its SigV4 signature, S3 IAM permissions and bucket policy. When joint authorization (IAM AND PostgreSQL native authorization) is enabled, the gateway also checks the PostgreSQL privileges of the mapped role on silo_bucket.<bucket>. Each S3 HTTP request executes in its own database transactions and cannot join an application’s open SQL transaction.
A SQL application connects to PostgreSQL under its own login role and calls silo_api functions. It can modify business tables and S3 objects atomically inside a single Read Committed transaction. The SQL API identifies callers through session_user and rejects SET ROLE impersonation. The database owner (silo_owner) and its role members are blocked from calling silo_api.
The SQL API is intentionally narrower than S3 HTTP: it does not expose multipart upload APIs, annotation CRUD, SSE ciphertext decryption, Object Lock administration or governance-retention bypass, and direct SQL writes do not emit S3 bucket notifications. Applications that need reliable event delivery from SQL transactions should write to an application-owned transactional outbox table. See the SQL API reference.
Requests, connections and memory
Each gateway splits its PostgreSQL connections across three pools. With the default limit of 32 connections (SILO_PG_MAX_CONNS=32), 4 connections are reserved for the control pool, 2 for the coordination pool, and 26 for the data pool:
- Data pool (26): serves object reads, writes, listings and
CopyObject(which requires at least two data connections). - Control pool (4): serves bucket configuration and metadata lookups so long object transfers cannot starve control operations.
- Coordination pool (2): reserves connections for IAM writes,
LISTEN/NOTIFYrevision channels and lease heartbeats.
Above 32 concurrent S3 API requests on a single gateway, additional requests wait for a free slot for up to SILO_PG_QUEUE_TIMEOUT (5 s by default) without holding a database connection, then receive HTTP 503 SlowDown, which SDKs retry. This queue was added in 1d387725c (2026-11-08); earlier builds, including 299378b and the frozen 3c7fdc03, answer HTTP 429 TooManyRequests at once. Segmented I/O bounds per-buffer memory, but each active stream still holds a connection, buffer memory and a database snapshot. See Configuration for pool settings.
Multiple gateways and authorization freshness
Multiple writable gateways connected to the same PostgreSQL primary share all buckets, objects and IAM state. Each gateway caches IAM state in memory and refreshes it via PostgreSQL LISTEN/NOTIFY plus periodic polling. Cached IAM state is valid for a bounded lease of at most 5 seconds; if a gateway cannot confirm a fresh revision token within the lease bound, it fails closed and rejects requests.
Read-only gateways (Preview) can connect to physical PostgreSQL standbys. Standby reads may lag behind the primary or be canceled by recovery conflicts. Standby authorization relies on continuous control heartbeats written by a writable gateway on the primary, and clocks between primary and standby hosts must differ by no more than 500 ms.
PostgreSQL high-availability tooling (such as Patroni) owns primary election and old-primary fencing. See High availability and IAM control plane for details.
Maintenance and recovery
Even if applications access objects exclusively through SQL, keep at least one writable Silo gateway connected to the PostgreSQL primary. The writable gateway maintains control-plane heartbeats and runs lease-guarded background workers for lifecycle expiration and unlinked annotation garbage collection. Read-only standby gateways cannot run these workers.
Durability and recovery rely on PostgreSQL WAL, physical backups and PITR, plus externally backed-up TLS certificates and KMS static keys. See Compatibility and Storage layout.
