diff --git a/core/docs/changelog/ZO-4057.change b/core/docs/changelog/ZO-4057.change new file mode 100644 index 0000000000..42cb79d9c0 --- /dev/null +++ b/core/docs/changelog/ZO-4057.change @@ -0,0 +1 @@ +ZO-4057: Truncate temporary table before running zodbpack diff --git a/core/src/zeit/cms/relstorage.py b/core/src/zeit/cms/relstorage.py index 9323459d57..f43ac21b67 100644 --- a/core/src/zeit/cms/relstorage.py +++ b/core/src/zeit/cms/relstorage.py @@ -11,6 +11,9 @@ import zope.app.appsetup.product +log = logging.getLogger(__name__) + + class PsqlServiceResolver(Resolver): def __call__(self, parsed_uri, kw): def factory(options): @@ -25,9 +28,20 @@ def factory(options): def zodbpack(): + import psycopg2 # soft dependency + settings = zeit.cms.cli.parse_paste_ini() storage_factory, db_kw = zodburi.resolve_uri(settings['zodbconn.uri']) storage = storage_factory() + + # Work around zodb/relstorage#482 + conn = psycopg2.connect(storage._adapter._dsn) + cur = conn.cursor() + log.info('Workaround: truncating object_refs_added table') + cur.execute('TRUNCATE object_refs_added') + conn.commit() + conn.close() + # We use keep_history=False, so we run pack only for garbage collection timestamp = None storage.pack(timestamp, ZODB.serialize.referencesf) @@ -46,9 +60,7 @@ def _instrument(self, **kw): tracer = opentelemetry.trace.get_tracer(__name__, tracer_provider=kw.get('tracer_provider')) if not perfmetrics._util.PURE_PYTHON: - logging.getLogger(__name__).warning( - 'perfmetrics loaded C extensions, skipping instrumentation' - ) + log.warning('perfmetrics loaded C extensions, skipping instrumentation') return wrapped_call = MetricImpl.__call__