问题
I spent an hour scouring the many other threads with this exact problem and trying to apply the solutions, but half the threads say the problem is that the disk is full (it's not), and for the rest, I couldn't understand the answers or they didn't work for me.
My db file is 8MB and my SSD has 314GB free. The only other volume is my iCloud Drive which has 237MB free.
Other threads suggest changing the volume the temporary directory is on, but:
(1) Both my volumes have plenty of free space.
(2) I can't find directions for how to set the temp directory. Trying syntax like the following gives a syntax error: SQLITE_TMPDIR = '/path/'
(3) I can't find directions for how to show what the current temporary directory is. [UPDATE: Typing "env" into the terminal shows TMPDIR=/var/folders..., which is on my SSD, with no space restrictions that I know of.]
UPDATE: Running pragma_integrity_check, I get:
On tree page 1206 cell 0: invalid page number 1658652726
On tree page 746 cell 0: invalid page number 205562142
On tree page 94 cell 0: invalid page number 1932643690
Page 1051 is never used
Page 1079 is never used
Page 1385 is never used
UPDATE: Various suggested ways of trying to recover the corrupt database are failing.
(1) RECOVER. In my code below, "sqlite>" is the command prompt. I get to it by entering "sqlite3" into the Terminal.
sqlite>$ sqlite3 -batch bad.db .recover > salvaged.sql; # Unrecognized token $
sqlite>sqlite3 -batch bad.db .recover > salvaged.sql; # Error: near "sqlite3": syntax error
sqlite>-batch bad.db .recover > salvaged.sql; # Error: near "-": syntax error
(2) VACUUM INTO
Got a syntax error. Discovered my SQLite version was too old. Downloaded new version, looked for instructions on how to upgrade. Found "brew update sqlite". Tried it, got error, Ruby too old. Updated Ruby. Tried "brew update sqlite" again, got error, "Error: sqlite not installed." Tried "brew install sqlite", got error "sqlite is keg-only, which means it was not symlinked into /usr/local, because macOS provides an older sqlite3."
(3) VACUUM ONE TABLE
My database has only one table.
回答1:
Since the database file is corrupted, you will have to attempt a recovery. I'd start by using VACUUM with an INTO clause, e.g.
VACUUM INTO 'recovery.db';
If that doesn't work, then try vacuuming one table at a time.
回答2:
The best way to try to recover data from a corrupt database is with the sqlite3 command line program's .recover
command, which prints out SQL DDL statements for as much of the data as it can salvage.
Example:
$ sqlite3 -batch bad.db .recover > salvaged.sql
See the documentation for complete details.
You'll probably want the latest version of the sqlite3
shell, either as a downloaded binary or built from source, as .recover
was improved in version 3.30.
来源:https://stackoverflow.com/questions/58739973/database-or-disk-is-full-on-vacuum-with-plenty-of-free-space