How can I find out the disk usage of a single table inside a SQLite database without copying it in a new empty database?
I ran into issues with the other answers here (namely sqlite_analyzer not working on Linux). 'Ended up creating the following Bash function to (temporarily) write out each table to disk as a way of assessing the on-disk size. Technically this is copying the db, which is not in the spirit of OP's question, but it gave me the information I was after.
function sqlite_size() {
TMPFILE="/tmp/__sqlite_size_tmp"
DB=$1
IFS=" " TABLES=`sqlite3 $DB .tables`
for i in $TABLES; do
\rm -f "$TMPFILE"
sqlite3 $DB ".dump $i" | sqlite3 $TMPFILE
echo $i `cat $TMPFILE | wc -c`
\rm -f "$TMPFILE"
done
}
Example:
$ sqlite_size sidekick.sqlite
SequelizeMeta 12288
events 16384
histograms 20480
programs 20480