[Bug] AO storage reloptions are copied as zeroed autovacuum options, causing repeated aggressive TOAST wraparound vacuums
Maintainer thường phản hồi trong vòng 3 ngày
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 55/100
Hướng nghiên cứu
Bắt đầu với reloptions.c, đặc biệt là allocateReloptStruct() và ao_amoptions(), sau đó lần theo extract_autovac_opts() và cơ chế kế thừa TOAST trong autovacuum.c. Tái hiện vấn đề với bảng AO và các reloptions được cung cấp, đồng thời kiểm tra các quyết định và log của autovacuum. Công việc được xem là hoàn tất khi một regression test bao quát các bảng AO dạng hàng và dạng cột, các relation TOAST có tuổi thấp, các giá trị mặc định toàn cục và các tùy chọn TOAST được chỉ định rõ ràng, mà không có các lần vacuum wraparound lặp lại.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Apache Cloudberry version
Apache Cloudberry 2.1.0
What happened
Cloudberry repeatedly performs automatic aggressive wraparound vacuums on thousands of nearly empty TOAST relations belonging to append-optimized row tables.
Typical log message:
automatic aggressive vacuum to prevent wraparound of table "<database>.pg_toast.pg_toast_<oid>"
This happens even though the affected TOAST relations are nowhere near the configured wraparound threshold.
Production observations from two databases:
- One database repeatedly vacuumed exactly 1,231 TOAST relations per cycle.
- Another database repeatedly vacuumed exactly 2,198 TOAST relations per cycle.
- These counts exactly matched the number of AO row parent tables having non-empty storage
reloptions. - The same TOAST OIDs were processed again during every autovacuum cycle.
- All affected parent tables used the
ao_rowaccess method. - Their
reloptionscontained only AO storage settings such ascompresstype,compresslevel,blocksize, orchecksum. - Affected TOAST relations had transaction ID ages of only a few hundred; the maximum observed age was below 1,000.
- Their multixact ages were zero.
- None was close to the normal
autovacuum_freeze_max_agevalue of approximately 200 million transactions. - The vacuums commonly reported zero pages and zero tuples.
- There was no
cutoff for removing and freezing tuples is far in the pastwarning. log_autovacuum_min_durationwas globally set to-1, but these vacuums were still logged.- In one five-second sample, 466 aggressive vacuum records were written and the logs grew by approximately 1 MB.
This causes continuous autovacuum worker activity, CPU consumption, buffer accesses, WAL generation, and very large log volume on databases containing many AO tables.
This may explain the still-unresolved AO/TOAST behavior reported in #1850. However, this case is deterministic and is not caused by a held-back OldestXmin: the affected relations have very low XID ages, there is no old-Xmin warning, and the affected set exactly matches AO parents with storage reloptions.
The problem appears to be caused by an interaction between AO reloption parsing and TOAST autovacuum option inheritance.
-
Autovacuum reloptions such as
autovacuum_freeze_max_ageare registered only forRELOPT_KIND_HEAP | RELOPT_KIND_TOAST, not forRELOPT_KIND_APPENDOPTIMIZED: -
allocateReloptStruct()zero-initializes the completeStdRdOptionsstructure usingpalloc0(): -
ao_amoptions()parses AO parent-table reloptions using onlyRELOPT_KIND_APPENDOPTIMIZED: -
Therefore, when an AO table has storage reloptions, a non-NULL
StdRdOptionsis returned, but its embeddedAutoVacOptsfields were never populated with the expected-1sentinel/default values. They remain zero because ofpalloc0(). -
extract_autovac_opts()explicitly acceptsAO_ROW_TABLE_AM_OIDandAO_COLUMN_TABLE_AM_OID, then copies the zero-filled embeddedAutoVacOpts: -
A TOAST relation without its own reloptions inherits this copied structure from its AO parent:
-
The resulting effective values include:
enabled = false
freeze_min_age = 0
freeze_max_age = 0
freeze_table_age = 0
multixact_freeze_max_age = 0
vacuum_cost_delay = 0
log_min_duration = 0
-
relation_needs_vacanalyze()considers any non-negativefreeze_max_ageto be an explicitly configured value:
Because the inherited value is zero, the force limit becomes effectively:
xidForceLimit = recentXid - 0
Consequently, almost every normal TOAST relfrozenxid precedes the force limit and is immediately classified as requiring wraparound vacuum.
The forced-wraparound condition bypasses autovacuum_enabled=false, while freeze_table_age=0 makes the operation aggressive. The inherited log_min_duration=0 also explains why the operations are logged even when the global log_autovacuum_min_duration is -1.
What you think should happen instead
AO storage reloptions must not be interpreted as explicit autovacuum settings.
When an AO parent table has only compression, checksum, or block-size options:
- Its unused embedded
AutoVacOptsvalues should not be copied as zero-valued overrides. - Its TOAST relation should use its own explicit autovacuum reloptions, if any.
- Otherwise, the TOAST relation should use the normal global autovacuum defaults.
- A TOAST relation with an XID age of only a few hundred must not be classified as requiring wraparound vacuum.
- The global
log_autovacuum_min_duration=-1setting should remain effective unless a real per-table override exists.
How to reproduce
For faster reproduction, use a short autovacuum_naptime, for example one second. Keep log_autovacuum_min_duration=-1; this helps demonstrate that the zero-valued inherited option overrides the global setting.
Create an AO row table with a TOAST-able column and explicit AO storage reloptions:
CREATE SCHEMA av_ao_relopts_repro;
CREATE TABLE av_ao_relopts_repro.ao_with_storage_opts
(
id integer,
payload text
)
WITH
(
appendonly=true,
orientation=row,
compresstype=zlib,
compresslevel=1,
checksum=true
)
DISTRIBUTED RANDOMLY;
Confirm the AO parent, its storage reloptions, and its TOAST relation:
SELECT
n.nspname AS parent_schema,
c.relname AS parent_relation,
am.amname AS access_method,
c.reloptions AS parent_reloptions,
t.oid AS toast_oid,
t.relname AS toast_relation,
age(t.relfrozenxid) AS toast_xid_age,
mxid_age(t.relminmxid) AS toast_mxid_age
FROM pg_class c
JOIN pg_namespace n
ON n.oid = c.relnamespace
JOIN pg_am am
ON am.oid = c.relam
JOIN pg_class t
ON t.oid = c.reltoastrelid
WHERE n.nspname = 'av_ao_relopts_repro'
AND c.relname = 'ao_with_storage_opts';
Advance several normal transactions:
SELECT txid_current();
SELECT txid_current();
SELECT txid_current();
SELECT txid_current();
SELECT txid_current();
For a continuous reproduction, an external session can generate one transaction at a time:
for i in $(seq 1 300); do
psql -Atqc 'SELECT txid_current()' >/dev/null
sleep 0.2
done
Wait for at least two autovacuum cycles and inspect the coordinator and segment logs.
Expected buggy result:
automatic aggressive vacuum to prevent wraparound of table "<database>.pg_toast.pg_toast_<toast_oid>"
The message appears while age(relfrozenxid) is still very small. As additional transactions are generated, the same TOAST relation is selected repeatedly.
To reproduce the high-volume effect, create multiple AO tables with storage reloptions:
DO $$
DECLARE
i integer;
BEGIN
FOR i IN 1..100 LOOP
EXECUTE format(
'CREATE TABLE av_ao_relopts_repro.ao_bug_%s
(
id integer,
payload text
)
WITH
(
appendonly=true,
orientation=row,
compresstype=zlib,
compresslevel=1,
checksum=true
)
DISTRIBUTED RANDOMLY',
i
);
END LOOP;
END
$$;
After advancing transactions, the TOAST relations of these tables should be selected for aggressive vacuum repeatedly, despite their very low XID ages.
Cleanup:
DROP SCHEMA av_ao_relopts_repro CASCADE;
Operating System
rocky 9.6
Anything else
The exact problematic logic is still present in the latest REL_2_STABLE branch:
-
AO option parsing:
-
AO autovacuum option extraction:
-
TOAST inheritance:
One possible minimal fix is to prevent an AO parent relation from returning an AutoVacOpts structure when AO autovacuum reloptions are not supported:
relam = ((Form_pg_class) GETSTRUCT(tup))->relam;
if (IsAccessMethodAO(relam))
return NULL;
AO auxiliary relations and TOAST relations use the heap access method, so this guard would only prevent the invalid AO parent options from being inherited.
Another possible fix is to initialize unsupported/missing AutoVacOpts members to their intended -1 sentinel values instead of leaving them zero.
A regression test should cover both AO row and AO column tables with non-empty storage reloptions and verify that:
- Their low-age TOAST relations are not marked for wraparound vacuum.
- The configured global
autovacuum_freeze_max_ageis used. log_autovacuum_min_duration=-1is not overridden by an unintended zero value.- Explicit TOAST autovacuum options continue to work.
Are you willing to submit PR?
- Yes, I am willing to submit a PR!
Code of Conduct
- I agree to follow this project's Code of Conduct.
- Ngôn ngữ chính
- C
- Star
- 1.4k
- Fork
- 262
- Merge trung bình
- 4 ngày 20 giờ
- Pull request đã merge (30 ngày)
- 57
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của apache/cloudberry
-
[Bug] Expand fails to recognize user-defined tablespacesCó thể đã có người làm @nix-oss đã nhận 62 ngày trước. Đang mởtype: Bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
apache/cloudberry#1885 · 2 reaction ·
Maintainer thường phản hồi trong vòng 3 ngày
-
gpexpand first stage fails: 'SyncPackages' object has no attribute 'ret' (extension sync never runs; regression)Có thể đã có người làm @talmacschen-arch đã nhận 123 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 86/100
apache/cloudberry#1825 ·
Maintainer thường phản hồi trong vòng 3 ngày
-
Lance support: contrib/lance_fdw and the MCP server's Lance toolsCó thể đã có người làm @MisterRaindrop đã nhận 3 ngày trước. Đang mở
apache/cloudberry#2139 · 1 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 3 ngày
-
type: Bug
Độ khó 3/5 Nửa ngày Mức phù hợp với người mới 58/100
apache/cloudberry#2137 ·
Maintainer thường phản hồi trong vòng 3 ngày
-
[Proposal] Remove `gpcontrib/gpmapreduce` starting from Cloudberry 3.0Có thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mởtype: Proposal
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 22/100
apache/cloudberry#2136 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 3 ngày
Tất cả issue của apache/cloudberry
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
FujiNetWIFI/fujinet-lib#204 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
os:linux
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
mpv-player/mpv#18649 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
facebookincubator/muse-gadget-sdk#249 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
docs: nng_dial / nng_dialer_start can return NNG_ECONNSHUT and NNG_ECRYPTO, which are not documentedĐang mở
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 89/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
micropython/micropython#19786 ·
Maintainer thường phản hồi trong vòng 1 ngày