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#

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 Control_Panel ‣ Database Management ‣ main, 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#