frn.sh

postgres vacuum and netbsd dir size

Running vacuum full in Postgres requires as much free disk space as your database currently occupies, since it rebuilds the entire table by copying all the non-deleted rows to a new file. vacuum on the other reclaims dead tuples space. Something similar occurs with directories in netBSD. If you create lots of files of 255 chars in a directory, the size of the directory will increase. If you delete all files, the size won’t decrease.

Suppose you run touch $( yes a | head -255 | tr -d '\n' ) three times, only replacing the letter. You would have a directory with something like this:

aaa… bbb… ccc…

Then, you delete “b” and create another file with the “d” letter. Since they both share the same size, the OS would understand that the new file can be placed between “a” and “c” (there’s a padding there now, since “b” was deleted):

aaa… ddd… ccc…