BSDDB Pack function?
Robert Roy
rjroy at takingcontrol.com
Tue Feb 15 21:08:26 EST 2000
(from Robin's Reference Guide)
ref B-Tree dbs
Space freed by deleting key/data pairs from the database is never
reclaimed from the filesystem, although it is reused where possible.
This means that the btree storage structure is grow-only. If
sufficiently many keys are deleted from a tree that shrinking the
underlying database file is desirable, this can be accomplished by
creating a new tree from a scan of the existing one.
You don't have to export to ascii and re-import. Try something like
this.
from TCS.bsddb import db
d = db.DB()
d.open('test.db', db.DB_BTREE)
e = db.DB()
e.open('test2.db', db.DB_BTREE, db.DB_CREATE)
c=d.cursor()
try:
while 1:
key,val = c.next()
print key,val
e[key]=val
except db.error, val:
print 'errror', val
c.close()
e.close()
d.close()
On Tue, 15 Feb 2000 11:06:32 -0500, "Warren Postma"
<embed at geocities.com> wrote:
>> approximately 3 times faster using your bsddb.
>
>Well it finished running in under an hour, whereas the stock python bsddb
>library took over four hours to finish. However, at the end, when I had
>deleted around 150,000 rows from the table, leaving 25,000 rows, the file
>itself had not "shrunk" at all and was still over 200 mb. This is okay,
>since it's rare that you'd really want to deallocate the disk space, since
>it's just going to get used again next time you add more records, however a
>"pack" function (like we had for dbf files) would be nice.
>
>Is there one or must I export the file to flat ASCII, and re-create a file
>to pack it down when much data is deleted?
>
>Warren Postma
>
>
More information about the Python-list
mailing list