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---------------------------------------
@@ -287,6 +304,10 @@ functionality like crash tolerance.
287304 reorganization; otherwise, deleted file space will be kept and reused as new
288305 (key, value) pairs are added.
289306
307+ .. note ::
308+ While reorganizing, as much as one time the size of the original database is required
309+ in free disk space. However, be aware that this factor changes for each :mod: `dbm ` submodule.
310+
290311 .. method :: gdbm.sync()
291312
292313 When the database has been opened in fast mode, this method forces any
@@ -441,6 +462,11 @@ The :mod:`!dbm.dumb` module defines the following:
441462 with a sufficiently large/complex entry due to stack depth limitations in
442463 Python's AST compiler.
443464
465+ .. warning ::
466+ :mod: `dbm.dumb ` does not support concurrent read/write access. (Multiple
467+ simultaneous read accesses are safe.) When a program has the database open
468+ for writing, no other program should have it open for reading or writing.
469+
444470 .. versionchanged :: 3.5
445471 :func: `~dbm.dumb.open ` always creates a new database when *flag * is ``'n' ``.
446472
@@ -463,3 +489,15 @@ The :mod:`!dbm.dumb` module defines the following:
463489 .. method :: dumbdbm.close()
464490
465491 Close the database.
492+
493+ .. method :: dumbdbm.reorganize()
494+
495+ If you have carried out a lot of deletions and would like to shrink the space
496+ used on disk, this method will reorganize the database; otherwise, deleted file
497+ space will not be reused.
498+
499+ .. note ::
500+ While reorganizing, no additional free disk space is required. However, be aware
501+ that this factor changes for each :mod: `dbm ` submodule.
502+
503+ .. versionadded :: next
0 commit comments