Skip to content

Add data directory locking and partial corrupt initdb cleanup#892

Open
reisepass wants to merge 2 commits intoelectric-sql:mainfrom
reisepass:main
Open

Add data directory locking and partial corrupt initdb cleanup#892
reisepass wants to merge 2 commits intoelectric-sql:mainfrom
reisepass:main

Conversation

@reisepass
Copy link

@reisepass reisepass commented Feb 16, 2026

I'v been running into issues with pglite getting corrupted in persist to disk mode. The most human scenario is that you have on pnpm dev running in one window and then you start for a quick test not remembering that you already had one open. In my dev work this honestly happens daily so it was hard to use pglite practically as an sqlite replacement.

But simple fix just add a lock file.
This is nothing fancy since postgres assumes it has full control we just reject the second process trying to use the data dir.

And then another small fix for corruption that happens if the file was corrupted due to partial initialization, this is less common but might as-well add another little feature to make it more robust. If a file is there that is so corrupt you can't even find the PG_VERSION it just moves it to a backup and makes another.
^I would be fine also editing this out if someone doesn't like this behavior the Lock file is the important feature

reisepass and others added 2 commits February 17, 2026 00:31
Tests that FAIL without the fix — reproducing real corruption:
- Overlapping instances: triple, staggered, DDL writer, rapid cycling
- HMR double-instance: lock-based blocking and rapid swap corruption
- WAL bloat burst mode: rapid kills without checkpoint cause corruption

Co-Authored-By: Matthaus Wolff <8714327+WolffM@users.noreply.github.com>
- Add PID-based file lock to NodeFS to prevent overlapping instance corruption
- Detect partially-initialized data dirs and move to .corrupt-<timestamp> backup
- Add tests verifying partial init backup behavior
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant