Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Documentation regarding Consistency #323

Open
ackava opened this issue Sep 14, 2024 · 3 comments
Open

Documentation regarding Consistency #323

ackava opened this issue Sep 14, 2024 · 3 comments

Comments

@ackava
Copy link

ackava commented Sep 14, 2024

Can you please add some documentation about how to maintain consistency in terms of running it from browser?

  1. Can multiple PGLite easily access single storage (IndexedDB)?
  2. Will it corrupt the data? Do we need any external locking mechanism?
@samwillis
Copy link
Collaborator

Good idea, we should document this better.

For quick context, PGlite is Postgres in "single user mode". There is no support for concurrent connections and you are like to corrupt the database if you open it multiple times at once.

The PGliteWorker helps you to open only a single instance and share it across browser tabs.

@0xOlias
Copy link
Contributor

0xOlias commented Oct 14, 2024

Related question - is there any way to check if a target directory is currently in use by a PGlite instance?

It would be awesome if the PGlite constructor threw (or the waitReady promise rejected) with a descriptive error, e.g. "this dataDir is currently in use by another PGlite instance" rather than allow undefined behavior / data corruption. I'm using the Node.js filesystem, but I imagine this applies to the others as well.

I think this validation would be reasonable in either the init or initialSyncFs methods on the Filesystem interface.

// Sync the filesystem from any previous store
await this.fs!.initialSyncFs()

@samwillis
Copy link
Collaborator

Hey @0xOlias

Yep, we should absolutely do this.

In the browser I think the best way is to implement it with WebLocks, for Node we should open and lock a file in the FS.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants