1515* :mod: `dbm.ndbm `
1616
1717If none of these modules are installed, the
18- slow-but-simple implementation in module :mod: `dbm.dumb ` will be used. There
18+ slow-but-simple implementation in module :mod: `dbm.dumb ` will be used. There
1919is a `third party interface <https://www.jcea.es/programacion/pybsddb.htm >`_ to
2020the Oracle Berkeley DB.
2121
22+ .. note ::
23+ None of the underlying modules will automatically shrink the disk space used by
24+ the database file. However, :mod: `dbm.sqlite3 `, :mod: `dbm.gnu ` and :mod: `dbm.dumb `
25+ provide a :meth: `!reorganize ` method that can be used for this purpose.
26+
27+
2228.. exception :: error
2329
2430 A tuple containing the exceptions that can be raised by each of the supported
@@ -186,6 +192,17 @@ or any other SQLite browser, including the SQLite CLI.
186192 The Unix file access mode of the file (default: octal ``0o666 ``),
187193 used only when the database has to be created.
188194
195+ .. method :: sqlite3.reorganize()
196+
197+ If you have carried out a lot of deletions and would like to shrink the space
198+ used on disk, this method will reorganize the database; otherwise, deleted file
199+ space will be kept and reused as new (key, value) pairs are added.
200+
201+ .. note ::
202+ While reorganizing, as much as two times the size of the original database is required
203+ in free disk space. However, be aware that this factor changes for each :mod: `dbm ` submodule.
204+
205+ .. versionadded :: next
189206
190207:mod: `dbm.gnu ` --- GNU database manager
191208---------------------------------------
@@ -284,6 +301,10 @@ functionality like crash tolerance.
284301 reorganization; otherwise, deleted file space will be kept and reused as new
285302 (key, value) pairs are added.
286303
304+ .. note ::
305+ While reorganizing, as much as one time the size of the original database is required
306+ in free disk space. However, be aware that this factor changes for each :mod: `dbm ` submodule.
307+
287308 .. method :: gdbm.sync()
288309
289310 When the database has been opened in fast mode, this method forces any
@@ -438,6 +459,11 @@ The :mod:`!dbm.dumb` module defines the following:
438459 with a sufficiently large/complex entry due to stack depth limitations in
439460 Python's AST compiler.
440461
462+ .. warning ::
463+ :mod: `dbm.dumb ` does not support concurrent read/write access. (Multiple
464+ simultaneous read accesses are safe.) When a program has the database open
465+ for writing, no other program should have it open for reading or writing.
466+
441467 .. versionchanged :: 3.5
442468 :func: `~dbm.dumb.open ` always creates a new database when *flag * is ``'n' ``.
443469
@@ -460,3 +486,15 @@ The :mod:`!dbm.dumb` module defines the following:
460486 .. method :: dumbdbm.close()
461487
462488 Close the database.
489+
490+ .. method :: dumbdbm.reorganize()
491+
492+ If you have carried out a lot of deletions and would like to shrink the space
493+ used on disk, this method will reorganize the database; otherwise, deleted file
494+ space will not be reused.
495+
496+ .. note ::
497+ While reorganizing, no additional free disk space is required. However, be aware
498+ that this factor changes for each :mod: `dbm ` submodule.
499+
500+ .. versionadded :: next
0 commit comments