# pgs3 reference

> Complete lookup for pgs3 v0.1.2: server GUCs, S3 API compatibility subset, SQL functions, and SQLSTATE-to-S3 error mappings.

---

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

---

## Server configuration (GUCs) {#settings}

All nine `pgs3.*` parameters have `SIGHUP` context, though some changes only take effect for new requests or require a restart as noted below.

| Name | Type | Default | Meaning |
| --- | --- | --- | --- |
| `pgs3.enabled` | boolean | `off` | Register the static launcher on server startup when `pgs3` is in `shared_preload_libraries`. Dynamic `pgs3.start()` ignores this flag. |
| `pgs3.workers` | integer (1–64) | `4` | Desired number of HTTP background workers. Each consumes one `max_worker_processes` slot. |
| `pgs3.listen_addr` | string (IP) | `127.0.0.1` | IPv4 or IPv6 bind address for HTTP workers. Keep on loopback and terminate TLS in a reverse proxy. |
| `pgs3.port` | integer (1–65535) | `9000` | Shared `SO_REUSEPORT` TCP port for HTTP workers. |
| `pgs3.inline_threshold` | integer (bytes, 0–1 GiB) | `65536` | Largest physical blob stored inline in `pgs3.blob` for new writes. Direct single-transaction PUT has an additional 64 KiB cap. |
| `pgs3.chunk_size` | integer (bytes, 64 KiB–16 MiB) | `4194304` | Chunk size for staged uploads exceeding the inline threshold; snapshotted per upload on admission. |
| `pgs3.statement_timeout_ms` | integer (ms, 1–3600000) | `30000` | PostgreSQL statement/lock timeout for each SPI semantic transaction. Applies to new transactions. |
| `pgs3.target_database` | string | `postgres` | Database served by the preloaded static launcher. Changing the pool's database requires a server restart. |
| `pgs3.server_role` | string | `pgs3_server` | Restricted service identity used by HTTP workers. Custom roles must exist beforehand and be `NOLOGIN NOINHERIT` with no elevated attributes, no inbound members, and `SET`-only membership in tenant roles. |
{.fields meta="type default"}

### Inspect live values {#inspect}

```sql
SELECT name, setting, unit, context, source, pending_restart
FROM pg_settings
WHERE name LIKE 'pgs3.%'
ORDER BY name;
```

### Reload vs. restart {#reload}

- **Applies on `SIGHUP` reload**: `pgs3.workers`, `pgs3.listen_addr`, `pgs3.port`, `pgs3.statement_timeout_ms`, `pgs3.inline_threshold` (new blobs), and `pgs3.chunk_size` (new uploads). Existing blobs keep their original physical layout. Always verify a real signed request after a port/address rebind because a failed bind can keep the old listener running.
- **Requires a server restart**: Adding `pgs3` to `shared_preload_libraries`, changing `pgs3.enabled` from `off` to `on` when the static launcher was not registered at boot, or changing `pgs3.target_database`.
- **Service role changes**: Reconciling a changed `pgs3.server_role` on reload requires matching grants and lacks release acceptance testing; prefer a planned restart.

### Fixed implementation thresholds {#fixed}

These limits are built into `v0.1.2` and have no registered GUC:

- **Upload lease**: 5 minutes; **body-idle timeout**: 60 seconds (renewed on subsequent body progress).
- **Pending upload retention**: 24 hours; **GC interval**: every 60 seconds, up to 1,000 rows per batch.
- **SQL hash fallback limit**: Optional `pgs3.sql_hash_fallback_limit` custom setting defaults to `134217728` bytes (128 MiB); packaged builds use Rust hash helpers instead.

## S3 API compatibility {#api}

| Area | Supported APIs | Behavior and boundaries |
| --- | --- | --- |
| Buckets | `ListBuckets`, `CreateBucket`, `DeleteBucket`, `HeadBucket`, `GetBucketLocation`, `GetBucketVersioning` | Versioning is permanently `Enabled`. `DeleteBucket` requires an empty bucket (including historical versions); pending uploads alone are aborted atomically on delete. |
| Objects | `PutObject`, `GetObject`, `HeadObject`, `CopyObject`, `DeleteObject`, `DeleteObjects` | Supports single `Range`, `If-Match`/`If-None-Match`/date conditions, `x-amz-meta-*` metadata, source `versionId` copies, and SHA-256 / MD5 / flexible checksums. `DeleteObjects` accepts up to 1,000 keys per batch. |
| Listing | `ListObjects` (V1), `ListObjectsV2`, `ListObjectVersions` | Prefix, delimiter, `encoding-type=url`, `max-keys` (0–1000), V1 markers, and V2 continuation tokens. |
| Multipart | `CreateMultipartUpload`, `UploadPart`, `ListParts`, `CompleteMultipartUpload`, `AbortMultipartUpload` | Non-final parts must be ≥ 5 MiB. `UploadPartCopy` and `ListMultipartUploads` are not supported. |
| Version restore | `POST /{bucket}/{key}?restore&versionId={id}` | `pgs3` extension route that publishes an older version as the new latest version (not AWS Glacier archival restore). |

### Signing and unsupported features {#signing}

- **Supported auth**: Header-based AWS SigV4 (`FullHash`, `UNSIGNED-PAYLOAD`, `STREAMING-AWS4-HMAC-SHA256-PAYLOAD`, `STREAMING-UNSIGNED-PAYLOAD-TRAILER`) and query-parameter presigned GET/PUT URLs (max expiry 7 days, clock skew ±15 minutes).
- **Outside the subset**: Virtual-host bucket addressing, TLS termination, bucket policies, ACLs, CORS, object tagging, lifecycle/TTL rules, object lock/retention, multi-range GET, `UploadPartCopy`, and `ListMultipartUploads`.

## SQL API {#sql}

Tenant operations run under the caller's PostgreSQL role (with RLS isolation); operator functions are revoked from `PUBLIC`.

### Buckets and objects

| Name | Type | Default | Meaning |
| --- | --- | --- | --- |
| `pgs3.create_bucket(p_name text, p_config jsonb)` | `bucket_info` | `p_config = '{}'` | Create a bucket owned by the current role (idempotent for the same owner). |
| `pgs3.list_buckets()` | `setof bucket_info` | — | List buckets visible to the current role. |
| `pgs3.delete_bucket(p_name text)` | `boolean` | — | Delete an empty bucket (aborts leftover pending uploads). |
| `pgs3.put(p_bucket text, p_key text, p_body bytea, p_content_type text, p_meta jsonb, p_if_none_match text, p_if_match text, p_checksum_sha256 bytea)` | `object_info` | `'application/octet-stream', '{}', NULL, NULL, NULL` | Atomically write a new object version; supports ETag preconditions and SHA-256 verification. |
| `pgs3.head(p_bucket text, p_key text, p_version_id bigint, p_if_match text, p_if_none_match text)` | `object_info` | `NULL, NULL, NULL` | Read object metadata for the latest or specified version. |
| `pgs3.get(p_bucket text, p_key text, p_version_id bigint, p_if_match text, p_if_none_match text)` | `object_data` | `NULL, NULL, NULL` | Read object metadata and full `body bytea`. |
| `pgs3.get_range(p_bucket text, p_key text, p_start bigint, p_end bigint, p_version_id bigint, p_if_match text, p_if_none_match text)` | `bytea` | `NULL, NULL, NULL, NULL` | Read an inclusive 0-based byte slice of an object. |
| `pgs3.copy(p_source_bucket text, p_source_key text, p_destination_bucket text, p_destination_key text, p_source_version_id bigint, p_content_type text, p_meta jsonb, p_if_none_match text, p_if_match text, p_source_if_match text)` | `object_info` | `NULL` for optional params | Copy an object or version by sharing its canonical SHA-256 blob. |
| `pgs3.delete(p_bucket text, p_key text, p_version_id bigint)` | `delete_result` | `p_version_id = NULL` | Insert a delete marker when `p_version_id` is NULL, or permanently delete that version. |
| `pgs3.list(p_bucket text, p_prefix text, p_delimiter text, p_start_after text, p_continuation_token text, p_max_keys integer)` | `setof list_entry` | `'', NULL, NULL, NULL, 1000` | List keys and common prefixes in indexed key order. |
| `pgs3.restore(p_bucket text, p_key text, p_version_id bigint, p_if_match text)` | `object_info` | `p_if_match = NULL` | Publish a historical version's payload as a new latest version. |
| `pgs3.fork_bucket(p_source_bucket text, p_destination_bucket text, p_destination_config jsonb)` | `bigint` | `p_destination_config = NULL` | Create a new bucket sharing the source's latest blobs and return the number of entries copied. |
{.fields meta="type default"}

### Credentials and runtime operations

| Name | Type | Default | Meaning |
| --- | --- | --- | --- |
| `pgs3.create_credential(p_access_key text, p_secret text, p_role_name name, p_enabled boolean)` | `boolean` | `p_enabled = true` | Operator only. Create an S3 key pair bound to an unprivileged tenant role. |
| `pgs3.rotate_credential(p_access_key text, p_new_secret text)` | `boolean` | — | Operator only. Replace the signing secret for an existing key. |
| `pgs3.set_credential_role(p_access_key text, p_role_name name)` | `boolean` | — | Operator only. Reassign an access key to another unprivileged tenant role. |
| `pgs3.set_credential_enabled(p_access_key text, p_enabled boolean)` | `boolean` | — | Operator only. Suspend or re-enable an access key. |
| `pgs3.delete_credential(p_access_key text)` | `boolean` | — | Operator only. Delete an access key. |
| `pgs3.start()` | `boolean` | — | Operator only. Start a dynamic worker pool for the current database. |
| `pgs3.stop()` | `boolean` | — | Operator only. Stop the dynamic worker pool in the current database. |
| `pgs3.extension_version()` | `text` | — | Return the installed SQL catalog version of `pgs3`. |
| `pgs3.worker_state` | table | — | Live launcher, GC, and HTTP worker status, listener address, and heartbeats. |
| `pgs3.stats` | view | — | Aggregated HTTP request counters, errors, latency buckets, bytes, and GC/upload backlog. |
| `pgs3.gc_pending_uploads(p_max_age interval, p_limit integer)` | `bigint` | — | Operator only. Clean up expired pending uploads in bounded batches. |
| `pgs3.gc_blobs(p_limit integer)` | `bigint` | `1000` | Operator only. Delete unreferenced zero-refcount blobs in bounded batches. |
{.fields meta="type default"}

## SQLSTATE to S3 error mapping {#errors}

| SQLSTATE | HTTP | S3 error code |
| --- | --- | --- |
| `P3B01` | 404 | `NoSuchBucket` |
| `P3K01` | 404 | `NoSuchKey` / `NoSuchVersion` |
| `P3U01` | 404 | `NoSuchUpload` |
| `P3C01` | 412 | `PreconditionFailed` |
| `P3N01` | 304 | `NotModified` (no XML body) |
| `P3R01` | 416 | `InvalidRange` |
| `P3E01` | 409 | `BucketAlreadyExists` |
| `P3F01` | 409 | `BucketNotEmpty` |
| `P3H01` | 400 | `BadDigest` |
| `P3P01` | 400 | `InvalidPart` / `InvalidPartOrder` / `EntityTooSmall` |
| `P3S01` | 400 | `EntityTooLarge` |
| `42501` | 403 | `AccessDenied` |
| `25006` | 503 | `ServiceUnavailable` (read-only standby) |
| `57014` | 503 | `SlowDown` (statement timeout) |
| `0A000` | 501 | `NotImplemented` |
| other | 500 | `InternalError` |

An allowlisted `pgs3.error=<code>` diagnostic detail takes precedence to distinguish finer variants such as `NoSuchVersion`, `InvalidBucketName`, or `EntityTooSmall`. `HEAD` and `304` responses omit XML bodies. For the complete protocol-to-SQL mapping, see [api-sql-mapping.md](https://github.com/pgsty/pgs3/blob/v0.1.2/docs/api-sql-mapping.md).

---

Backlinks:

- [Operations](/docs/pgs3/operations/)
- [Performance](/docs/pgs3/performance/)
- [SQL & tenants](/docs/pgs3/workflows/)
