Why does clearing an SQLite database not reduce its size?

前端 未结 2 840
醉话见心
醉话见心 2020-12-10 02:46

I have an SQLite database.

I created the tables and filled them with a considerable amount of data.

Then I cleared the database by deleting and recreating t

相关标签:
2条回答
  • 2020-12-10 03:02

    From here:

    When an object (table, index, trigger, or view) is dropped from the database, it leaves behind empty space. This empty space will be reused the next time new information is added to the database. But in the meantime, the database file might be larger than strictly necessary. Also, frequent inserts, updates, and deletes can cause the information in the database to become fragmented - scrattered out all across the database file rather than clustered together in one place.

    The VACUUM command cleans the main database by copying its contents to a temporary database file and reloading the original database file from the copy. This eliminates free pages, aligns table data to be contiguous, and otherwise cleans up the database file structure.

    0 讨论(0)
  • 2020-12-10 03:05

    Databases sizes work like water marks e.g. if the water rises the water mark goes up, when the water receeds the water mark stays where it was

    You should look into shrinking databases

    0 讨论(0)
提交回复
热议问题