SQLite表磁盘使用情况

如何在SQLite数据库中查找单个表的磁盘使用情况,而不将其复制到新的空数据库中?

您可以使用http://www.sqlite.org/download.html中的; sqlite_anlyzer

这是一个非常酷的工具。 向您显示每个带有或不带索引的表所使用的页数(默认情况下,每个页面为1024字节)

这是Northwind数据库的一个示例sqlite3_analyzer.exe输出:

*** Page counts for all tables with their indices ******************** EMPLOYEES............................. 200 34.4% ORDERS................................ 152 26.2% CATEGORIES............................ 90 15.5% ORDER DETAILS......................... 81 13.9% CUSTOMERS............................. 17 2.9% SQLITE_MASTER......................... 11 1.9% PRODUCTS.............................. 7 1.2% SUPPLIERS............................. 7 1.2% TERRITORIES........................... 6 1.0% CUSTOMERCUSTOMERDEMO.................. 2 0.34% CUSTOMERDEMOGRAPHICS.................. 2 0.34% EMPLOYEETERRITORIES................... 2 0.34% REGION................................ 2 0.34% SHIPPERS.............................. 2 0.34% 

它还为space_used表生成sql,您可以在任何数据库中加载并分析使用情况。

我意识到这个答案完全违反了这个问题的精神,但它确实让你的大小没有复制文件…

 $ ls -lh db.sqlite -rw-r--r-- 1 dude bros 44M Jan 11 18:44 db.sqlite $ sqlite3 db.sqlite sqlite> drop table my_table; sqlite> vacuum; sqlite> ^D $ ls -lh db.sqlite -rw-r--r-- 1 dude bros 23M Jan 11 18:44 db.sqlite