Pack and garbage-collect the database¶
This guide shows you how to pack the ZODB to reclaim disk space and remove unreferenced objects (garbage collection). The procedure depends on your storage backend.
Prerequisites¶
New to this template? Start with Your first Zope instance.
A generated instance with data to pack.
RelStorage¶
For RelStorage, the cookiecutter always generates etc/relstorage-pack.conf
for the zodbpack command-line utility.
Run it from your instance directory:
zodbpack etc/relstorage-pack.conf
zodbpack packs the database and performs garbage collection.
For all options, read
Packing or reference checking a ZODB storage.
Schedule regular packing with cron, for example weekly:
0 3 * * 0 cd /srv/instance && zodbpack etc/relstorage-pack.conf
Filestorage¶
For the direct backend, pack from the Zope Management Interface:
open , set the
number of days of history to keep, and select Pack.
Two settings control packing behavior:
default_context:
db_storage: direct
# Keep a .old copy of the database before packing
db_filestorage_pack_keep_old: true
# Skip garbage collection during packing for speed
db_filestorage_pack_gc: true
See Database: direct filestorage for details.
PGJsonb¶
A history-free PGJsonb database (the default) does not accumulate undo history, so routine packing is rarely needed.
A history-preserving database (db_pgjsonb_history_preserving: true) grows
over time and requires regular packing through the storage’s own tooling.
See Database: PGJsonb.
ZEO¶
Packing a ZEO database is a server-side operation: pack the storage on the ZEO server, not from the client. ZEO server administration is outside the scope of this template; consult the ZODB/ZEO documentation.
Next steps¶
Database: RelStorage – RelStorage command-line utilities.
Back up and restore – Back up before packing large databases.
Understanding storage backends – Comparison of all storage backends.