我正试图在我的数据库上运行VACUUM命令,但似乎空间不足:
> sqlite3 mydatabase.db "VACUUM"
Error: database or disk is full
数据库大约为36GB,我运行它的驱动器看起来像(通过df -h):
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 406G 171G 215G 45% /home
所以我显然超出了所需的双人尺寸限制。我该怎么做才能让真空命令运行?
Tyson:
要允许VACUUM命令运行,请将临时文件的目录更改为具有足够可用空间的目录。
SQLite的documentation表示临时目录是(按顺序):
使用PRAGMA temp_store_directory命令设置的任何内容;或
使用SQLITE_TMPDIR环境变量设置的任何内容;或
使用TMPDIR环境变量设置的任何内容;或
/var/tmp;或
/usr/tmp;或
/tmp;或
.,当前工作目录
OP注意到,在真空状态下,SQLite创建的临时文件大小与原始数据库大致相同。它这样做是为了维护数据库ACID属性。SQLite在执行真空操作时使用一个目录来保存所需的临时文件。为了确定要使用哪个目录,它会将层次结构下移,以查找具有适当访问权限的第一个目录。如果它找到一个它没有访问权限的目录,它将忽略该目录并继续下降层次结构以查找它有访问权限的目录。如果有人指定了一个环境变量,而SQLite似乎忽略了它,我会提到这个问题。
在他的回答中,CL给出了Linux的层次结构,并且在他的评论中提到了层次结构依赖于OS。为了完整起见,这里是层次结构(在我可以从代码中确定的范围内)。
ForUnix(andLinux) the hierarchy is:
Whatever is specified by theSQLITE_TMPDIRenvironment variable,
Whatever is specified by theTMPDIRenvironment variable,
/var/tmp,
/usr/tmp,
/tmp, and finally
The current working directory.
ForCygwinthe hierarchy is:
Whatever is specified by theSQLITE_TMPDIRenvironment variable,
Whatever is specified by theTMPDIRenvironment variable,
Whatever is specified by theTMPenvironment variable,
Whatever is specified by theTEMPenvironment variable,
Whatever is specified by theUSERPROFILEenvironment variable,
/var/tmp,
/usr/tmp,
/tmp, and finally
The current working directory.
For Windows the hierarchy is:
GetTempPath(), which is documented to return:
Whatever is specified by theTMP environment variable,
Whatever is specified by theTEMP environment variable,
Whatever is specified by the USERPROFILE environment variable, and finally
theWindowsdirectory.
。
希望这有帮助。
可能创建临时文件的驱动器没有足够的空间。看这里 Vacuum-command-is-failing-with-SQL-Error-Database-or-disk-is-full
网友评论