I was watching the progress and write-speed estimates while writing a 15 GB SQLite database to a USB flash drive and noticed that the speed varies from a short-interval high of over 400 MB to a short-interval low of 20 MB; and not just that it starts out fast and continually slows down but it fluctuates during the entire write time.
That caused me to wonder how a database file is stored on disk. Is it scattered all over the drive in pieces, at most as large as a single database write?
If one performs a vacuum of some kind on the database, will it then be written anew as one giant block or will it still be scattered and only the empty blocks are released?
When I plug the drive into another machine to backup the database a second time, it writes much quicker from the flash drive to the machine than from the macine to the drive. Both machines have SSD.
I ask for two reasons.
- Out of curiosity over the mentioned write speeds and wondered if the speed increases when a large part of the data is close together on the hard drive, such as when I wrote a large number of BLOBs in one script; and is slower when it has to collect data from many, many updates made over time to smaller rows of data.
- I wonder what happens to database efficiency over time when the data is often updated, such as using a piece table for editing text files.
I read somewhere that I cannot recall at the moment that Linux store data on disk differently than Windows such that it sort of “self-corrects” in that on HDD there is no need to de-fragment the disk. I’m using SSD but am asking with respect to similar thought of a database being “fragmented” across an SSD.
Thank you.