SQLite table disk usage

后端 未结 5 1048
借酒劲吻你
借酒劲吻你 2021-01-30 08:39

How can I find out the disk usage of a single table inside a SQLite database without copying it in a new empty database?

5条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-30 08:53

    You can use sqlite3_analyzer from https://www.sqlite.org/download.html.

    It's a really cool tool. It shows you the number of pages used by each table with and without indexes (each page, by default, is 1024 bytes).

    This is a sample sqlite3_analyzer output for the Northwind database:

    *** 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% 
    

    It also generates SQL statements which can be used to create a database with usage statistics, which you can then analyze.

提交回复
热议问题