Trying to vacuum all databases under /data with sqlite3, but fails with error 14 I would like to vacuum all my database files under /data, to achieve somewhat better performance so I ran the following script:

for i in $(find /data -iname "*.db"); do
#echo $(basename $i);
sqlite3 $i 'VACUUM;';
resVac=$?
if [ $resVac == 0 ]; then
    resVac="SUCCESS";
else
    resVac="ERRCODE-$resVac";
fi;

sqlite3 $i 'REINDEX;';
resIndex=$?
if [ $resIndex == 0 ]; then
    resIndex="SUCCESS";
else
    resIndex="ERRCODE-$resIndex";
fi;
echo "Database $i:  VACUUM=$resVac  REINDEX=$resIndex" | tee -a /data/vacuum.log
done


As you can see this script vacuums and reindexes each database file under /data. REINDEX works fine, but VACUUM does not. It returns "Error: unable to open database file". (error code 14)

I am dealing with /data. So, it can't be a mount problem.
Unlike REINDEX, the VACUUM command needs to create a new temporary file to work in. It then replaces the database file with this temporary file. This means that it needs write access, not only to the database file, but also to the directory it's in.