Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xHOQ0-00000002yi2-1405 for pgsql-bugs@arkaria.postgresql.org; Thu, 15 Oct 2026 16:35:00 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.98.2) (envelope-from ) id 1xHOPw-00000009xHF-3Hwz for pgsql-bugs@arkaria.postgresql.org; Thu, 15 Oct 2026 16:34:56 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xHOPw-00000009xH7-1xZa for pgsql-bugs@lists.postgresql.org; Thu, 15 Oct 2026 16:34:56 +0000 Received: from relay4-d.mail.gandi.net ([2001:4b98:dc4:8::224]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xHOPt-00000002B9C-2GbL for pgsql-bugs@lists.postgresql.org; Thu, 15 Oct 2026 16:34:55 +0000 Received: by mail.gandi.net (Postfix) with ESMTPSA id AFD7B3F67F; Thu, 15 Oct 2026 16:34:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vondra.me; s=gm1; t=1792082086; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=mQGn6i8rBkK3vzpo95WNLPi3eBHACjmty+jQvB7WDUg=; b=Ac2Qn94vE6gBj2mUkXeqHIvwt7VF50V/4wu1VzB5v9fm4ip1fv2J/yOqnBB5s14PvmHcR5 82YRa0MI8dBJZi1tKL7hjrVbqNj07lmZCLdYr3+n2/yGjzlTO9JZYFs6SlYoQYex8fkr+k 3msxsA+9SmORbkULcVJ96g1FnId6dHfJC17KUEnJRK1ZkS5dpjZf1b0E8chqDgCyNERxe6 25bwNFBFHqXRKdxO6huOpnWf0A8yHX2kptvB21WXj5q4bHs7fX/sD+7negDnwdJpUgeYet 5DtyEUHzuoSpIhRZYNToUkgFjBPPZ9eGZhXz/BTsILcM0d94PbcQug9dcLcWVQ== Message-ID: Date: Thu, 15 Oct 2026 18:34:44 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: BUG #19764: ManualBug3 Assert failure in pgstat_setup_shared_refs crashes initdb post-bootstrap subprocess To: 1217816127@qq.com, pgsql-bugs@lists.postgresql.org, PG Bug reporting form References: <19764-dbbe7e43001dede5@postgresql.org> Content-Language: en-US From: Tomas Vondra In-Reply-To: <19764-dbbe7e43001dede5@postgresql.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-GND-Sasl: tomas@vondra.me X-GND-Cause: dmFkZTFz5lVx8yjEIa28/Hkq/n4UpbP2USqzrGcLiHy8DpB8+6OQSpCw4KV/mnR88pXZpK3r49mH4d0RJ6QDbMVT1JJEv4wFhlawY+u0oAOuVN2baiulueaUVfmeVoQkvAzVux/kuzB7Ym25S/9oXgzQqQDxa4ks3DmZASBSxOsxuJOr14M/1YBuvNKI/esM9I08h4vNhiwAJxgCTw5mEoQ5VuZg1oczUGiMEliTP8rrbXrb1prJ/8CnlxZ1T11qXzq76uzT/489Pd+Pbe5zD2nCNWwiefDVwDfeqw4tFMNEJV3hWSvMFZoSqWu6u7+vA17nBrcMiNch4FKy4vqqsJFlgBUxmGkQkfP7TD500ZQQzqwfvdz+TzU9rK8GW+dyfpTfxD+7pqXfJDwhCwqHiv91g1PR/ckSnyYCsY+yZHZ/s2mZiAi/OxQ1lsTx3GoY332qYeBmNPrir5uhL5J1EK9w5JwZ4aocxbVXtiBoF2W1li5Nh1WeVOvf0y28gm/AQN3m88G79h8n/4LWCkftAsK466rfgM7tp1xLyhlVXyvOGkbrSzxX4uv/ejiE9RWvD5BBN1smUIuNe/97tNb4pRd4OUbksO9wffJ9yNTLAvRB03O53ZzdIxpY/cRmVsJ8usnOuPXjYbzhODXazlGAayQ9BLcFKTFlKKUOo/tpELvnHxNUIw X-GND-State: clean X-GND-Score: 0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 10/15/26 17:05, PG Bug reporting form wrote: > The following bug has been logged on the website: > > Bug reference: 19764 > Logged by: Yuelin Wang > Email address: 1217816127@qq.com > PostgreSQL version: 19rc1 > Operating system: Linux (Ubuntu 24.04, x86_64) > Description: > > ### What happens? > > During `initdb`, the "performing post-bootstrap initialization" subprocess > calls `pgstat_initialize()` (which sets `pgStatLocal.shmem->gc_request_count > = 1` via `StatsShmemInit`), then calls `StartupXLOG()`. > Inside `StartupXLOG()`, `pgstat_restore_stats()` is invoked. > After `pgstat_restore_stats()` completes, `gc_request_count` has been zeroed > out to 0 (verified via debug instrumentation in the working-tree build). > Later, during catalog initialization (`InitPostgres` calls > `table_beginscan_catalog`, which calls `heap_beginscan`, which calls > `pgstat_assoc_relation`), `pgstat_get_entry_ref` is invoked for the first > time in this subprocess. > This triggers `pgstat_setup_shared_refs()` > (src/backend/utils/activity/pgstat_shmem.c), which reads `pgStatSharedRefAge > = pg_atomic_read_u64(&pgStatLocal.shmem->gc_request_count)` and gets 0. > Immediately after, the function asserts `Assert(pgStatSharedRefAge != 0)` at > pgstat_shmem.c:939, which fires and aborts the subprocess, causing initdb to > fail and clean up the data directory. > The violated invariant is: `gc_request_count` must remain at its initialized > value (1) and never fall to 0, since `pgstat_setup_shared_refs` relies on a > non-zero value to guarantee `pgStatSharedRefAge != 0`. > The `own_hash` feature introduced in commit 44539786b8 added `entry_counts`, > `kind_hash_handles`, and `raw_kind_dsa_area` arrays to > `PgStat_ShmemControl`, altering the struct layout and the initialization > sequence in `pgstat_restore_stats`/`pgstat_read_statsfile`. > The debug trace confirms that `gc_request_count` transitions from 1 to 0 > precisely during `pgstat_restore_stats()`. > This matches the Entry91 root-cause pattern: a field that must be > initialized to a sentinel non-zero value before use is inadvertently reset > to the uninitialized zero value by a code path that was modified by the same > recent commit. > > ### To Reproduce > > Start a fresh PostgreSQL ASAN instance with initdb: > > ```sh > TMPDIR=$(mktemp -d /tmp/pg_scan_XXXX) > DATADIR=$TMPDIR/pgdata > PGUSER=$(whoami) > > ASAN_OPTIONS=detect_leaks=0:abort_on_error=0:log_path=$TMPDIR/asan \ > /data/ylwang/Projects/DirectedDB/latesttarget/postgre/build_asan/install/bin/initdb > \ > -D $DATADIR -U $PGUSER --no-locale --encoding=UTF8 2>&1 > ``` > > Trigger output: > > ``` > The files belonging to this database system will be owned by user > "yuelinwang". > This user must also own the server process. > > The database cluster will be initialized with locale "C". > The default text search configuration will be set to "english". > > Data page checksums are enabled. > > creating directory .../pgdata ... ok > creating subdirectories ... ok > selecting dynamic shared memory implementation ... posix > selecting default "max_connections" ... 100 > selecting default "shared_buffers" ... 128MB > selecting default time zone ... Asia/Singapore > creating configuration files ... ok > running bootstrap script ... ok > performing post-bootstrap initialization ... TRAP: failed > Assert("pgStatSharedRefAge != 0"), File: "pgstat_shmem.c", Line: 939, PID: > 3146498 > /lib/x86_64-linux-gnu/libasan.so.8(+0x831e0)[...] > .../postgres(ExceptionalCondition+0x165)[...] > .../postgres(+0x14c282a)[...] > .../postgres(pgstat_get_entry_ref+0x33b)[...] > .../postgres(pgstat_prep_pending_entry+0x37)[...] > .../postgres(+0x14b9ee9)[...] > .../postgres(pgstat_assoc_relation+0x1f7)[...] > .../postgres(+0x5a3a24)[...] > .../postgres(heap_beginscan+0x8c0)[...] > .../postgres(+0x6e832b)[...] > .../postgres(table_beginscan_catalog+0x9a)[...] > .../postgres(+0x1963b82)[...] > .../postgres(InitPostgres+0x63a)[...] > .../postgres(PostgresMain+0x553)[...] > .../postgres(main+0x5d5)[...] > Aborted (core dumped) > child process exited with exit code 134 > initdb: removing data directory ".../pgdata" > ``` > > The assertion failure prevents initdb from completing and the data directory > is cleaned up automatically. > I can't reproduce this. Please provide step-by-step instructions how to trigger the issue. I tried this: CC=clang ./configure --prefix=/home/user/builds/asan \ --enable-debug --enable-cassert \ CFLAGS="-O0 -g -fno-omit-frame-pointer -fsanitize=address,undefined \ -fno-sanitize=function -fno-sanitize-recover=all" \ LDFLAGS="-fsanitize=address,undefined" and then after build export ASAN_OPTIONS=detect_leaks=0:abort_on_error=0 initdb tmp/data2 --no-locale --encoding=UTF8 -U test No crash / assert failure. Furthermore, I fail to understand why would this require ASAN build, if it crashes on an assert. regards -- Tomas Vondra