I had the same problem: on a macOS system with a shelf about 4 megabytes in size, the data grew to a huge size of 29 gigabytes on disk! This obviously happened because I updated the same pairs of key values ββin the shelf again and again.
Since my regiment was based on GNU dbm, I was able to use its hint of reorganization. Here is the code that returned my file in the shelf to its normal size in a few seconds:
import dbm db = dbm.open(shelfFileName, 'w') db.reorganize() db.close()
I am not sure if this method will work for other (non GNU) dbms. To test your dbm system, remember the code shown by @hynekcer:
import dbm print( dbm.whichdb(shelfFileName) )
If GNU dbm is used by your system, this should output 'dbm.gnu' (this is the new name for the old gdbm).
source share