Limit number of open db files (fixes #587)