Recreating S3 in Postgres using PostgREST
A simple S3-like file server can be built inside Postgres by storing binary data in a BYTEA table and exposing it through PostgREST's functions-as-RPC via the Neon Data API. A custom "*/*" domain lets a PL/pgSQL function return arbitrary media types and set Content-Type, Content-Disposition and Cache-Control headers, and generated columns compute size, MIME type and SHA-256 hash. Row-level security policies on anonymous and authenticated roles, with JWT-based user IDs, restrict access to public or owned blobs. Tables grant SELECT to anonymous users by default, so RLS setup is essential, and the pattern is meant as a teaching vehicle rather than a real S3 replacement.
Related posts
- Storage is now available in Supabase
Supabase mediumAdeptSupabase Storage is an object store built as a custom TypeScript/Fastify API server behind Kong, with object metadata and access policies kept in each project's Postgres database and objects stored in S3. Existing servers like Minio, Ceph and Zenko were rejected because they couldn't use Postgres as their datastore, carried features unnecessary on managed backends, and didn't map to Supabase Auth. Authorization uses Postgres Row Level Security on a storage.objects table: if a user can select or delete the row, they can read or delete the object, so policies are written in SQL and listing filters happen in the database. Uploads stream through Node streams to S3 with minimal buffering, trading off knowing the object size upfront, and objects get a default 1-hour Cache-Control header.
- Supabase Storage now in Beta
Supabase mediumAdeptSupabase Storage moves to Beta with range-request streaming for audio/video, whole-bucket public visibility (private by default, to avoid S3-style per-object exposure), directory uploads via the File and Directory Entries API, an RLS policy editor with SQL templates, and a local-filesystem backend so self-hosted setups need no S3. To keep supabase-js small and universal without a FormData polyfill or separate Node/browser bundles, the server now accepts raw binary bodies, letting clients upload Buffers, Blobs and Node streams. The dashboard emulates filesystem semantics on S3: move becomes copy-then-delete, and placeholder files keep empty directories from disappearing. Upsert support and list virtualization for large buckets are also added.
- How to Set Up Row-Level Security in Postgres Using AWS Cognito
Neon mediumAdept
Postgres row-level security can be driven by AWS Cognito JWTs: a Cognito User Pool issues tokens, and Neon Authorize validates them and maps claims like `sub` into Postgres session variables. A `notes` table gets an RLS policy comparing `user_id` to `current_setting('jwt.claims.sub')`, so each user sees only their own rows. The demo app uses Express.js, HTMX and the Neon serverless driver, with step-by-step setup for Cognito, the database schema, environment variables and policy verification. Neon has since folded this functionality into the Neon Data API.
- How to create an AWS S3 bucket for Postgres backups
Neon mediumAdept
Part 1 of a series on automating nightly Postgres backups from many Neon projects to S3 via scheduled GitHub Actions covers the AWS setup. It registers GitHub's OIDC identity provider (token.actions.githubusercontent.com, audience sts.amazonaws.com), creates a web-identity IAM role scoped to a specific repository, and creates a general-purpose S3 bucket. A bucket policy then grants that role List, Get, Put and Delete access. Bucket region matters, since distance from the databases lengthens backup jobs, and the account ID, bucket name and role name should be stored as GitHub Secrets for part 2.
- Is “SQL from the frontend” viable?
Neon easyNovice
Letting the frontend query the database directly, via tools like PostgREST or Firebase, can sharply speed up development by removing backend abstraction layers and frontend/backend team dependencies, which makes it attractive for prototypes and many apps. It does not have to replace the backend, which still holds secrets and sensitive logic. Exposing a database safely would require query-shape and parameter allow-listing with tooling to maintain the lists, per-IP rate limiting, and database-level authorization such as Postgres Row-Level Security. The verdict is that the approach is not production-ready yet, and Neon is exploring it through its RLS work, now part of the Neon Data API.