[PATCH] VACUUM: avoid pre-creation transactions holding back cleanup of newly created relations
| От | Mikhail Kharitonov |
|---|---|
| Тема | [PATCH] VACUUM: avoid pre-creation transactions holding back cleanup of newly created relations |
| Дата | |
| Msg-id | CAKkoVas0Eq9mD6pUPg7yWs0fOHbHDHB-nePnjD+EuiYqXYimZQ@mail.gmail.com обсуждение исходный текст |
| Список | pgsql-hackers |
Hi hackers,
Attached is a patch that extends VACUUM’s VISHORIZON_DATA handling by tracking
a relation "birth XID" and using it to compute a relation-specific data horizon.
The goal is to avoid cases where transactions that started before a relation
existed to hold back cleanup of that relation. The patch applies
cleanly to current master.
Right now GetOldestNonRemovableTransactionId() for VISHORIZON_DATA uses
a database-wide horizon. Because of that, a single old transaction can hold
the VACUUM horizon and prevent removal of dead tuples, and may also prevent
VACUUM from truncating the relation, even for a table that was created after
that transaction started although that transaction cannot possibly see
the table.
Reproduction steps (two sessions):
Session 1:
BEGIN;
SELECT txid_current();
Session 2:
CREATE TABLE t (id bigserial, payload text);
INSERT INTO t(payload) SELECT repeat('x', 200) FROM generate_series(1, 200000);
DELETE FROM t WHERE id > 150000;
VACUUM (VERBOSE) t;
Without the patch, VACUUM reports "dead but not yet removable" and oldest xmin
matches the XID from session 1, so the cleanup is held back even though
the relation was created later. With the patch applied, the transaction from
session 1 is ignored for this relation’s VISHORIZON_DATA horizon,
so VACUUM can remove the dead tuples and truncate the relation.
The patch adds pg_class.relminxid, sets it at relation creation, and when
computing VISHORIZON_DATA scans ProcArray but ignores backends whose xid/xmin
are unambiguously older than relminxid, since such snapshots cannot require
keeping tuples of a relation that did not exist yet. A regression test is
included: src/test/recovery/t/121_vacuum_xid_horizons.pl.
I’d be grateful for any comments.
______
Thanks,
Mikhail Kharitonov
Вложения
В списке pgsql-hackers по дате отправления: