electric-sql / pglite

Lightweight WASM Postgres with real-time, reactive bindings.
https://pglite.dev
Apache License 2.0
9.48k stars 204 forks source link

wip: HTTP VFS for read only access to a datadir on a web server #364

Open samwillis opened 1 month ago

samwillis commented 1 month ago

Export a database from PGlite with dumpDataDir, with this is now includes an index.json as a file listing. Untar to a web server, use the HttpFs vfs, and point it at the dir on the server:

const pg = await PGlite.create({
  fs: new HttpFs("http://localhost/pglite/examples/pgdata", { 
    fetchGranularity: 'file', // 'file' or 'page'
  }),
});

fetchGranularity is self explanatory, when set to "file" it will download the hole file when it is first read, "page" downloads individual file pages using a http range header.

Has support for:

Demo site: https://pglite-httpfs-demo.netlify.app

https://github.com/user-attachments/assets/5e9c8224-1899-4be5-8559-f642892bdebc

github-actions[bot] commented 1 month ago

Built bundles:

github-actions[bot] commented 1 month ago

🚀 Deployed on https://6705845cda92212e1566b5e9--pglite.netlify.app

thruflo commented 1 month ago

Could this work naturally with S3 / an S3 compatible file store?

samwillis commented 1 month ago

@thruflo yes, for a read path it's trivial. For a write path it would be possible to also make work. But still single connection.

Although this is "read only", it actually maintains an "overlay" of writes on each file. So it's really a snapshot loaded over http, with in-memory writes. It just doesn't write back to the server.

nestarz commented 1 month ago

Can we imagine a read/write FS to S3-like storage and in an env where workers (multi-thread) is not allowed ?