Documentation
¶
Overview ¶
Package sqliteutil provides shared SQLite health-check and recovery utilities.
Index ¶
- func CheckAndRecover(db *sqlx.DB, dbPath string) (bool, error)
- func CheckAndRecoverContext(ctx context.Context, db *sqlx.DB, dbPath string) (bool, error)
- func OpenWithRecovery(dbPath, dsn string) (*sqlx.DB, error)
- func OpenWithRecoveryContext(ctx context.Context, dbPath, dsn string) (*sqlx.DB, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CheckAndRecover ¶
CheckAndRecover attempts to detect and fix stale WAL/SHM files that cause "disk I/O error" on SQLite databases using WAL journal mode. This happens when a process crashes or doesn't cleanly close its connection, leaving behind -shm and -wal files that reference invalid shared memory state.
Recovery strategy:
- Try to ping the database
- If that succeeds, run PRAGMA integrity_check as a deeper validation
- If either fails, close the connection, remove stale -shm/-wal files, and return an error indicating the caller should retry
Returns (healthy bool, error). If healthy is false and error is nil, stale files were removed and the caller should reopen the connection.
func CheckAndRecoverContext ¶
CheckAndRecoverContext is like CheckAndRecover but respects context cancellation.
func OpenWithRecovery ¶
OpenWithRecovery opens a SQLite database with the given DSN, performing health checks and automatic WAL recovery if stale files are detected. It will attempt recovery once before giving up.
Types ¶
This section is empty.