删除条目时python bsddb不会刷新

2024-10-04 03:19:57 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个python BSDDB数据库。显然,它存储在硬盘上。当我删除一些条目时,驱动器上的文件不会变小(因此-它增长得相当快…)

utDelList   = []
urlsDelList = []
for ut in iter(self.urls2task):

    tmp = string.split(ut, ":")
    uid = tmp[1]
    url = cPickle.loads(self.urls[int(uid)])
    urlsDelList.append(uid)             
    utDelList.append(ut)                
    del self.urlsDepth[uid]
    del self.urlsStatus[uid]
    del url

for ut in utDelList:
    del self.urls2task[ut]

for uid in urlsDelList:
    del self.urls[int(uid)]

(...)
#synchronize all files
self.sync() 

我最后的希望是以一种野蛮的方式迫使刷新-通过关闭和打开文件

^{pr2}$

关键因素是自我任务条目;它是所有文件中增长最快和最大的。酸洗可以改变去除它的方法吗?而且,再一次-为什么文件删除后仍然保留这些条目? 如果有任何建议,我将不胜感激


Tags: 文件inselfurlforuid条目urls
3条回答

你试过使用db.compact()方法吗?在

根据文件:

compact(start=None, stop=None, flags=0, compact_fillpercent=0, compact_pages=0, compact_timeout=0)

Compacts Btree and Recno access method databases, and optionally returns unused Btree, Hash or Recno database pages to the underlying filesystem.

The method returns the number of pages returned to the filesystem.

听起来它应该减少磁盘上数据库的大小

可能无法单独从btree数据库获取空间。 您可以做的最好的方法是db_转储一个文本文件中的所有数据,并使用该文件的db_load创建一个新的db。在

相关问题 更多 >